Skip to content

Commit e75fcef

Browse files
committed
more ast specs
1 parent fc741a3 commit e75fcef

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

spec/compiler_spec.moon

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Block from require "moonscript.compile"
2-
import ref from require "spec.factory"
2+
3+
import ref, str from require "spec.factory"
34

45
-- no transform step
56
class SimpleBlock extends Block
@@ -28,6 +29,76 @@ describe "moonscript.compile", ->
2829
-> {"ref", "hello_world"}
2930
"hello_world"
3031
}
32+
33+
{
34+
"explist"
35+
-> { "explist", ref("a"), ref("b"), ref("c")}
36+
"a, b, c"
37+
}
38+
39+
{
40+
"parens"
41+
-> { "parens", ref! }
42+
"(val)"
43+
}
44+
45+
{
46+
"string (single quote)"
47+
-> {"string", "'", "Hello\\'s world"}
48+
"'Hello\\'s world'"
49+
}
50+
51+
{
52+
"string (double quote)"
53+
-> {"string", '"', "Hello's world"}
54+
[["Hello's world"]]
55+
56+
}
57+
58+
{
59+
"string (lua)"
60+
-> {"string", '[==[', "Hello's world"}
61+
"[==[Hello's world]==]"
62+
}
63+
64+
{
65+
"chain (single)"
66+
-> {"chain", ref!}
67+
"val"
68+
}
69+
70+
{
71+
"chain (dot)"
72+
-> {"chain", ref!, {"dot", "zone"} }
73+
"val.zone"
74+
}
75+
76+
{
77+
"chain (index)"
78+
-> {"chain", ref!, {"index", ref("x") } }
79+
"val[x]"
80+
}
81+
82+
83+
{
84+
"chain (call)"
85+
-> {"chain", ref!, {"call", { ref("arg") }} }
86+
"val(arg)"
87+
}
88+
89+
{
90+
"chain"
91+
-> {
92+
"chain"
93+
ref!
94+
{"dot", "one"}
95+
{"index", str!}
96+
{"colon", "two"}
97+
{"call", { ref("arg") }}
98+
}
99+
'val.one["dogzone"]:two(arg)'
100+
}
101+
31102
}
32103
it "compiles #{name}", ->
33104
node = node!

spec/factory.moon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
ref = (name="val") ->
55
{"ref", name}
66

7+
str = (contents="dogzone", delim='"') ->
8+
{"string", delim, contents}
9+
710
{
8-
:var
11+
:ref
12+
:str
913
}

0 commit comments

Comments
 (0)