tests are now passing on symbology

This commit is contained in:
Jeremy Ashkenas
2010-07-24 22:23:37 -07:00
parent 492ee57b8f
commit 88847df70b
42 changed files with 514 additions and 522 deletions

View File

@@ -1,40 +1,40 @@
# Simple variable swapping.
a: -1
b: -2
a = -1
b = -2
[a, b]: [b, a]
[a, b] = [b, a]
ok a is -2
ok b is -1
func: ->
[a, b]: [b, a]
func = ->
[a, b] = [b, a]
ok func().join(' ') is '-1 -2'
noop: ->
noop = ->
noop [a,b]: [c,d]: [1,2]
noop [a,b] = [c,d] = [1,2]
ok a is 1 and b is 2
# Array destructuring, including splats.
arr: [1, 2, 3]
arr = [1, 2, 3]
[a, b, c]: arr
[a, b, c] = arr
ok a is 1
ok b is 2
ok c is 3
[x,y...,z]: [1,2,3,4,5]
[x,y...,z] = [1,2,3,4,5]
ok x is 1
ok y.length is 3
ok z is 5
[x, [y, mids..., last], z..., end]: [1, [10, 20, 30, 40], 2,3,4, 5]
[x, [y, mids..., last], z..., end] = [1, [10, 20, 30, 40], 2,3,4, 5]
ok x is 1
ok y is 10
@@ -45,15 +45,15 @@ ok end is 5
# Object destructuring.
obj: {x: 10, y: 20, z: 30}
obj = {x: 10, y: 20, z: 30}
{x: a, y: b, z: c}: obj
{x: a, y: b, z: c} = obj
ok a is 10
ok b is 20
ok c is 30
person: {
person = {
name: "Moe"
family: {
'elder-brother': {
@@ -68,12 +68,12 @@ person: {
}
}
{name: a, family: {'elder-brother': {addresses: [one, {city: b}]}}}: person
{name: a, family: {'elder-brother': {addresses: [one, {city: b}]}}} = person
ok a is "Moe"
ok b is "Moquasset NY, 10021"
test: {
test = {
person: {
address: [
"------"
@@ -84,13 +84,13 @@ test: {
}
}
{person: {address: [ignore, addr...]}}: test
{person: {address: [ignore, addr...]}} = test
ok addr.join(', ') is "Street 101, Apt 101, City 101"
# Pattern matching against an expression.
[a, b]: if true then [2, 1] else [1, 2]
[a, b] = if true then [2, 1] else [1, 2]
ok a is 2
ok b is 1
@@ -98,13 +98,13 @@ ok b is 1
# Pattern matching with object shorthand.
person: {
person = {
name: "Bob"
age: 26
dogs: ["Prince", "Bowie"]
}
{name, age, dogs: [first, second]}: person
{name, age, dogs: [first, second]} = person
ok name is "Bob"
ok age is 26
@@ -113,27 +113,27 @@ ok second is "Bowie"
# Pattern matching within for..loops
persons: {
persons = {
George: { name: "Bob" },
Bob: { name: "Alice" }
Christopher: { name: "Stan" }
}
join1: "$key: $name" for key, { name } of persons
join1 = "$key: $name" for key, { name } of persons
deepEqual join1, ["George: Bob", "Bob: Alice", "Christopher: Stan"]
persons: [
persons = [
{ name: "Bob", parent: { name: "George" } },
{ name: "Alice", parent: { name: "Bob" } },
{ name: "Stan", parent: { name: "Christopher" } }
]
join2: "$parent: $name" for { name, parent: { name: parent } } in persons
join2 = "$parent: $name" for { name, parent: { name: parent } } in persons
deepEqual join1, join2
persons: [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
join3: "$parent: $name" for [name, [parent]] in persons
persons = [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
join3 = "$parent: $name" for [name, [parent]] in persons
deepEqual join2, join3