use stern4rust::settings::rule_selection::RuleSelection;
const KNOWN: [&str; 3] = ["header", "test-file-structure", "tests-layout"];
fn selection(selected: &[&str], skipped: &[&str]) -> RuleSelection {
RuleSelection::new(
selected.iter().map(|name| (*name).to_string()).collect(),
skipped.iter().map(|name| (*name).to_string()).collect(),
)
}
#[test]
fn also_skipping_a_rule_already_skipped_names_it_once() {
let selection = RuleSelection::new(Vec::new(), vec!["paired-test-file".to_string()]);
let widened = selection.also_skipping(&["paired-test-file".to_string()]);
assert_eq!(widened.unknown_in(&["header"]), vec!["paired-test-file"]);
}
#[test]
fn also_skipping_adds_to_what_was_already_skipped() {
let selection = RuleSelection::new(Vec::new(), vec!["test-naming".to_string()]);
let widened = selection.also_skipping(&["paired-test-file".to_string()]);
assert!(!widened.includes("paired-test-file"));
assert!(!widened.includes("test-naming"));
}
#[test]
fn also_skipping_leaves_the_rules_it_was_not_given_applying() {
let selection = RuleSelection::new(Vec::new(), Vec::new());
let widened = selection.also_skipping(&["paired-test-file".to_string()]);
assert!(widened.includes("header"));
}
#[test]
fn default_includes_every_rule() {
let selection = RuleSelection::default();
assert!(selection.includes("header"));
assert!(selection.includes("tests-layout"));
}
#[test]
fn includes_a_rule_that_was_selected() {
let selection = selection(&["header"], &[]);
assert!(selection.includes("header"));
}
#[test]
fn includes_of_a_rule_both_selected_and_skipped_is_false() {
let selection = selection(&["header"], &["header"]);
assert!(!selection.includes("header"));
}
#[test]
fn includes_of_a_rule_outside_an_explicit_selection_is_false() {
let selection = selection(&["header"], &[]);
assert!(!selection.includes("tests-layout"));
}
#[test]
fn includes_of_a_skipped_rule_is_false() {
let selection = selection(&[], &["tests-layout"]);
assert!(!selection.includes("tests-layout"));
assert!(selection.includes("header"));
}
#[test]
fn selects_explicitly_of_a_named_rule_is_true() {
let selection = selection(&["header"], &[]);
assert!(selection.selects_explicitly("header"));
}
#[test]
fn selects_explicitly_with_no_selection_is_false() {
let selection = RuleSelection::default();
assert!(!selection.selects_explicitly("header"));
}
#[test]
fn unknown_in_checks_both_switches() {
let selection = selection(&["heder"], &["tets-layout"]);
assert_eq!(selection.unknown_in(&KNOWN), ["heder", "tets-layout"]);
}
#[test]
fn unknown_in_names_a_misspelled_rule() {
let selection = selection(&[], &["test-file-strucutre"]);
assert_eq!(selection.unknown_in(&KNOWN), ["test-file-strucutre"]);
}
#[test]
fn unknown_in_of_valid_names_is_empty() {
let selection = selection(&["header"], &["tests-layout"]);
assert!(selection.unknown_in(&KNOWN).is_empty());
}