Skip to content

Commit 5e80348

Browse files
committed
Improve Regex.escape tests
1 parent caeea89 commit 5e80348

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/elixir/test/elixir/regex_test.exs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,35 @@ defmodule Regex.BinaryTest do
129129
end
130130

131131
test :escape do
132-
assert escaping(".", ".")
133-
refute escaping(".", "x")
132+
assert matches_escaped?(".")
133+
refute matches_escaped?(".", "x")
134134
135-
assert escaping("[\w]", "[\w]")
136-
refute escaping("[\w]", "x")
135+
assert matches_escaped?("[\w]")
136+
refute matches_escaped?("[\w]", "x")
137137
138-
assert escaping("\\", "\\")
138+
assert matches_escaped?("\\")
139139
140-
assert escaping("\\xff", "\\xff")
141-
refute escaping("\\xff", "\xff")
140+
assert matches_escaped?("\\xff", "\\xff")
141+
refute matches_escaped?("\\xff", "\xff")
142142
143-
assert escaping("(", "(")
144-
assert escaping("()", "()")
145-
assert escaping("(?:foo)", "(?:foo)")
143+
assert matches_escaped?("(")
144+
assert matches_escaped?("()")
145+
assert matches_escaped?("(?:foo)")
146146

147-
assert escaping("\\A \\z", "\\A \\z")
148-
assert escaping(" x ", " x ")
149-
assert escaping("  x    x ", "  x    x ") # unicode spaces here
150-
assert escaping("# lol", "# lol")
147+
assert matches_escaped?("\\A \\z")
148+
assert matches_escaped?(" x ")
149+
assert matches_escaped?("  x    x ") # unicode spaces here
150+
assert matches_escaped?("# lol")
151+
152+
assert matches_escaped?("\\A.^$*+?()[{\\| \t\n\xff\\z #hello\x{202F}\x{205F}")
153+
end
154+
155+
defp matches_escaped?(string) do
156+
matches_escaped?(string, string)
151157
end
152158

153-
defp escaping(string, match) do
154-
Regex.match? %r/#{Regex.escape(string)}/xu, match
159+
defp matches_escaped?(string, match) do
160+
Regex.match? %r/#{Regex.escape(string)}/usimx, match
155161
end
156162
end
157163

0 commit comments

Comments
 (0)