mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
start building ast spec
This commit is contained in:
parent
0998331a5d
commit
fc741a3c1e
36
spec/compiler_spec.moon
Normal file
36
spec/compiler_spec.moon
Normal 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
9
spec/factory.moon
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
-- ast factory
|
||||
|
||||
ref = (name="val") ->
|
||||
{"ref", name}
|
||||
|
||||
{
|
||||
:var
|
||||
}
|
Loading…
Reference in New Issue
Block a user