Skip to content

Commit

Permalink
bump up code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 committed Feb 25, 2017
1 parent 789b615 commit 125dd72
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
8 changes: 0 additions & 8 deletions src/byteset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ function Base.:(==)(s1::ByteSet, s2::ByteSet)
return s1.a == s2.a && s1.b == s2.b && s1.c == s2.c && s1.d == s2.d
end

function Base.hash(s::ByteSet, h::UInt)
x = hash(s.a, h)
x = xor(x, hash(s.b, h))
x = xor(x, hash(s.c, h))
x = xor(x, hash(s.d, h))
return x
end

function Base.in(byte::UInt8, set::ByteSet)
if byte < 0x40
return set.a & (UInt64(1) << (byte - 0x00)) != 0
Expand Down
11 changes: 0 additions & 11 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,6 @@ function generate_transition_code(machine::Machine, actions::Dict{Symbol,Expr})
end
end

function compact_transition{T}(trans::Dict{UInt8,T})
revtrans = Dict{T,Vector{UInt8}}()
for (l, val) in trans
if !haskey(revtrans, val)
revtrans[val] = UInt8[]
end
push!(revtrans[val], l)
end
return [(ByteSet(ls), val) for (val, ls) in revtrans]
end

function generate_goto_code(machine::Machine, actions::Dict{Symbol,Expr}, check::Bool)
actions_in = Dict{Node,Set{Vector{Symbol}}}()
for s in traverse(machine.start), (e, t) in s.edges
Expand Down
28 changes: 28 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,34 @@ module Test12
@test validate(b"aaab") == ([:a, :a, :a], :error)
end

module Test13
import Automa
import Automa.RegExp: @re_str
const re = Automa.RegExp
using Base.Test

abra = re"abra"
ca = re"(ca)+"
ca.actions[:enter] = [:ca_enter]
ca.actions[:exit] = [:ca_exit]
dabra = re"dabra"
machine = Automa.compile(re.cat(abra, ca, dabra))
@eval function validate(data)
logger = Symbol[]
$(Automa.generate_init_code(machine))
p_end = p_eof = sizeof(data)
$(Automa.generate_exec_code(machine, actions=:debug, code=:inline, clean=true))
return logger, cs == 0 ? :ok : cs < 0 ? :error : :incomplete
end
@test validate(b"a") == ([], :incomplete)
@test validate(b"abrac") == ([:ca_enter], :incomplete)
@test validate(b"abraca") == ([:ca_enter], :incomplete)
@test validate(b"abracad") == ([:ca_enter, :ca_exit], :incomplete)
@test validate(b"abracadabra") == ([:ca_enter, :ca_exit], :ok)
@test validate(b"abracacadabra") == ([:ca_enter, :ca_exit], :ok)
@test validate(b"abrad") == ([], :error)
end

module TestDOT
import Automa
import Automa.RegExp: @re_str
Expand Down

0 comments on commit 125dd72

Please sign in to comment.