jashkenas--coffeescript/test/compilation.coffee

57 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2010-12-31 03:48:31 +00:00
# Compilation
# -----------
# helper to assert that a string should fail compilation
cantCompile = (code) ->
throws -> CoffeeScript.compile code
test "ensure that carriage returns don't break compilation on Windows", ->
doesNotThrow -> CoffeeScript.compile 'one\r\ntwo', bare: on
2010-12-31 03:48:31 +00:00
test "--bare and globals:on", ->
eq -1, CoffeeScript.compile('x = y', bare: on, globals: on).indexOf 'var'
ok 'passed' is CoffeeScript.eval '"passed"', bare: on, filename: 'test'
2010-12-31 03:48:31 +00:00
test "multiple generated references", ->
2010-12-31 03:48:31 +00:00
a = {b: []}
a.b[true] = -> this == a.b
c = 0
d = []
ok a.b[0<++c<2] d...
test "splat on a line by itself is invalid", ->
cantCompile "x 'a'\n...\n"
test "Issue 750", ->
2010-12-31 03:48:31 +00:00
cantCompile 'f(->'
2010-12-31 03:48:31 +00:00
cantCompile 'a = (break)'
2010-12-31 03:48:31 +00:00
cantCompile 'a = (return 5 for item in list)'
2010-12-31 03:48:31 +00:00
cantCompile 'a = (return 5 while condition)'
2010-12-31 03:48:31 +00:00
cantCompile 'a = for x in y\n return 5'
2010-12-31 03:48:31 +00:00
test "Issue #986: Unicode identifiers", ->
λ = 5
eq λ, 5
2010-12-31 03:48:31 +00:00
test "don't accidentally stringify keywords", ->
ok (-> this == 'this')() is false
2011-01-11 04:19:31 +00:00
test "#1026", ->
cantCompile '''
if a
b
else
c
else
d
'''
2011-01-19 04:10:09 +00:00
test "#1050", ->
2011-03-12 03:44:18 +00:00
cantCompile "### */ ###"