1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 19:36:16 +00:00

dircolors: align TERM matching behavior with that of GNU dircolors

This commit is contained in:
Ackerley Tng 2022-07-31 10:38:56 -07:00
parent 8c504edfca
commit 1239fc477b
2 changed files with 43 additions and 2 deletions

View file

@ -165,6 +165,47 @@ fn test_extra_operand() {
.no_stdout();
}
#[test]
fn test_term_matching() {
fn check(term_pattern: &str, term: &str, expectation: &str) {
let theme = format!(
"
TERM {term_pattern}
.term_matching 00;38;5;61
"
);
new_ucmd!()
.env("TERM", term)
.pipe_in(theme)
.args(&["-b", "-"])
.succeeds()
.stdout_is(expectation)
.no_stderr();
}
let expectation_if_match = r#"
LS_COLORS='*.term_matching=00;38;5;61:';
export LS_COLORS
"#
.trim_start();
let expectation_if_no_match = r#"
LS_COLORS='';
export LS_COLORS
"#
.trim_start();
// sanity checks
check("matches", "matches", expectation_if_match);
check("matches", "no_match", expectation_if_no_match);
// character set negation should treat ^ like !
check("[!a]_negation", "a_negation", expectation_if_no_match);
check("[!a]_negation", "b_negation", expectation_if_match);
check("[^a]_negation", "a_negation", expectation_if_no_match);
check("[^a]_negation", "b_negation", expectation_if_match);
}
fn test_helper(file_name: &str, term: &str) {
new_ucmd!()
.env("TERM", term)