add some specs for name extract

This commit is contained in:
leaf corcoran 2015-09-29 20:47:27 -07:00
parent e94494721a
commit 02a20ea695
3 changed files with 52 additions and 2 deletions

View File

@ -228,5 +228,6 @@ end
return {
has_destructure = has_destructure,
split_assign = split_assign,
build_assign = build_assign
build_assign = build_assign,
extract_assign_names = extract_assign_names
}

View File

@ -123,4 +123,4 @@ split_assign = (scope, assign) ->
build.group g
{ :has_destructure, :split_assign, :build_assign }
{ :has_destructure, :split_assign, :build_assign, :extract_assign_names }

View File

@ -1,6 +1,55 @@
import with_dev from require "spec.helpers"
describe "moonscript.transform.destructure", ->
local extract_assign_names
with_dev ->
{ :extract_assign_names } = require "moonscript.transform.destructure"
it "extracts names from table destructure", ->
des = {
"table"
{
{{"key_literal", "hi"}, {"ref", "hi"}}
{{"key_literal", "world"}, {"ref", "world"}}
}
}
assert.same {
{
{"ref", "hi"} -- target
{
{"dot", "hi"}
} -- chain suffix
}
{
{"ref", "world"}
{
{"dot", "world"}
}
}
}, extract_assign_names des
it "extracts names from array destructure", ->
des = {
"table"
{
{{"ref", "hi"}}
}
}
assert.same {
{
{"ref", "hi"}
{
{"index", {"number", 1}}
}
}
}, extract_assign_names des
describe "moonscript.transform.statements", ->
local last_stm, transform_last_stm, Run