aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-test-harness
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-03 11:55:03 +0900
committernsfisis <nsfisis@gmail.com>2026-05-03 11:55:03 +0900
commitae1aa6540761e54a76b8f7984cf93cd3a0d011d0 (patch)
treef111e1c73977f0bffb6323b03f4210269b43b297 /crates/mozart-test-harness
parent30ae6c869adc7f3cb87a4d63edd6d0cda89d571d (diff)
downloadphp-mozart-ae1aa6540761e54a76b8f7984cf93cd3a0d011d0.tar.gz
php-mozart-ae1aa6540761e54a76b8f7984cf93cd3a0d011d0.tar.zst
php-mozart-ae1aa6540761e54a76b8f7984cf93cd3a0d011d0.zip
refactor: switch internal maps/sets from HashMap to IndexMap
Adopt indexmap workspace-wide so iteration order is deterministic and follows insertion order. The non-deterministic order of std HashMap otherwise leaks into resolver decisions when multiple valid solutions exist (e.g. cyclic require pairs under prefer-lowest), making behavior flaky and divergent from Composer's PHP-array semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-test-harness')
-rw-r--r--crates/mozart-test-harness/Cargo.toml1
-rw-r--r--crates/mozart-test-harness/src/parser.rs8
2 files changed, 5 insertions, 4 deletions
diff --git a/crates/mozart-test-harness/Cargo.toml b/crates/mozart-test-harness/Cargo.toml
index 61b9109..6c9421c 100644
--- a/crates/mozart-test-harness/Cargo.toml
+++ b/crates/mozart-test-harness/Cargo.toml
@@ -5,6 +5,7 @@ edition.workspace = true
[dependencies]
anyhow.workspace = true
+indexmap.workspace = true
regex.workspace = true
serde_json.workspace = true
tempfile.workspace = true
diff --git a/crates/mozart-test-harness/src/parser.rs b/crates/mozart-test-harness/src/parser.rs
index dbc71ae..827272b 100644
--- a/crates/mozart-test-harness/src/parser.rs
+++ b/crates/mozart-test-harness/src/parser.rs
@@ -1,5 +1,5 @@
use anyhow::{Context, Result, bail};
-use std::collections::HashMap;
+use indexmap::IndexMap;
use std::fs;
use std::path::Path;
@@ -53,7 +53,7 @@ pub fn parse_test_str(content: &str) -> Result<ParsedTest> {
}
}
- let mut take = |key: &str| sections.remove(key);
+ let mut take = |key: &str| sections.shift_remove(key);
let test = take("TEST").unwrap();
let composer = take("COMPOSER").unwrap();
@@ -86,10 +86,10 @@ pub fn parse_test_str(content: &str) -> Result<ParsedTest> {
})
}
-fn split_sections(content: &str) -> Result<HashMap<String, String>> {
+fn split_sections(content: &str) -> Result<IndexMap<String, String>> {
let header_re = regex::Regex::new(r"^--([A-Z][A-Z-]*)--$").unwrap();
- let mut sections: HashMap<String, String> = HashMap::new();
+ let mut sections: IndexMap<String, String> = IndexMap::new();
let mut current_section: Option<String> = None;
let mut current_body = String::new();