aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/json
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 12:51:24 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 12:51:24 +0900
commitfce44d4587ba11b080fe0266c483d0be684ffd0d (patch)
tree753e87ac7ed2e57d635a60c10a4ce01b7e0f0f8e /crates/shirabe/tests/json
parentb12c2b15f0487d54d359a581e99ced68713914d0 (diff)
downloadphp-shirabe-fce44d4587ba11b080fe0266c483d0be684ffd0d.tar.gz
php-shirabe-fce44d4587ba11b080fe0266c483d0be684ffd0d.tar.zst
php-shirabe-fce44d4587ba11b080fe0266c483d0be684ffd0d.zip
refactor(php-shim): split json_decode into assoc and obj variants
The assoc flag was always a literal at every call site, so the boolean carried no information the function name could not. json_decode_assoc and json_decode_obj make the resulting PhpMixed shape visible at the call site. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/json')
-rw-r--r--crates/shirabe/tests/json/composer_schema_test.rs4
-rw-r--r--crates/shirabe/tests/json/json_file_test.rs6
2 files changed, 5 insertions, 5 deletions
diff --git a/crates/shirabe/tests/json/composer_schema_test.rs b/crates/shirabe/tests/json/composer_schema_test.rs
index f2a5da44..8c6e8b8a 100644
--- a/crates/shirabe/tests/json/composer_schema_test.rs
+++ b/crates/shirabe/tests/json/composer_schema_test.rs
@@ -10,7 +10,7 @@
use shirabe::json::{JsonFile, JsonValidationException};
use shirabe_php_shim::Catch as _;
-use shirabe_php_shim::json_decode;
+use shirabe_php_shim::json_decode_obj;
const NAME_PATTERN: &str = r#"^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$"#;
const VERSION_PATTERN: &str = r#"^[vV]?\d+(?:[.-]\d+){0,3}[._-]?(?:(?:[sS][tT][aA][bB][lL][eE]|[bB][eE][tT][aA]|[bB]|[rR][cC]|[aA][lL][pP][hH][aA]|[aA]|[pP][aA][tT][cC][hH]|[pP][lL]|[pP])(?:(?:[.-]?\d+)*)?)?(?:[.-]?[dD][eE][vV]|\.x-dev)?(?:\+.*)?$|^dev-.*$"#;
@@ -19,7 +19,7 @@ const VERSION_PATTERN: &str = r#"^[vV]?\d+(?:[.-]\d+){0,3}[._-]?(?:(?:[sS][tT][a
/// (the `{"$ref": "file://…"}` wrapper used by `LAX_SCHEMA`), returning the validation error
/// strings, or an empty vec when the document is valid.
fn check(json: &str) -> Vec<String> {
- let data = json_decode(json, false).unwrap();
+ let data = json_decode_obj(json).unwrap();
match JsonFile::validate_json_schema("test", &data, JsonFile::LAX_SCHEMA, None) {
Ok(_) => Vec::new(),
Err(e) => e
diff --git a/crates/shirabe/tests/json/json_file_test.rs b/crates/shirabe/tests/json/json_file_test.rs
index 27b43a05..490571ec 100644
--- a/crates/shirabe/tests/json/json_file_test.rs
+++ b/crates/shirabe/tests/json/json_file_test.rs
@@ -198,9 +198,9 @@ fn test_double_escaped_unicode() {
wrapper.insert("t".to_string(), PhpMixed::String(encoded_data));
let double_encoded_data = JsonFile::encode(&PhpMixed::Array(wrapper)).unwrap();
- let decoded_data = shirabe_php_shim::json_decode(&double_encoded_data, true).unwrap();
+ let decoded_data = shirabe_php_shim::json_decode_assoc(&double_encoded_data).unwrap();
let t = decoded_data.as_array().unwrap().get("t").unwrap();
- let double_data = shirabe_php_shim::json_decode(t.as_string().unwrap(), true).unwrap();
+ let double_data = shirabe_php_shim::json_decode_assoc(t.as_string().unwrap()).unwrap();
assert_eq!(data, double_data);
}
@@ -439,7 +439,7 @@ fn test_auth_schema_validation_with_custom_data_source() {
// INCOMPATIBILITY NOTE: upstream asserts justinrainbow's "github-oauth : String value found, but an
// object is required". The jsonschema crate reports the same type violation with different
// wording.
- let json = shirabe_php_shim::json_decode("{\"github-oauth\": \"foo\"}", false).unwrap();
+ let json = shirabe_php_shim::json_decode_obj("{\"github-oauth\": \"foo\"}").unwrap();
let expected_message = "\"COMPOSER_AUTH\" does not match the expected JSON schema".to_string();
let expected_error = "github-oauth : \"foo\" is not of type \"object\"".to_string();