drop error improvements across the board for localization

This commit is contained in:
2026-06-23 17:47:19 -04:00
parent d77765cb61
commit b0377e076e
42 changed files with 8857 additions and 773 deletions

View File

@ -107,7 +107,7 @@ pub fn run_test_case(path: &str, suite_idx: usize, case_idx: usize) -> Result<()
match test.action.as_str() {
"compile" => {
let result = test.run_compile(db);
let result = test.run_compile(db, path, suite_idx, case_idx);
if let Err(e) = result {
println!("TEST COMPILE ERROR FOR '{}': {}", test.description, e);
failures.push(format!(

View File

@ -41,6 +41,9 @@ impl Case {
pub fn run_compile(
&self,
db_res: &Result<Arc<Database>, crate::drop::Drop>,
path: &str,
suite_idx: usize,
case_idx: usize,
) -> Result<(), String> {
let expect = match &self.expect {
Some(e) => e,
@ -52,6 +55,10 @@ impl Case {
Err(d) => d.clone(),
};
if env::var("UPDATE_EXPECT").is_ok() {
update_validation_fixture(path, suite_idx, case_idx, &result.errors);
}
expect.assert_drop(&result)?;
if let Ok(db) = db_res {

View File

@ -1,4 +1,5 @@
use super::Expect;
use serde_json::Value;
impl Expect {
pub fn assert_drop(&self, drop: &crate::drop::Drop) -> Result<(), String> {
@ -14,14 +15,14 @@ impl Expect {
if !self.success {
if let Some(expected_errors) = &self.errors {
let actual_values: Vec<serde_json::Value> = drop.errors
let actual_values: Vec<Value> = drop.errors
.iter()
.map(|e| serde_json::to_value(e).unwrap())
.collect();
if expected_errors.len() != actual_values.len() {
return Err(format!(
"Expected {} errors, but got {}.\nExpected subset: {:?}\nActual full errors: {:?}",
"Expected {} errors, but got {}.\nExpected: {:?}\nActual full errors: {:?}",
expected_errors.len(),
actual_values.len(),
expected_errors,
@ -31,17 +32,15 @@ impl Expect {
for (i, expected_val) in expected_errors.iter().enumerate() {
let mut matched = false;
for actual_val in &actual_values {
if subset_match(expected_val, actual_val) {
if expected_val == actual_val {
matched = true;
break;
}
}
if !matched {
return Err(format!(
"Expected error {} was not found in actual errors.\nExpected subset: {}\nActual full errors: {:?}",
"Expected error {} was not found in actual errors.\nExpected: {}\nActual full errors: {:?}",
i,
serde_json::to_string_pretty(expected_val).unwrap(),
drop.errors,
@ -54,35 +53,3 @@ impl Expect {
Ok(())
}
}
// Helper to check if `expected` is a structural subset of `actual`
fn subset_match(expected: &serde_json::Value, actual: &serde_json::Value) -> bool {
match (expected, actual) {
(serde_json::Value::Object(exp_map), serde_json::Value::Object(act_map)) => {
for (k, v) in exp_map {
if let Some(act_v) = act_map.get(k) {
if !subset_match(v, act_v) {
return false;
}
} else {
return false;
}
}
true
}
(serde_json::Value::Array(exp_arr), serde_json::Value::Array(act_arr)) => {
// Basic check: array sizes and elements must match exactly in order
if exp_arr.len() != act_arr.len() {
return false;
}
for (e, a) in exp_arr.iter().zip(act_arr.iter()) {
if !subset_match(e, a) {
return false;
}
}
true
}
// For primitives, exact match
(e, a) => e == a,
}
}