-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error on compiling null regex
It is possible for users to construct a regex that matches the null set, i.e. no strings, not even the empty string. An example is `re"A" & re"B"`. Automa could support these, but don't currently, as there is no point to. However, attempting to compile such a regex currently throws an obscure internal error. This PR improves that error. See issue #104
- Loading branch information
1 parent
8b23e8b
commit d64ba0d
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Test13 | ||
|
||
using Automa | ||
using Test | ||
|
||
# Some cases of regex I've seen fail | ||
@testset "Test13" begin | ||
for (regex, good_strings, bad_strings) in [ | ||
(re"[AB]" & re"A", ["A"], ["B", "AA", "AB"]), | ||
(re"(A|B|C|D)" \ re"[A-C]", ["D"], ["AC", "A", "B", "DD"]), | ||
(!re"A[BC]D?E", ["ABCDE", "ABCE"], ["ABDE", "ACE", "ABE"]) | ||
] | ||
for goto in (false, true) | ||
machine = Automa.compile(regex) | ||
@eval $(Automa.generate_validator_function(:validate, machine, goto)) | ||
for string in good_strings | ||
@test validate(string) === nothing | ||
end | ||
for string in bad_strings | ||
@test validate(string) !== nothing | ||
end | ||
end | ||
end | ||
end | ||
|
||
end # module |