finished converting the test suite, to run it, do: bin/node_coffee -r tasks.coffee -- test
This commit is contained in:
parent
b41afe79b4
commit
a8a46257ae
|
@ -1,5 +1,3 @@
|
|||
# Assign to try/catch.
|
||||
|
||||
result: try
|
||||
nonexistent * missing
|
||||
catch error
|
||||
|
@ -7,17 +5,15 @@ catch error
|
|||
|
||||
result2: try nonexistent * missing catch error then true
|
||||
|
||||
puts result is true and result2 is true
|
||||
ok result is true and result2 is true, 'can assign the result of a try/catch block'
|
||||
|
||||
|
||||
# Assign to conditional.
|
||||
|
||||
get_x: -> 10
|
||||
|
||||
if x: get_x() then 100
|
||||
|
||||
puts x is 10
|
||||
ok x is 10, 'can assign a conditional statement'
|
||||
|
||||
x: if get_x() then 100
|
||||
|
||||
puts x is 100
|
||||
ok x is 100, 'can assign a conditional statement'
|
|
@ -1,4 +1,4 @@
|
|||
results: [1, 2, 3].map (x) ->
|
||||
x * x
|
||||
|
||||
puts results.join(' ') is '1 4 9'
|
||||
ok results.join(' ') is '1 4 9', 'basic block syntax'
|
|
@ -21,7 +21,7 @@ ThirdChild::func: (string) ->
|
|||
|
||||
result: (new ThirdChild()).func 'four'
|
||||
|
||||
puts result is 'zero/one/two/three/four'
|
||||
ok result is 'zero/one/two/three/four', 'successfully set up and called a four-level inheritance chain'
|
||||
|
||||
|
||||
TopClass: (arg) ->
|
||||
|
@ -39,4 +39,4 @@ SubClass: ->
|
|||
SuperClass extends TopClass
|
||||
SubClass extends SuperClass
|
||||
|
||||
puts((new SubClass()).prop is 'top-super-sub')
|
||||
ok (new SubClass()).prop is 'top-super-sub', 'inheritance'
|
|
@ -3,7 +3,7 @@ identity_wrap: (x) ->
|
|||
|
||||
result: identity_wrap(identity_wrap(true))()()
|
||||
|
||||
puts result
|
||||
ok result, 'basic chained function calls'
|
||||
|
||||
|
||||
str: 'god'
|
||||
|
@ -14,7 +14,7 @@ result: str.
|
|||
reverse().
|
||||
reverse()
|
||||
|
||||
puts result.join('') is 'dog'
|
||||
ok result.join('') is 'dog', 'chained accesses split on period/newline'
|
||||
|
||||
result: str
|
||||
.split('')
|
||||
|
@ -22,4 +22,4 @@ result: str
|
|||
.reverse()
|
||||
.reverse()
|
||||
|
||||
puts result.join('') is 'dog'
|
||||
ok result.join('') is 'dog', 'chained accesses split on newline/period'
|
|
@ -3,26 +3,26 @@ b: -2
|
|||
|
||||
[a, b]: [b, a]
|
||||
|
||||
puts a is -2
|
||||
puts b is -1
|
||||
ok a is -2
|
||||
ok b is -1
|
||||
|
||||
|
||||
arr: [1, 2, 3]
|
||||
|
||||
[a, b, c]: arr
|
||||
|
||||
puts a is 1
|
||||
puts b is 2
|
||||
puts c is 3
|
||||
ok a is 1
|
||||
ok b is 2
|
||||
ok c is 3
|
||||
|
||||
|
||||
obj: {x: 10, y: 20, z: 30}
|
||||
|
||||
{x: a, y: b, z: c}: obj
|
||||
|
||||
puts a is 10
|
||||
puts b is 20
|
||||
puts c is 30
|
||||
ok a is 10
|
||||
ok b is 20
|
||||
ok c is 30
|
||||
|
||||
|
||||
person: {
|
||||
|
@ -42,8 +42,8 @@ person: {
|
|||
|
||||
{name: a, family: {brother: {addresses: [one, {city: b}]}}}: person
|
||||
|
||||
puts a is "Bob"
|
||||
puts b is "Moquasset NY, 10021"
|
||||
ok a is "Bob"
|
||||
ok b is "Moquasset NY, 10021"
|
||||
|
||||
|
||||
test: {
|
||||
|
@ -59,4 +59,4 @@ test: {
|
|||
|
||||
{person: {address: [ignore, addr...]}}: test
|
||||
|
||||
puts addr.join(', ') is "Street 101, Apt 101, City 101"
|
||||
ok addr.join(', ') is "Street 101, Apt 101, City 101"
|
|
@ -26,4 +26,4 @@ func: ->
|
|||
|
||||
c.single: c.list[1..1][0]
|
||||
|
||||
puts func() is '-'
|
||||
ok func() is '-'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
puts(if my_special_variable? then false else true)
|
||||
ok(if my_special_variable? then false else true)
|
||||
|
||||
my_special_variable: false
|
||||
|
||||
puts(if my_special_variable? then true else false)
|
||||
ok(if my_special_variable? then true else false)
|
||||
|
||||
|
||||
# Existential assignment.
|
||||
|
@ -12,7 +12,7 @@ a: null
|
|||
a ?= 10
|
||||
b ?= 10
|
||||
|
||||
puts a is 10 and b is 10
|
||||
ok a is 10 and b is 10
|
||||
|
||||
|
||||
# The existential operator.
|
||||
|
@ -20,7 +20,7 @@ puts a is 10 and b is 10
|
|||
z: null
|
||||
x: z ? "EX"
|
||||
|
||||
puts z is null and x is "EX"
|
||||
ok z is null and x is "EX"
|
||||
|
||||
|
||||
# Only evaluate once.
|
||||
|
@ -30,7 +30,7 @@ get_next_node: ->
|
|||
throw "up" if counter
|
||||
counter++
|
||||
|
||||
puts(if get_next_node()? then true else false)
|
||||
ok(if get_next_node()? then true else false)
|
||||
|
||||
|
||||
# Existence chains, soaking up undefined properties:
|
||||
|
@ -39,19 +39,19 @@ obj: {
|
|||
prop: "hello"
|
||||
}
|
||||
|
||||
puts obj?.prop is "hello"
|
||||
ok obj?.prop is "hello"
|
||||
|
||||
puts obj.prop?.length is 5
|
||||
ok obj.prop?.length is 5
|
||||
|
||||
puts obj?.prop?.non?.existent?.property is undefined
|
||||
ok obj?.prop?.non?.existent?.property is undefined
|
||||
|
||||
|
||||
# Soaks and caches method calls as well.
|
||||
|
||||
arr: ["--", "----"]
|
||||
|
||||
puts arr.pop()?.length is 4
|
||||
puts arr.pop()?.length is 2
|
||||
puts arr.pop()?.length is undefined
|
||||
puts arr[0]?.length is undefined
|
||||
puts arr.pop()?.length?.non?.existent()?.property is undefined
|
||||
ok arr.pop()?.length is 4
|
||||
ok arr.pop()?.length is 2
|
||||
ok arr.pop()?.length is undefined
|
||||
ok arr[0]?.length is undefined
|
||||
ok arr.pop()?.length?.non?.existent()?.property is undefined
|
||||
|
|
|
@ -9,7 +9,7 @@ findit: (items) ->
|
|||
for item in items
|
||||
return item if item is "bacon"
|
||||
|
||||
puts findit(items) is "bacon"
|
||||
ok findit(items) is "bacon"
|
||||
|
||||
|
||||
# When when a closure wrapper is generated for expression conversion, make sure
|
||||
|
@ -26,5 +26,5 @@ obj: {
|
|||
this.num
|
||||
}
|
||||
|
||||
puts obj.num is obj.func()
|
||||
puts obj.num is obj.result
|
||||
ok obj.num is obj.func()
|
||||
ok obj.num is obj.result
|
|
@ -7,13 +7,13 @@ result: if a
|
|||
if d
|
||||
true
|
||||
|
||||
puts result
|
||||
ok result
|
||||
|
||||
|
||||
first: if false then false else second: if false then false else true
|
||||
|
||||
puts first
|
||||
puts second
|
||||
ok first
|
||||
ok second
|
||||
|
||||
|
||||
result: if false
|
||||
|
@ -23,4 +23,4 @@ else if NaN
|
|||
else
|
||||
true
|
||||
|
||||
puts result
|
||||
ok result
|
|
@ -2,11 +2,11 @@ x: 1
|
|||
y: {}
|
||||
y.x: -> 3
|
||||
|
||||
puts x is 1
|
||||
puts typeof(y.x) is 'function'
|
||||
puts y.x instanceof Function
|
||||
puts y.x() is 3
|
||||
puts y.x.name is 'x'
|
||||
ok x is 1
|
||||
ok typeof(y.x) is 'function'
|
||||
ok y.x instanceof Function
|
||||
ok y.x() is 3
|
||||
ok y.x.name is 'x'
|
||||
|
||||
|
||||
# The empty function should not cause a syntax error.
|
||||
|
@ -18,10 +18,10 @@ obj: {
|
|||
name: "Fred"
|
||||
|
||||
bound: ->
|
||||
(=> puts(this.name is "Fred"))()
|
||||
(=> ok(this.name is "Fred"))()
|
||||
|
||||
unbound: ->
|
||||
(-> puts(!this.name?))()
|
||||
(-> ok(!this.name?))()
|
||||
}
|
||||
|
||||
obj.unbound()
|
||||
|
@ -45,18 +45,18 @@ Math: {
|
|||
FastAdd: memoize (a, b) -> a + b
|
||||
}
|
||||
|
||||
puts Math.Add(5, 5) is 10
|
||||
puts Math.AnonymousAdd(10, 10) is 20
|
||||
puts Math.FastAdd(20, 20) is 40
|
||||
ok Math.Add(5, 5) is 10
|
||||
ok Math.AnonymousAdd(10, 10) is 20
|
||||
ok Math.FastAdd(20, 20) is 40
|
||||
|
||||
|
||||
# Parens are optional on simple function calls.
|
||||
puts 100 > 1 if 1 > 0
|
||||
puts true unless false
|
||||
puts true for i in [1..3]
|
||||
ok 100 > 1 if 1 > 0
|
||||
ok true unless false
|
||||
ok true for i in [1..3]
|
||||
|
||||
puts_func: (f) -> puts(f())
|
||||
puts_func -> true
|
||||
ok_func: (f) -> ok(f())
|
||||
ok_func -> true
|
||||
|
||||
# Optional parens can be used in a nested fashion.
|
||||
call: (func) -> func()
|
||||
|
@ -65,7 +65,7 @@ result: call ->
|
|||
inner: call ->
|
||||
Math.Add(5, 5)
|
||||
|
||||
puts result is 10
|
||||
ok result is 10
|
||||
|
||||
|
||||
# And even with strange things like this:
|
||||
|
@ -73,8 +73,8 @@ puts result is 10
|
|||
funcs: [(x) -> x, (x) -> x * x]
|
||||
result: funcs[1] 5
|
||||
|
||||
puts result is 25
|
||||
ok result is 25
|
||||
|
||||
result: ("hello".slice) 3
|
||||
|
||||
puts result is 'lo'
|
||||
ok result is 'lo'
|
|
@ -18,7 +18,7 @@ switch 'string'
|
|||
code()
|
||||
# comment
|
||||
|
||||
puts func()
|
||||
ok func()
|
||||
|
||||
func
|
||||
func
|
||||
|
|
|
@ -3,7 +3,7 @@ a: """
|
|||
on two lines
|
||||
"""
|
||||
|
||||
puts a is "basic heredoc\non two lines"
|
||||
ok a is "basic heredoc\non two lines"
|
||||
|
||||
|
||||
a: '''
|
||||
|
@ -12,12 +12,12 @@ a: '''
|
|||
c
|
||||
'''
|
||||
|
||||
puts a is "a\n \"b\nc"
|
||||
ok a is "a\n \"b\nc"
|
||||
|
||||
|
||||
a: '''one-liner'''
|
||||
|
||||
puts a is 'one-liner'
|
||||
ok a is 'one-liner'
|
||||
|
||||
|
||||
a: """
|
||||
|
@ -25,7 +25,7 @@ a: """
|
|||
here
|
||||
"""
|
||||
|
||||
puts a is "out\nhere"
|
||||
ok a is "out\nhere"
|
||||
|
||||
|
||||
a: '''
|
||||
|
@ -34,7 +34,7 @@ a: '''
|
|||
c
|
||||
'''
|
||||
|
||||
puts a is " a\n b\nc"
|
||||
ok a is " a\n b\nc"
|
||||
|
||||
a: '''
|
||||
a
|
||||
|
@ -43,4 +43,4 @@ a
|
|||
b c
|
||||
'''
|
||||
|
||||
puts a is "a\n\n\nb c"
|
||||
ok a is "a\n\n\nb c"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
num: 1 + 2 + (a: 3)
|
||||
|
||||
puts num is 6
|
||||
ok num is 6
|
||||
|
||||
|
||||
result: if true
|
||||
false
|
||||
other: "result"
|
||||
|
||||
puts result is "result" and other is "result"
|
||||
ok result is "result" and other is "result"
|
|
@ -1,43 +1,43 @@
|
|||
a: [(x) -> x, (x) -> x * x]
|
||||
|
||||
puts a.length is 2
|
||||
ok a.length is 2
|
||||
|
||||
|
||||
regex: /match/i
|
||||
words: "I think there is a match in here."
|
||||
|
||||
puts !!words.match(regex)
|
||||
ok !!words.match(regex)
|
||||
|
||||
|
||||
neg: (3 -4)
|
||||
|
||||
puts neg is -1
|
||||
ok neg is -1
|
||||
|
||||
|
||||
func: ->
|
||||
return if true
|
||||
|
||||
puts func() is null
|
||||
ok func() is null
|
||||
|
||||
|
||||
str: "\\"
|
||||
reg: /\\/
|
||||
|
||||
puts reg(str) and str is '\\'
|
||||
ok reg(str) and str is '\\'
|
||||
|
||||
|
||||
i: 10
|
||||
while i -= 1
|
||||
|
||||
puts i is 0
|
||||
ok i is 0
|
||||
|
||||
|
||||
money$: 'dollars'
|
||||
|
||||
puts money$ is 'dollars'
|
||||
ok money$ is 'dollars'
|
||||
|
||||
|
||||
puts {a: (num) -> num is 10 }.a 10
|
||||
ok {a: (num) -> num is 10 }.a 10
|
||||
|
||||
|
||||
bob: {
|
||||
|
@ -49,8 +49,8 @@ bob: {
|
|||
10: 'number'
|
||||
}
|
||||
|
||||
puts bob.hello() is "Hello Bob"
|
||||
puts bob[10] is 'number'
|
||||
ok bob.hello() is "Hello Bob"
|
||||
ok bob[10] is 'number'
|
||||
|
||||
|
||||
obj: {
|
||||
|
@ -58,5 +58,5 @@ obj: {
|
|||
'not': -> no
|
||||
}
|
||||
|
||||
puts obj.is()
|
||||
puts not obj.not()
|
||||
ok obj.is()
|
||||
ok not obj.not()
|
||||
|
|
|
@ -6,6 +6,6 @@ multi_liner:
|
|||
single_liner:
|
||||
[x, y] for y in [3..5] for x in [3..5]
|
||||
|
||||
puts multi_liner.length is single_liner.length
|
||||
puts 5 is multi_liner[2][2][1]
|
||||
puts 5 is single_liner[2][2][1]
|
||||
ok multi_liner.length is single_liner.length
|
||||
ok 5 is multi_liner[2][2][1]
|
||||
ok 5 is single_liner[2][2][1]
|
||||
|
|
|
@ -3,4 +3,4 @@ six:
|
|||
2 +
|
||||
3
|
||||
|
||||
puts six is 6
|
||||
ok six is 6
|
|
@ -1,12 +1,12 @@
|
|||
# CoffeeScript's operations should be chainable, like Python's.
|
||||
|
||||
puts 500 > 50 > 5 > -5
|
||||
ok 500 > 50 > 5 > -5
|
||||
|
||||
puts true is not false is true is not false
|
||||
ok true is not false is true is not false
|
||||
|
||||
puts 10 < 20 > 10
|
||||
ok 10 < 20 > 10
|
||||
|
||||
puts 50 > 10 > 5 is parseInt('5', 10)
|
||||
ok 50 > 10 > 5 is parseInt('5', 10)
|
||||
|
||||
|
||||
# Make sure that each argument is only evaluated once, even if used
|
||||
|
@ -15,4 +15,4 @@ puts 50 > 10 > 5 is parseInt('5', 10)
|
|||
i: 0
|
||||
func: -> i++
|
||||
|
||||
puts 1 > func() < 1
|
||||
ok 1 > func() < 1
|
||||
|
|
|
@ -5,16 +5,16 @@ negs: negs[0..2]
|
|||
|
||||
result: nums.concat(negs).join(', ')
|
||||
|
||||
puts result is '3, 6, 9, -20, -19, -18'
|
||||
ok result is '3, 6, 9, -20, -19, -18'
|
||||
|
||||
# Ensure that ranges are safe. This used to infinite loop:
|
||||
j = 5
|
||||
result: for j in [j..(j+3)]
|
||||
j
|
||||
|
||||
puts result.join(' ') is '5 6 7 8'
|
||||
ok result.join(' ') is '5 6 7 8'
|
||||
|
||||
# With range comprehensions, you can loop in steps.
|
||||
results: x for x in [0..25] by 5
|
||||
|
||||
puts results.join(' ') is '0 5 10 15 20 25'
|
||||
ok results.join(' ') is '0 5 10 15 20 25'
|
|
@ -5,12 +5,12 @@ b: array[2...4]
|
|||
|
||||
result: a.concat(b).join(' ')
|
||||
|
||||
puts result is "7 8 9 2 3"
|
||||
ok result is "7 8 9 2 3"
|
||||
|
||||
|
||||
countdown: [10..1].join(' ')
|
||||
puts countdown is "10 9 8 7 6 5 4 3 2 1"
|
||||
ok countdown is "10 9 8 7 6 5 4 3 2 1"
|
||||
|
||||
|
||||
array: [(1+5)..1+9]
|
||||
puts array.join(' ') is "6 7 8 9 10"
|
||||
ok array.join(' ') is "6 7 8 9 10"
|
|
@ -3,7 +3,7 @@ func: (first, second, rest...) ->
|
|||
|
||||
result: func 1, 2, 3, 4, 5
|
||||
|
||||
puts result is "3 4 5"
|
||||
ok result is "3 4 5"
|
||||
|
||||
|
||||
gold: silver: bronze: the_field: null
|
||||
|
@ -29,7 +29,7 @@ contenders: [
|
|||
|
||||
medalists "Mighty Mouse", contenders...
|
||||
|
||||
puts gold is "Mighty Mouse"
|
||||
puts silver is "Michael Phelps"
|
||||
puts bronze is "Liu Xiang"
|
||||
puts the_field.length is 8
|
||||
ok gold is "Mighty Mouse"
|
||||
ok silver is "Michael Phelps"
|
||||
ok bronze is "Liu Xiang"
|
||||
ok the_field.length is 8
|
|
@ -2,4 +2,4 @@ array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|||
|
||||
array[5..10]: [0, 0, 0]
|
||||
|
||||
puts array.join(' ') is '0 1 2 3 4 0 0 0'
|
||||
ok array.join(' ') is '0 1 2 3 4 0 0 0'
|
|
@ -14,7 +14,7 @@ result: switch num
|
|||
when 11 then false
|
||||
else false
|
||||
|
||||
puts result
|
||||
ok result
|
||||
|
||||
|
||||
func: (num) ->
|
||||
|
@ -25,7 +25,7 @@ func: (num) ->
|
|||
false
|
||||
else false
|
||||
|
||||
puts func(2)
|
||||
puts func(6)
|
||||
puts !func(3)
|
||||
puts !func(8)
|
||||
ok func(2)
|
||||
ok func(6)
|
||||
ok !func(3)
|
||||
ok !func(8)
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
i: 100
|
||||
while i -= 1
|
||||
|
||||
puts i is 0
|
||||
ok i is 0
|
||||
|
||||
|
||||
i: 5
|
||||
list: while i -= 1
|
||||
i * 2
|
||||
|
||||
puts list.join(' ') is "8 6 4 2"
|
||||
ok list.join(' ') is "8 6 4 2"
|
||||
|
||||
|
||||
i: 5
|
||||
list: (i * 3 while i -= 1)
|
||||
|
||||
puts list.join(' ') is "12 9 6 3"
|
||||
ok list.join(' ') is "12 9 6 3"
|
||||
|
||||
|
||||
i: 5
|
||||
func: (num) -> i -= num
|
||||
assert: -> puts i < 5 > 0
|
||||
assert: -> ok i < 5 > 0
|
||||
|
||||
results: while func 1
|
||||
assert()
|
||||
i
|
||||
|
||||
puts results.join(' ') is '4 3 2 1'
|
||||
ok results.join(' ') is '4 3 2 1'
|
Loading…
Reference in New Issue