use super::*;
#[test]
fn mask_strings_basic() {
assert_eq!(
mask_strings(r#"let s = "if x > 0";"#, &[]),
r#"let s = " ";"#
);
assert_eq!(
mask_strings(r#"let c = '{'; if x {"#, &[]),
r#"let c = ' '; if x {"#
);
assert_eq!(
mask_strings(r#"let s = "he said \"hi\"";"#, &[]),
r#"let s = " ";"#
);
}
#[test]
fn mask_strings_empty() {
assert_eq!(mask_strings("", &[]), "");
}
#[test]
fn mask_strings_no_strings() {
assert_eq!(mask_strings("let x = 42;", &[]), "let x = 42;");
}
#[test]
fn mask_strings_raw_string() {
let result = mask_strings(r#"x = r"if|for|while""#, &[]);
assert!(!result.contains("if|for|while"));
assert!(result.contains("r")); }
#[test]
fn mask_strings_unclosed_string() {
assert_eq!(mask_strings(r#"let s = "hello"#, &[]), r#"let s = " "#);
}
#[test]
fn mask_strings_with_line_comment() {
assert_eq!(
mask_strings("x = 5; // don't do this", &["//"]),
"x = 5; "
);
}
#[test]
fn mask_strings_comment_after_string() {
assert_eq!(
mask_strings(r#"x = "hello"; // it's ok"#, &["//"]),
r#"x = " "; "#
);
}
#[test]
fn mask_strings_comment_marker_inside_string() {
assert_eq!(
mask_strings(r#"x = "http://foo"; if y"#, &["//"]),
r#"x = " "; if y"#
);
}
#[test]
fn read_and_classify_blanks_inline_tests_when_they_are_excluded() {
let (_dir, path) = crate::test_blocks::tests::source_with_test_module();
let spec = crate::loc::language::detect(&path).unwrap();
let code = |exclude_tests| {
let (lines, kinds) = read_and_classify(&path, spec, exclude_tests)
.unwrap()
.unwrap();
assert_eq!(lines.len(), kinds.len());
kinds.iter().filter(|k| **k == LineKind::Code).count()
};
assert_eq!(code(true), 3);
assert_eq!(code(false), 14);
}