Improved test readability + fixed integer divison

This commit is contained in:
Anatoly Ressin
2014-10-12 22:32:02 +03:00
parent e8a4e93a72
commit ec44aba71a

View File

@@ -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