1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

Merge pull request #4020 from ackerleytng/main

dircolors: align TERM matching behavior with that of GNU dircolors
This commit is contained in:
Sylvestre Ledru 2022-10-12 09:27:34 +02:00 committed by GitHub
commit b7c298afee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View file

@ -263,7 +263,7 @@ impl StrUtils for str {
} }
fn fnmatch(&self, pat: &str) -> bool { fn fnmatch(&self, pat: &str) -> bool {
pat.parse::<glob::Pattern>().unwrap().matches(self) parse_glob::from_str(pat).unwrap().matches(self)
} }
} }
@ -276,7 +276,7 @@ enum ParseState {
} }
use std::collections::HashMap; use std::collections::HashMap;
use uucore::format_usage; use uucore::{format_usage, parse_glob};
fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String> fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String>
where where

View file

@ -165,6 +165,47 @@ fn test_extra_operand() {
.no_stdout(); .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) { fn test_helper(file_name: &str, term: &str) {
new_ucmd!() new_ucmd!()
.env("TERM", term) .env("TERM", term)