Skip to content

Commit 8f5fff1

Browse files
committed
test(glob): Normalize some strings to compare
Some of the files have unicode characters that can be represented in multiple ways, so we normalize them. Specifically: 'e\u0301' ('e' + 'Combining Acute Accent') doesn't equal '\xe9' (LATIN SMALL LETTER E WITH ACUTE) unless you normalize them.
1 parent 153fcc2 commit 8f5fff1

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

test/t/unit/test_unit_expand_glob.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
import unicodedata
2+
13
import pytest
24

35
from conftest import assert_bash_exec, bash_env_saved
46

57

8+
def normalize(string):
9+
# Applies "canonical decomposition", so might make errors look weird?
10+
# The alternative is probably `NFC` which composes together some of
11+
# the characters again.
12+
# See https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize
13+
return unicodedata.normalize("NFD", string)
14+
15+
616
@pytest.mark.bashcomp(
717
cmd=None,
818
cwd="_filedir",
@@ -22,14 +32,15 @@ def functions(self, bash):
2232

2333
def test_match_all(self, bash, functions):
2434
output = assert_bash_exec(bash, "__tester '*'", want_output=True)
25-
assert (
26-
output.strip()
27-
== "<a b><a$b><a&b><a'b><ab><aé><brackets><dotdot><ext>"
35+
assert normalize(output.strip()) == normalize(
36+
"<a b><a$b><a&b><a'b><ab><aé><brackets><dotdot><ext>"
2837
)
2938

3039
def test_match_pattern(self, bash, functions):
3140
output = assert_bash_exec(bash, "__tester 'a*'", want_output=True)
32-
assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>"
41+
assert normalize(output.strip()) == normalize(
42+
"<a b><a$b><a&b><a'b><ab><aé>"
43+
)
3344

3445
def test_match_unmatched(self, bash, functions):
3546
output = assert_bash_exec(
@@ -51,7 +62,9 @@ def test_protect_from_noglob(self, bash, functions):
5162
with bash_env_saved(bash, functions) as bash_env:
5263
bash_env.set("noglob", True)
5364
output = assert_bash_exec(bash, "__tester 'a*'", want_output=True)
54-
assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>"
65+
assert normalize(output.strip()) == normalize(
66+
"<a b><a$b><a&b><a'b><ab><aé>"
67+
)
5568

5669
def test_protect_from_failglob(self, bash, functions):
5770
with bash_env_saved(bash) as bash_env:
@@ -83,4 +96,6 @@ def test_protect_from_GLOBIGNORE(self, bash, functions):
8396
bash_env.save_shopt("dotglob")
8497
bash_env.write_variable("GLOBIGNORE", "*")
8598
output = assert_bash_exec(bash, "__tester 'a*'", want_output=True)
86-
assert output.strip() == "<a b><a$b><a&b><a'b><ab><aé>"
99+
assert normalize(output.strip()) == normalize(
100+
"<a b><a$b><a&b><a'b><ab><aé>"
101+
)

0 commit comments

Comments
 (0)