test_operations: removed the top-level closures that symbolized
sections
This commit is contained in:
parent
47426c28e1
commit
af759dcf42
|
@ -1,4 +1,4 @@
|
|||
#### Operators
|
||||
## Operators
|
||||
|
||||
# binary (2-ary) math operators do not require spaces
|
||||
(->
|
||||
|
@ -52,10 +52,9 @@ eq (+ +1), (- -1)
|
|||
|
||||
|
||||
#### compound assignment operators
|
||||
(->
|
||||
|
||||
# boolean operators
|
||||
(->
|
||||
# boolean operators
|
||||
(->
|
||||
a = 0
|
||||
a or= 2
|
||||
eq a, 2
|
||||
|
@ -76,19 +75,19 @@ eq (+ +1), (- -1)
|
|||
e = f = false
|
||||
e and= f or true
|
||||
eq e, false
|
||||
)()
|
||||
)()
|
||||
|
||||
# compound assignment as a sub expression
|
||||
(->
|
||||
# compound assignment as a sub expression
|
||||
(->
|
||||
[a, b, c] = [1, 2, 3]
|
||||
eq (a + b += c), 6
|
||||
eq a, 1
|
||||
eq b, 5
|
||||
eq c, 3
|
||||
)()
|
||||
)()
|
||||
|
||||
# compound assignment should be careful about caching variables
|
||||
(->
|
||||
# compound assignment should be careful about caching variables
|
||||
(->
|
||||
count = 0
|
||||
list = []
|
||||
|
||||
|
@ -115,10 +114,10 @@ eq (+ +1), (- -1)
|
|||
base().five ?= 5
|
||||
eq base.five, 5
|
||||
eq count, 5
|
||||
)()
|
||||
)()
|
||||
|
||||
# compound assignment with implicit objects
|
||||
(->
|
||||
# compound assignment with implicit objects
|
||||
(->
|
||||
obj = undefined
|
||||
obj ?=
|
||||
one: 1
|
||||
|
@ -130,50 +129,44 @@ eq (+ +1), (- -1)
|
|||
|
||||
eq obj.one, undefined
|
||||
eq obj.two, 2
|
||||
)()
|
||||
|
||||
)()
|
||||
|
||||
|
||||
#### `is`,`isnt`,`==`,`!=`
|
||||
(->
|
||||
|
||||
# `==` and `is` should be interchangeable.
|
||||
(->
|
||||
# `==` and `is` should be interchangeable.
|
||||
(->
|
||||
a = b = 1
|
||||
ok a is 1 and b == 1
|
||||
ok a == b
|
||||
ok a is b
|
||||
)()
|
||||
)()
|
||||
|
||||
# `!=` and `isnt` should be interchangeable.
|
||||
(->
|
||||
# `!=` and `isnt` should be interchangeable.
|
||||
(->
|
||||
a = 0
|
||||
b = 1
|
||||
ok a isnt 1 and b != 0
|
||||
ok a != b
|
||||
ok a isnt b
|
||||
)()
|
||||
|
||||
)()
|
||||
|
||||
|
||||
#### `in`, `of`
|
||||
(->
|
||||
|
||||
# `in` should check if an array contains a value using `indexOf`
|
||||
# `of` should check if a property is defined on an object using `in`
|
||||
(->
|
||||
# - `in` should check if an array contains a value using `indexOf`
|
||||
# - `of` should check if a property is defined on an object using `in`
|
||||
(->
|
||||
arr = [1]
|
||||
ok 0 of arr
|
||||
ok 1 in arr
|
||||
# prefixing `not` to `in and `of` should negate them
|
||||
ok 1 not of arr
|
||||
ok 0 not in arr
|
||||
)()
|
||||
)()
|
||||
|
||||
# `in` should be able to operate on an array literal
|
||||
(->
|
||||
# `in` should be able to operate on an array literal
|
||||
(->
|
||||
ok 2 in [0, 1, 2, 3]
|
||||
ok 4 not in [0, 1, 2, 3]
|
||||
arr = [0, 1, 2, 3]
|
||||
|
@ -187,10 +180,10 @@ eq (+ +1), (- -1)
|
|||
val = 0
|
||||
ok val++ of arr
|
||||
ok val++ not of arr
|
||||
)()
|
||||
)()
|
||||
|
||||
# `of` and `in` should be able to operate on instance variables
|
||||
(->
|
||||
# `of` and `in` should be able to operate on instance variables
|
||||
(->
|
||||
obj = {
|
||||
list: [2,3]
|
||||
in_list: (value) -> value in @list
|
||||
|
@ -202,64 +195,59 @@ eq (+ +1), (- -1)
|
|||
ok obj.not_in_list 1
|
||||
ok obj.of_list 0
|
||||
ok obj.not_of_list 2
|
||||
)()
|
||||
)()
|
||||
|
||||
#???: `in` with cache and `__indexOf` should work in argument lists
|
||||
eq [Object() in Array()].length, 1
|
||||
#???: `in` with cache and `__indexOf` should work in argument lists
|
||||
eq [Object() in Array()].length, 1
|
||||
|
||||
#737: `in` should have higher precedence than logical operators.
|
||||
eq 1, 1 in [1] and 1
|
||||
#737: `in` should have higher precedence than logical operators.
|
||||
eq 1, 1 in [1] and 1
|
||||
|
||||
#768: `in` should preserve evaluation order.
|
||||
(->
|
||||
#768: `in` should preserve evaluation order.
|
||||
(->
|
||||
share = 0
|
||||
a = -> share++ if share is 0
|
||||
b = -> share++ if share is 1
|
||||
c = -> share++ if share is 2
|
||||
ok a() not in [b(),c()]
|
||||
eq share, 3
|
||||
)()
|
||||
|
||||
)()
|
||||
|
||||
|
||||
#### chainable operators
|
||||
|
||||
ok 100 > 10 > 1 > 0 > -1
|
||||
ok -1 < 0 < 1 < 10 < 100
|
||||
|
||||
# `is` and `isnt` may be chained
|
||||
ok true is not false is true is not false
|
||||
ok 0 is 0 isnt 1 is 1
|
||||
|
||||
# different comparison operators (`>`,`<`,`is`,etc.) may be combined
|
||||
ok 1 < 2 > 1
|
||||
ok 10 < 20 > 2+3 is 5
|
||||
|
||||
# some chainable operators can be negated by `unless`
|
||||
ok (true unless 0==10!=100)
|
||||
|
||||
# operator precedence: `|` lower than `<`
|
||||
eq 1, 1 | 2 < 3 < 4
|
||||
|
||||
# preserve references
|
||||
(->
|
||||
|
||||
ok 100 > 10 > 1 > 0 > -1
|
||||
ok -1 < 0 < 1 < 10 < 100
|
||||
|
||||
# `is` and `isnt` may be chained
|
||||
ok true is not false is true is not false
|
||||
ok 0 is 0 isnt 1 is 1
|
||||
|
||||
# different comparison operators (`>`,`<`,`is`,etc.) may be combined
|
||||
ok 1 < 2 > 1
|
||||
ok 10 < 20 > 2+3 is 5
|
||||
|
||||
# some chainable operators can be negated by `unless`
|
||||
ok (true unless 0==10!=100)
|
||||
|
||||
# operator precedence: `|` lower than `<`
|
||||
eq 1, 1 | 2 < 3 < 4
|
||||
|
||||
# preserve references
|
||||
(->
|
||||
a = b = c = 1
|
||||
# `a == b <= c` should become `a === b && b <= c`
|
||||
ok a == b <= c
|
||||
)()
|
||||
)()
|
||||
|
||||
# chained operations should evaluate each value only once
|
||||
(->
|
||||
# chained operations should evaluate each value only once
|
||||
(->
|
||||
a = 0
|
||||
ok 1 > a++ < 1
|
||||
)()
|
||||
)()
|
||||
|
||||
#891: incorrect inversion of chained comparisons
|
||||
(->
|
||||
#891: incorrect inversion of chained comparisons
|
||||
(->
|
||||
ok (true unless 0 > 1 > 2)
|
||||
ok (true unless (NaN = 0/0) < 0/0 < NaN)
|
||||
)()
|
||||
|
||||
)()
|
||||
|
|
Loading…
Reference in New Issue