more ast specs

This commit is contained in:
leaf corcoran 2016-11-23 00:04:31 -08:00
parent fc741a3c1e
commit e75fceff68
2 changed files with 77 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import Block from require "moonscript.compile" import Block from require "moonscript.compile"
import ref from require "spec.factory"
import ref, str from require "spec.factory"
-- no transform step -- no transform step
class SimpleBlock extends Block class SimpleBlock extends Block
@ -28,6 +29,76 @@ describe "moonscript.compile", ->
-> {"ref", "hello_world"} -> {"ref", "hello_world"}
"hello_world" "hello_world"
} }
{
"explist"
-> { "explist", ref("a"), ref("b"), ref("c")}
"a, b, c"
}
{
"parens"
-> { "parens", ref! }
"(val)"
}
{
"string (single quote)"
-> {"string", "'", "Hello\\'s world"}
"'Hello\\'s world'"
}
{
"string (double quote)"
-> {"string", '"', "Hello's world"}
[["Hello's world"]]
}
{
"string (lua)"
-> {"string", '[==[', "Hello's world"}
"[==[Hello's world]==]"
}
{
"chain (single)"
-> {"chain", ref!}
"val"
}
{
"chain (dot)"
-> {"chain", ref!, {"dot", "zone"} }
"val.zone"
}
{
"chain (index)"
-> {"chain", ref!, {"index", ref("x") } }
"val[x]"
}
{
"chain (call)"
-> {"chain", ref!, {"call", { ref("arg") }} }
"val(arg)"
}
{
"chain"
-> {
"chain"
ref!
{"dot", "one"}
{"index", str!}
{"colon", "two"}
{"call", { ref("arg") }}
}
'val.one["dogzone"]:two(arg)'
}
} }
it "compiles #{name}", -> it "compiles #{name}", ->
node = node! node = node!

View File

@ -4,6 +4,10 @@
ref = (name="val") -> ref = (name="val") ->
{"ref", name} {"ref", name}
str = (contents="dogzone", delim='"') ->
{"string", delim, contents}
{ {
:var :ref
:str
} }