Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tawheeler committed Aug 18, 2017
1 parent b95c507 commit 7c0cbe7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ExprRules.jl
Expand Up @@ -180,15 +180,15 @@ function Base.hash(node::RuleNode, h::UInt=zero(UInt))
end

function Base.show(io::IO, node::RuleNode; separator=",", last_child::Bool=false)
print(node.ind)
print(io, node.ind)
if !isempty(node.children)
print("{")
print(io, "{")
for (i,c) in enumerate(node.children)
show(io, c, separator=separator, last_child=(i == length(node.children)))
end
print("}")
print(io, "}")
elseif !last_child
print(separator)
print(io, separator)
end
end

Expand Down Expand Up @@ -226,7 +226,7 @@ function _get_executable(expr::Expr, rulenode::RuleNode, ruleset::RuleSet)
child = rulenode.children[j+=1]
ex.args[k] = !isnull(child._val) ?
get(child._val) : deepcopy(ruleset.rules[child.ind])
if !ruleset.isterminal[child.ind]
if !isterminal(ruleset, child)
ex.args[k] = _get_executable(ex.args[k], child, ruleset)
end
elseif isa(arg, Expr)
Expand Down
30 changes: 30 additions & 0 deletions test/runtests.jl
Expand Up @@ -27,6 +27,25 @@ let
@test contains_returntype(rulenode, ruleset, :R)
@test contains_returntype(rulenode, ruleset, :I)
@test !contains_returntype(rulenode, ruleset, :B)

io = IOBuffer()
show(io, rulenode)
@test String(take!(io)) == "1{2}"

display(rulenode, ruleset)
end

let
ruleset = @ruleset begin
Real = x
Real = Real * Real
Real = f(Real)
Real = _(Base.rand(1.0:5.0))
Real = A | B | g(Real)
Real = 1 | 2 | 3
Real = |(4:6)
Real = |([7,8,9])
end
end

x = 3
Expand Down Expand Up @@ -96,9 +115,20 @@ let

eval(rulenode, ruleset)

srand(0)
sample(rulenode)

srand(1)
sample(rulenode, :Real, ruleset)

srand(2)
loc = sample(NodeLoc, rulenode)
get(rulenode, loc)

srand(3)
insert!(rulenode, loc, rand(RuleNode, ruleset, :Real, 3))

srand(4)
rulenode = rand(RuleNode, ruleset, :Real)
loc = sample(NodeLoc, rulenode, :Real, ruleset)
end

0 comments on commit 7c0cbe7

Please sign in to comment.