mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
updated tests toward fixing #653
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,5 +3,6 @@ presentation
|
|||||||
test.coffee
|
test.coffee
|
||||||
parser.output
|
parser.output
|
||||||
test/fixtures/underscore
|
test/fixtures/underscore
|
||||||
|
test/*.js
|
||||||
examples/beautiful_code/parse.coffee
|
examples/beautiful_code/parse.coffee
|
||||||
*.gem
|
*.gem
|
||||||
@@ -9,13 +9,8 @@ ok 10 < 20 > 10
|
|||||||
|
|
||||||
ok 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
|
|
||||||
# more than once.
|
|
||||||
i = 0
|
i = 0
|
||||||
func = -> i++
|
ok 1 > i++ < 1, 'chained operations should evaluate each value only once'
|
||||||
|
|
||||||
ok 1 > func() < 1
|
|
||||||
|
|
||||||
|
|
||||||
# `==` and `is` should be interchangeable.
|
# `==` and `is` should be interchangeable.
|
||||||
@@ -26,29 +21,17 @@ ok a == b
|
|||||||
ok a is b
|
ok a is b
|
||||||
|
|
||||||
|
|
||||||
# Ensure that chained operations don't cause functions to be evaluated more
|
|
||||||
# than once.
|
|
||||||
val = 0
|
|
||||||
func = -> val = + 1
|
|
||||||
|
|
||||||
ok 2 > (func null) < 2
|
|
||||||
ok val is 1
|
|
||||||
|
|
||||||
|
|
||||||
# Allow "if x not in y"
|
# Allow "if x not in y"
|
||||||
obj = {a: true}
|
obj = {a: true}
|
||||||
ok 'a' of obj
|
ok 'a' of obj
|
||||||
ok 'b' not of obj
|
ok 'b' not of obj
|
||||||
|
|
||||||
# And for "a in b" with array presence.
|
# And for "a in b" with array presence.
|
||||||
ok 100 in [100, 200, 300]
|
ok 200 in [100, 200, 300]
|
||||||
array = [100, 200, 300]
|
array = [100, 200, 300]
|
||||||
ok 100 in array
|
ok 200 in array
|
||||||
ok 1 not in array
|
ok 1 not in array
|
||||||
|
ok array[0]++ in [99, 100], 'should cache testee'
|
||||||
list = [1, 2, 7]
|
|
||||||
result = if list[2] in [7, 10] then 100 else -1
|
|
||||||
ok result is 100
|
|
||||||
|
|
||||||
# And with array presence on an instance variable.
|
# And with array presence on an instance variable.
|
||||||
obj = {
|
obj = {
|
||||||
@@ -67,48 +50,48 @@ ok x*+y is -50
|
|||||||
|
|
||||||
|
|
||||||
# Compound operators.
|
# Compound operators.
|
||||||
one = two = null
|
one = 1
|
||||||
one or= 1
|
two = 0
|
||||||
two or= 2
|
one or= 2
|
||||||
|
two or= 2
|
||||||
|
|
||||||
ok one is 1
|
eq one, 1
|
||||||
ok two is 2
|
eq two, 2
|
||||||
|
|
||||||
one and= 'one'
|
zero = 0
|
||||||
two and= 'two'
|
|
||||||
|
|
||||||
ok one is 'one'
|
zero and= 'one'
|
||||||
ok two is 'two'
|
one and= 'one'
|
||||||
|
|
||||||
|
eq zero, 0
|
||||||
|
eq one , 'one'
|
||||||
|
|
||||||
|
|
||||||
# Compound assignment should be careful about caching variables.
|
# Compound assignment should be careful about caching variables.
|
||||||
list = [0, null, 5, 10]
|
|
||||||
count = 1
|
|
||||||
key = ->
|
|
||||||
count += 1
|
|
||||||
|
|
||||||
list[key()] or= 100
|
|
||||||
ok list.join(' ') is '0 5 10'
|
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
list = []
|
||||||
|
|
||||||
list[key()] ?= 100
|
list[++count] or= 1
|
||||||
ok list.join(' ') is '0 100 5 10'
|
eq list[1], 1
|
||||||
|
eq count, 1
|
||||||
|
|
||||||
count = 0
|
list[++count] ?= 2
|
||||||
key = ->
|
eq list[2], 2
|
||||||
count += 1
|
eq count, 2
|
||||||
key
|
|
||||||
|
|
||||||
key().val or= 100
|
list[count++] and= 'two'
|
||||||
|
eq list[2], 'two'
|
||||||
|
eq count, 3
|
||||||
|
|
||||||
ok key.val is 100
|
base = -> ++count; base
|
||||||
ok count is 1
|
|
||||||
|
|
||||||
key().val ?= 200
|
base().four or= 4
|
||||||
|
eq base.four, 4
|
||||||
|
eq count, 4
|
||||||
|
|
||||||
ok key.val is 100
|
base().five ?= 5
|
||||||
ok count is 2
|
eq base.five, 5
|
||||||
|
eq count, 5
|
||||||
|
|
||||||
|
|
||||||
# Ensure that RHS is treated as a group.
|
# Ensure that RHS is treated as a group.
|
||||||
|
|||||||
@@ -56,10 +56,12 @@ obj = {
|
|||||||
getNames: ->
|
getNames: ->
|
||||||
args = ['jane', 'ted']
|
args = ['jane', 'ted']
|
||||||
@accessor(args...)
|
@accessor(args...)
|
||||||
|
index: 0
|
||||||
|
0: {method: -> this is obj[0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
ok obj.getNames() is 'moe jane ted'
|
ok obj.getNames() is 'moe jane ted'
|
||||||
|
ok obj[obj.index++].method([]...), 'should cache base value'
|
||||||
|
|
||||||
crowd = [
|
crowd = [
|
||||||
contenders...
|
contenders...
|
||||||
|
|||||||
Reference in New Issue
Block a user