test(build): close stylesheet scanner mutants
Prove sorted, deduplicated CSS/SCSS class extraction across starts, compounds, delimiters, invalid candidates, and invalid stylesheet module names; simplify token scanning to one boundary loop and classify only deterministic non-terminating progress mutants. req: style/001 req: diagnostics/004 req: test/021
This commit is contained in:
+46
-1
@@ -1451,7 +1451,7 @@ fn stylesheet_class_tokens(source: &str) -> Vec<&str> {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
let mut end = start + 1;
|
||||
let mut end = start;
|
||||
while end < bytes.len() && is_class_continue(bytes[end]) {
|
||||
end += 1;
|
||||
}
|
||||
@@ -2983,6 +2983,37 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stylesheet_class_scanner_is_sorted_deduplicated_and_boundary_aware() {
|
||||
assert_eq!(stylesheet_class_tokens(""), Vec::<&str>::new());
|
||||
assert_eq!(stylesheet_class_tokens(".a"), vec!["a"]);
|
||||
assert_eq!(stylesheet_class_tokens(".ab"), vec!["ab"]);
|
||||
assert_eq!(stylesheet_class_tokens("x.skip .kept"), vec!["kept"]);
|
||||
assert_eq!(stylesheet_class_tokens("x..kept"), vec!["kept"]);
|
||||
assert_eq!(stylesheet_class_tokens("..kept"), vec!["kept"]);
|
||||
assert_eq!(stylesheet_class_tokens(". .kept"), vec!["kept"]);
|
||||
assert_eq!(stylesheet_class_tokens(".1 .kept"), vec!["kept"]);
|
||||
assert_eq!(stylesheet_class_tokens(".é .kept"), vec!["kept"]);
|
||||
assert!(!preceded_by_class_in_compound(b"tag.", 3));
|
||||
assert!(preceded_by_class_in_compound(b".first.", 6));
|
||||
assert_eq!(
|
||||
stylesheet_class_tokens(
|
||||
".z9, .alpha.alpha, ._private, .-prefixed, .compound.second, tag.skipped, name-.skipped, name_.skipped"
|
||||
),
|
||||
vec!["-prefixed", "_private", "alpha", "compound", "second", "z9"]
|
||||
);
|
||||
assert_eq!(
|
||||
stylesheet_class_tokens(
|
||||
" .space\n.newline\r.return\t.tab,.comma{.open}.close>.child+.adjacent~.sibling(.paren)"
|
||||
),
|
||||
vec![
|
||||
"adjacent", "child", "close", "comma", "newline", "open", "paren", "return",
|
||||
"sibling", "space", "tab"
|
||||
]
|
||||
);
|
||||
// test req: style/001
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn class_and_form_resource_contracts_fail_closed_and_deduplicate() {
|
||||
let base = test_dir("hemx-build-resource-collisions");
|
||||
@@ -2990,6 +3021,20 @@ mod tests {
|
||||
let out = base.join("out");
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
std::fs::create_dir_all(&templates).unwrap();
|
||||
let invalid_stylesheet = templates.join("123.css");
|
||||
std::fs::write(&invalid_stylesheet, ".valid {}").unwrap();
|
||||
let invalid_stylesheet_name = app()
|
||||
.template_dir(&templates)
|
||||
.out_dir(&out)
|
||||
.run()
|
||||
.unwrap_err();
|
||||
assert_eq!(invalid_stylesheet_name.kind(), io::ErrorKind::InvalidData);
|
||||
assert_eq!(
|
||||
invalid_stylesheet_name.to_string(),
|
||||
"invalid template name `123`; expected a Rust module identifier"
|
||||
);
|
||||
std::fs::remove_file(invalid_stylesheet).unwrap();
|
||||
|
||||
let invalid_class_template = templates.join("invalid_class.heml");
|
||||
std::fs::write(&invalid_class_template, r#"<div class="123"></div>"#).unwrap();
|
||||
let invalid_class = app()
|
||||
|
||||
Reference in New Issue
Block a user