mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Improved test readability + fixed integer divison
This commit is contained in:
@@ -82,22 +82,24 @@ test "yield in if statements", ->
|
||||
|
||||
test "symbolic operators has precedence over the `yield`", ->
|
||||
|
||||
symbolic = '+ - * / << >> & | || && ** ^ \\ or and'.split ' '
|
||||
symbolic = '+ - * / << >> & | || && ** ^ // or and'.split ' '
|
||||
compound = ("#{op}=" for op in symbolic)
|
||||
relations = '< > == != <= >= is isnt'.split ' '
|
||||
|
||||
operators = []
|
||||
operators.push symbolic...
|
||||
operators.push compound...
|
||||
operators.push relations...
|
||||
operators = [symbolic..., '=', compound..., relations...]
|
||||
|
||||
allOf = (gen) -> ref.value until (ref = gen.next()).done
|
||||
collect = (gen) -> ref.value until (ref = gen.next()).done
|
||||
|
||||
values = [0, 1, 2, 3]
|
||||
|
||||
for op in operators
|
||||
generator = CoffeeScript.eval "(arr) -> yield i #{op} 2 for i in arr"
|
||||
transform = CoffeeScript.eval "(i) -> i #{op} 2"
|
||||
expected = values.map transform
|
||||
actual = allOf generator values
|
||||
|
||||
expression = "i #{op} 2"
|
||||
|
||||
yielded = CoffeeScript.eval "(arr) -> yield #{expression} for i in arr"
|
||||
mapped = CoffeeScript.eval "(arr) -> (#{expression} for i in arr)"
|
||||
|
||||
expected = mapped values
|
||||
actual = collect yielded values
|
||||
|
||||
arrayEq actual, expected
|
||||
|
||||
Reference in New Issue
Block a user