start building ast spec

This commit is contained in:
leaf corcoran 2016-11-22 23:50:48 -08:00
parent 0998331a5d
commit fc741a3c1e
2 changed files with 45 additions and 0 deletions

36
spec/compiler_spec.moon Normal file
View File

@ -0,0 +1,36 @@
import Block from require "moonscript.compile"
import ref from require "spec.factory"
-- no transform step
class SimpleBlock extends Block
new: (...) =>
super ...
@transform = {
value: (...) -> ...
statement: (...) -> ...
}
value = require "moonscript.compile.value"
describe "moonscript.compile", ->
compile_node = (node) ->
block = SimpleBlock!
block\add block\value node
lines = block._lines\flatten!
lines[#lines] = nil if lines[#lines] == "\n"
table.concat lines
-- compiling lua ast
describe "value", ->
for {name, node, expected} in *{
{
"ref"
-> {"ref", "hello_world"}
"hello_world"
}
}
it "compiles #{name}", ->
node = node!
assert.same expected, compile_node(node)

9
spec/factory.moon Normal file
View File

@ -0,0 +1,9 @@
-- ast factory
ref = (name="val") ->
{"ref", name}
{
:var
}