Skip to content

Commit

Permalink
Merge 987bd0e into 0dcf7fa
Browse files Browse the repository at this point in the history
  • Loading branch information
cobac committed May 3, 2021
2 parents 0dcf7fa + 987bd0e commit ec0122e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ExprRules.jl
Expand Up @@ -576,7 +576,9 @@ function Base.insert!(root::RuleNode, loc::NodeLoc, rulenode::RuleNode)
if loc.i > 0
parent.children[i] = rulenode
else
root = rulenode
root.ind = rulenode.ind
root._val = rulenode._val
root.children = rulenode.children
end
return root
end
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Expand Up @@ -218,6 +218,18 @@ let
Random.seed!(3)
insert!(rulenode, loc, rand(RuleNode, grammar, :Real, 3))

node = RuleNode(1, [RuleNode(2), RuleNode(2)])
child_loc = NodeLoc(node, 1)
new = RuleNode(3)
inserted = insert!(node, child_loc, new)
@test node == inserted

node = RuleNode(1, [RuleNode(2), RuleNode(2)])
root_loc = NodeLoc(node, 0)
new = RuleNode(3)
inserted = insert!(node, root_loc, new)
@test node == inserted

Random.seed!(4)
rulenode = RuleNode(3, [RuleNode(4), RuleNode(5)])
for i in 1 : 10
Expand Down Expand Up @@ -446,4 +458,4 @@ let
@test all(interpret(S, Meta.parse("x .== y")) .== [false, true, false])
@test all(interpret(S, Meta.parse("b1 .& b2")) .== [true, false, true])
@test all(interpret(S, Meta.parse("b1 .| b2")) .== [true, true, true])
end
end

0 comments on commit ec0122e

Please sign in to comment.