use super::{migrations, render};
#[test]
fn every_row_matches_the_runtime_registry() {
let rows = migrations();
assert!(
rows.len() > 100,
"the registry should carry the whole migrated surface, got {} rows",
rows.len()
);
for (name, replacement) in &rows {
let migration = harn_vm::stdlib::harness_migration_for_builtin(name)
.unwrap_or_else(|| panic!("`{name}` is in the table but not in the registry"));
assert_eq!(
replacement,
&format!(
"harness.{}.{}",
migration.capability.field_name(),
migration.method
),
"`{name}` disagrees with the registry"
);
}
}
#[test]
fn the_table_carries_the_case_the_fuzzy_matcher_got_wrong() {
assert_eq!(
migrations().get("uuid_v7").map(String::as_str),
Some("harness.random.uuid_v7")
);
}
#[test]
fn the_known_name_collisions_are_still_collisions() {
let rows = migrations();
for (legacy, migration, reason) in harn_parser::diagnostic::HARNESS_MIGRATION_DISAGREEMENTS {
let generated = rows.get(*legacy).map(String::as_str);
assert!(
generated.is_some(),
"`{legacy}` is pinned as a collision but the registry has no row for it"
);
assert_ne!(
generated,
Some(*migration),
"`{legacy}` no longer collides — the registry now agrees with the migration, \
so drop it from HARNESS_MIGRATION_DISAGREEMENTS ({reason})"
);
}
}
#[test]
fn the_rendered_table_is_sorted_and_stable() {
let rendered = render(&migrations());
let names: Vec<&str> = rendered
.lines()
.filter_map(|line| line.trim().strip_prefix('('))
.filter_map(|line| line.split('"').nth(1))
.collect();
assert!(names.len() > 100);
let mut sorted = names.clone();
sorted.sort_unstable();
assert_eq!(names, sorted, "the generator must emit a sorted table");
assert_eq!(
rendered,
render(&migrations()),
"two renders of the same registry must be byte-identical"
);
}