Skip to content

Commit 356d61a

Browse files
committed
Test ensure, delete attrs, attrtypes
1 parent 0520c94 commit 356d61a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/syntax_graph.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
@testset "SyntaxGraph attrs" begin
2+
st = parsestmt(SyntaxTree, "function foo end")
3+
g_init = JuliaLowering.unfreeze_attrs(st._graph)
4+
gf1 = JuliaLowering.freeze_attrs(g_init)
5+
gu1 = JuliaLowering.unfreeze_attrs(gf1)
6+
7+
# Check that freeze/unfreeze do their jobs
8+
@test gf1.attributes isa NamedTuple
9+
@test gu1.attributes isa Dict
10+
@test Set(keys(gf1.attributes)) == Set(keys(gu1.attributes))
11+
12+
# ensure_attributes
13+
gf2 = JuliaLowering.ensure_attributes(gf1, test_attr=Symbol, foo=Type)
14+
gu2 = JuliaLowering.ensure_attributes(gu1, test_attr=Symbol, foo=Type)
15+
# returns a graph with the same attribute storage
16+
@test gf2.attributes isa NamedTuple
17+
@test gu2.attributes isa Dict
18+
# does its job
19+
@test (:test_attr, Symbol) in JuliaLowering.attrtypes(gf2)
20+
@test (:foo, Type) in JuliaLowering.attrtypes(gf2)
21+
@test Set(keys(gf2.attributes)) == Set(keys(gu2.attributes))
22+
# no mutation
23+
@test !((:test_attr, Symbol) in JuliaLowering.attrtypes(gf1))
24+
@test !((:foo, Type) in JuliaLowering.attrtypes(gf1))
25+
@test Set(keys(gf1.attributes)) == Set(keys(gu1.attributes))
26+
27+
# delete_attributes
28+
gf3 = JuliaLowering.delete_attributes(gf2, :test_attr, :foo)
29+
gu3 = JuliaLowering.delete_attributes(gu2, :test_attr, :foo)
30+
# returns a graph with the same attribute storage
31+
@test gf3.attributes isa NamedTuple
32+
@test gu3.attributes isa Dict
33+
# does its job
34+
@test !((:test_attr, Symbol) in JuliaLowering.attrtypes(gf3))
35+
@test !((:foo, Type) in JuliaLowering.attrtypes(gf3))
36+
@test Set(keys(gf3.attributes)) == Set(keys(gu3.attributes))
37+
# no mutation
38+
@test (:test_attr, Symbol) in JuliaLowering.attrtypes(gf2)
39+
@test (:foo, Type) in JuliaLowering.attrtypes(gf2)
40+
@test Set(keys(gf2.attributes)) == Set(keys(gu2.attributes))
41+
end
42+
143
@testset "SyntaxTree" begin
244
# Expr conversion
345
@test Expr(parsestmt(SyntaxTree, "begin a + b ; c end", filename="none")) ==

0 commit comments

Comments
 (0)