Skip to content

Commit d85f5b5

Browse files
committed
gsd-parser: tests: Check that invalid set_prm() does not panic
Add more assertions to ensure invalid calls to set_prm() and set_prm_from_text() never panic.
1 parent 19aa736 commit d85f5b5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gsd-parser/tests/regress.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,31 @@ fn regress_prm(#[files("tests/data/*.[gG][sS][dD]")] gsd_file: PathBuf) {
2323
texts.keys().next().unwrap()
2424
};
2525
prm.set_prm_from_text(&prm_ref.name, text).unwrap();
26+
27+
// Test that trying a wrong text doens't panic
28+
let res = prm.set_prm_from_text(&prm_ref.name, "InvalidTextAllTheWay");
29+
assert!(res.is_err());
2630
} else {
2731
let v = match &prm_ref.constraint {
2832
gsd_parser::PrmValueConstraint::MinMax(_, max) => *max,
2933
gsd_parser::PrmValueConstraint::Enum(values) => *values.last().unwrap(),
3034
gsd_parser::PrmValueConstraint::Unconstrained => 1,
3135
};
3236
prm.set_prm(&prm_ref.name, v).unwrap();
37+
38+
// Test that an invalid value results in an error rather than a panic
39+
let res = prm.set_prm(&prm_ref.name, i64::MIN);
40+
assert!(res.is_err());
41+
42+
// Test that trying a text PRM doesn't panic
43+
let res = prm.set_prm_from_text(&prm_ref.name, "InvalidTextAllTheWay");
44+
assert!(res.is_err());
3345
}
3446
}
3547

48+
// Test that a non-existent PRM doesn't panic
49+
let res = prm.set_prm("ThisPrmNeverEverExistsEver", 0);
50+
assert!(res.is_err());
51+
3652
insta::assert_debug_snapshot!(format!("{}-PRM", name).as_ref(), prm.as_bytes());
3753
}

0 commit comments

Comments
 (0)