-
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.
Fix escaping - and ^ inside character classes. (#36)
- Loading branch information
1 parent
7a0791c
commit 3c98910
Showing
3 changed files
with
67 additions
and
8 deletions.
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,58 @@ | ||
module Test17 | ||
|
||
if VERSION >= v"0.7-" | ||
using Test | ||
else | ||
using Base.Test | ||
end | ||
import Automa | ||
import Automa.RegExp: @re_str | ||
import Compat: lastindex, occursin | ||
|
||
@testset "Test17" begin | ||
re1 = re"[a\-c]" | ||
re1.actions[:enter] = [:enter] | ||
re1.actions[:exit] = [:exit] | ||
machine1 = Automa.compile(re1) | ||
@test occursin(r"^Automa.Machine\(<.*>\)$", repr(machine1)) | ||
|
||
for generator in (:table, :inline, :goto), checkbounds in (true, false), clean in (true, false) | ||
ctx = Automa.CodeGenContext(generator=generator, checkbounds=checkbounds, clean=clean) | ||
init_code = Automa.generate_init_code(ctx, machine1) | ||
exec_code = Automa.generate_exec_code(ctx, machine1, :debug) | ||
validate = @eval function (data) | ||
logger = Symbol[] | ||
$(init_code) | ||
p_end = p_eof = lastindex(data) | ||
$(exec_code) | ||
return cs == 0, logger | ||
end | ||
|
||
@test validate(b"-") == (true, [:enter, :exit]) | ||
@test validate(b"b") == (false, Symbol[]) | ||
end | ||
|
||
re2 = re"[a-c]" | ||
re2.actions[:enter] = [:enter] | ||
re2.actions[:exit] = [:exit] | ||
machine2 = Automa.compile(re2) | ||
@test occursin(r"^Automa.Machine\(<.*>\)$", repr(machine2)) | ||
|
||
for generator in (:table, :inline, :goto), checkbounds in (true, false), clean in (true, false) | ||
ctx = Automa.CodeGenContext(generator=generator, checkbounds=checkbounds, clean=clean) | ||
init_code = Automa.generate_init_code(ctx, machine2) | ||
exec_code = Automa.generate_exec_code(ctx, machine2, :debug) | ||
validate = @eval function (data) | ||
logger = Symbol[] | ||
$(init_code) | ||
p_end = p_eof = lastindex(data) | ||
$(exec_code) | ||
return cs == 0, logger | ||
end | ||
|
||
@test validate(b"-") == (false, []) | ||
@test validate(b"b") == (true, Symbol[:enter, :exit]) | ||
end | ||
end | ||
|
||
end |