mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
more ast specs
This commit is contained in:
parent
fc741a3c1e
commit
e75fceff68
@ -1,5 +1,6 @@
|
||||
import Block from require "moonscript.compile"
|
||||
import ref from require "spec.factory"
|
||||
|
||||
import ref, str from require "spec.factory"
|
||||
|
||||
-- no transform step
|
||||
class SimpleBlock extends Block
|
||||
@ -28,6 +29,76 @@ describe "moonscript.compile", ->
|
||||
-> {"ref", "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}", ->
|
||||
node = node!
|
||||
|
@ -4,6 +4,10 @@
|
||||
ref = (name="val") ->
|
||||
{"ref", name}
|
||||
|
||||
str = (contents="dogzone", delim='"') ->
|
||||
{"string", delim, contents}
|
||||
|
||||
{
|
||||
:var
|
||||
:ref
|
||||
:str
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user