Skip to content

Commit

Permalink
Case insensitive --map-syntax (#2650)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas AMBRY <nicolas.ambry@atos.net>
  • Loading branch information
AmbryN and Nicolas AMBRY authored Sep 14, 2023
1 parent e2bf85e commit 5a240f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## Bugfixes

- Fix `more` not being found on Windows when provided via `BAT_PAGER`, see #2570, #2580, and #2651 (@mataha)
- Switched default behavior of `--map-syntax` to be case insensitive #2520

## Other

Expand Down
2 changes: 1 addition & 1 deletion src/syntax_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<'a> SyntaxMapping<'a> {

pub fn insert(&mut self, from: &str, to: MappingTarget<'a>) -> Result<()> {
let glob = GlobBuilder::new(from)
.case_insensitive(false)
.case_insensitive(true)
.literal_separator(true)
.build()?;
self.mappings.push((glob.compile_matcher(), to));
Expand Down
1 change: 1 addition & 0 deletions tests/examples/map-syntax_case.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"test": "value"}
24 changes: 24 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,3 +2385,27 @@ fn lessopen_validity() {
"\u{1b}[33m[bat warning]\u{1b}[0m: LESSOPEN ignored: must contain exactly one %s\n",
);
}

// Regression test for issue #2520 and PR #2650
// Syntax highlighting should be the same regardless of
// --map-syntax' case or file extension's case
#[test]
fn highlighting_independant_from_map_syntax_case() {
let expected = bat()
.arg("-f")
.arg("--map-syntax=*.config:JSON")
.arg("map-syntax_case.Config")
.assert()
.get_output()
.stdout
.clone();

bat()
.arg("-f")
.arg("--map-syntax=*.Config:JSON")
.arg("map-syntax_case.Config")
.assert()
.success()
.stdout(expected)
.stderr("");
}

0 comments on commit 5a240f3

Please sign in to comment.