diff options
author | Hubert GÅ‚uchowski <hubert.gluchowski19@gmail.com> | 2022-01-20 17:48:38 +0100 |
---|---|---|
committer | Hubert GÅ‚uchowski <hubert.gluchowski19@gmail.com> | 2022-01-20 18:18:07 +0100 |
commit | b03fe13b5bb5ce540215a7e8df0d63a99f389db5 (patch) | |
tree | 2df69a4929d1b2e9fb318fa879b01d1fc30065a2 | |
parent | 9510ad10c54d906ec2597d3baa81d0f0f97b1f77 (diff) |
Add some tests for multiple regex/match highlighting in `nix search`
-rw-r--r-- | tests/search.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/search.sh b/tests/search.sh index ee3261687..52e12f381 100644 --- a/tests/search.sh +++ b/tests/search.sh @@ -23,3 +23,16 @@ clearCache nix search -f search.nix '' |grep -q foo nix search -f search.nix '' |grep -q bar nix search -f search.nix '' |grep -q hello + +## Tests for multiple regex/match highlighting + +e=$'\x1b' # grep doesn't support \e, \033 or even \x1b +# Multiple overlapping regexes +(( $(nix search -f search.nix '' 'oo' 'foo' 'oo' | grep "$e\[32;1mfoo$e\\[0;1m" | wc -l) == 1 )) +(( $(nix search -f search.nix '' 'broken b' 'en bar' | grep "$e\[32;1mbroken bar$e\\[0m" | wc -l) == 1 )) + +# Multiple matches +# Searching for 'o' should yield the 'o' in 'broken bar', the 'oo' in foo and 'o' in hello +(( $(nix search -f search.nix '' 'o' | grep -Eo "$e\[32;1mo{1,2}$e\[(0|0;1)m" | wc -l) == 3 )) +# Searching for 'b' should yield the 'b' in bar and the two 'b's in 'broken bar' +(( $(nix search -f search.nix '' 'b' | grep -Eo "$e\[32;1mb$e\[(0|0;1)m" | wc -l) == 3 )) |