From e75fceff68ff4167b051390eaa4ec5c6d842aae6 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Wed, 23 Nov 2016 00:04:31 -0800 Subject: [PATCH] more ast specs --- spec/compiler_spec.moon | 73 ++++++++++++++++++++++++++++++++++++++++- spec/factory.moon | 6 +++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/spec/compiler_spec.moon b/spec/compiler_spec.moon index 0123353..c1c9577 100644 --- a/spec/compiler_spec.moon +++ b/spec/compiler_spec.moon @@ -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! diff --git a/spec/factory.moon b/spec/factory.moon index 5a1c498..a6f3d76 100644 --- a/spec/factory.moon +++ b/spec/factory.moon @@ -4,6 +4,10 @@ ref = (name="val") -> {"ref", name} +str = (contents="dogzone", delim='"') -> + {"string", delim, contents} + { - :var + :ref + :str }