use super::*;
#[test]
fn trivial_digit_runs_pinned() {
for t in ["0000", "1234", "9876", "1357", "2468", "4321"] {
assert!(is_trivial_4_digits(t), "{t} is a trivial run");
}
for ok in ["4283", "1233", "1122", "5180", "7391"] {
assert!(!is_trivial_4_digits(ok), "{ok} is not a trivial run");
}
}
#[test]
fn minimum_length_marker_is_accepted() {
assert!(validate_trap_marker("FoxBarBaz4283").is_ok());
}
#[test]
fn validate_trap_marker_enforces_the_strict_grammar() {
for ok in [
"CrimsonWillowFen5180",
"MossyLanternCove6024",
"GildedHeronVale7391",
] {
assert!(validate_trap_marker(ok).is_ok(), "should accept {ok}");
}
for bad in [
"", "foo", "CrimsonOwlPond", "DeepRiverStone12", "OneTwo4283", "WistfulAmberGlenMoor8135", "GoFooBars4283", "HTTPSPROXYGATE4827", "HTML0000", "DeepRiverStone1234", "DeepRiverStone0000", "DeepRiverStone9876", "DeepRiverStone1357", "DeepRiverStone2468", ] {
assert!(validate_trap_marker(bad).is_err(), "should reject {bad:?}");
}
}
#[test]
fn validate_trap_marker_refuses_the_reserved_doc_example() {
for reserved in RESERVED_EXAMPLE_MARKERS {
let err = validate_trap_marker(reserved)
.expect_err("the documented example must be refused")
.to_string();
assert!(
err.contains("RESERVED") && err.to_lowercase().contains("example"),
"reserved-marker error must explain it is the reserved doc example: {err}"
);
}
}
#[test]
fn is_trivial_4_digits_flags_arithmetic_runs_only() {
for t in ["0000", "1234", "9876", "1357", "2468", "8642", "3210"] {
assert!(is_trivial_4_digits(t), "{t} is trivial");
}
for ok in ["4283", "6024", "7391", "8135", "1212", "1122"] {
assert!(!is_trivial_4_digits(ok), "{ok} is NOT trivial");
}
}