2010-12-29 14:06:57 -05:00
|
|
|
# Formatting
|
|
|
|
# ----------
|
|
|
|
|
2011-01-01 23:35:05 -05:00
|
|
|
# TODO: maybe this file should be split up into their respective sections:
|
|
|
|
# operators -> operators
|
|
|
|
# array literals -> array literals
|
|
|
|
# string literals -> string literals
|
|
|
|
# function invocations -> function invocations
|
|
|
|
|
|
|
|
# * Line Continuation
|
|
|
|
# * Property Accesss
|
|
|
|
# * Operators
|
|
|
|
# * Array Literals
|
|
|
|
# * Function Invocations
|
|
|
|
# * String Literals
|
|
|
|
|
|
|
|
doesNotThrow -> CoffeeScript.compile "a = then b"
|
|
|
|
|
|
|
|
test "multiple semicolon-separated statements in parentheticals", ->
|
|
|
|
nonce = {}
|
|
|
|
eq nonce, (1; 2; nonce)
|
|
|
|
eq nonce, (-> return (1; 2; nonce))()
|
|
|
|
|
2011-03-11 21:41:12 -05:00
|
|
|
# Line Continuation
|
2011-01-01 23:35:05 -05:00
|
|
|
|
|
|
|
# Property Access
|
|
|
|
|
|
|
|
test "chained accesses split on period/newline, backwards and forwards", ->
|
|
|
|
str = 'abc'
|
|
|
|
result = str.
|
|
|
|
split('').
|
|
|
|
reverse().
|
|
|
|
reverse().
|
|
|
|
reverse()
|
|
|
|
arrayEq ['c','b','a'], result
|
|
|
|
arrayEq ['c','b','a'], str.
|
|
|
|
split('').
|
|
|
|
reverse().
|
|
|
|
reverse().
|
|
|
|
reverse()
|
|
|
|
result = str
|
|
|
|
.split('')
|
|
|
|
.reverse()
|
|
|
|
.reverse()
|
|
|
|
.reverse()
|
|
|
|
arrayEq ['c','b','a'], result
|
|
|
|
arrayEq ['c','b','a'], str
|
|
|
|
.split('')
|
|
|
|
.reverse()
|
|
|
|
.reverse()
|
|
|
|
.reverse()
|
|
|
|
arrayEq ['c','b','a'], str.
|
|
|
|
split('')
|
|
|
|
.reverse().
|
|
|
|
reverse()
|
|
|
|
.reverse()
|
|
|
|
|
|
|
|
# Operators
|
|
|
|
|
|
|
|
test "newline suppression for operators", ->
|
|
|
|
six =
|
|
|
|
1 +
|
|
|
|
2 +
|
|
|
|
3
|
|
|
|
eq 6, six
|
|
|
|
|
|
|
|
test "`?.` and `::` should continue lines", ->
|
|
|
|
ok not Date
|
|
|
|
::
|
|
|
|
?.foo
|
|
|
|
#eq Object::toString, Date?.
|
|
|
|
#prototype
|
|
|
|
#::
|
|
|
|
#?.foo
|
|
|
|
|
2011-01-22 01:29:07 -05:00
|
|
|
doesNotThrow -> CoffeeScript.compile """
|
|
|
|
oh. yes
|
2011-01-22 01:34:30 -05:00
|
|
|
oh?. true
|
|
|
|
oh:: return
|
2011-01-22 01:29:07 -05:00
|
|
|
"""
|
|
|
|
|
2011-01-22 01:56:14 -05:00
|
|
|
doesNotThrow -> CoffeeScript.compile """
|
|
|
|
a?[b..]
|
|
|
|
a?[...b]
|
|
|
|
a?[b..c]
|
|
|
|
"""
|
|
|
|
|
2011-01-01 23:35:05 -05:00
|
|
|
# Array Literals
|
|
|
|
|
|
|
|
test "indented array literals don't trigger whitespace rewriting", ->
|
|
|
|
getArgs = -> arguments
|
|
|
|
result = getArgs(
|
|
|
|
[[[[[],
|
|
|
|
[]],
|
|
|
|
[[]]]],
|
|
|
|
[]])
|
|
|
|
eq 1, result.length
|
|
|
|
|
|
|
|
# Function Invocations
|
|
|
|
|
|
|
|
doesNotThrow -> CoffeeScript.compile """
|
|
|
|
obj = then fn 1,
|
|
|
|
1: 1
|
|
|
|
a:
|
|
|
|
b: ->
|
|
|
|
fn c,
|
|
|
|
d: e
|
|
|
|
f: 1
|
|
|
|
"""
|
|
|
|
|
|
|
|
# String Literals
|
|
|
|
|
|
|
|
test "indented heredoc", ->
|
|
|
|
result = ((_) -> _)(
|
|
|
|
"""
|
|
|
|
abc
|
|
|
|
""")
|
|
|
|
eq "abc", result
|
2011-07-16 10:34:46 -04:00
|
|
|
|
|
|
|
# Nested blocks caused by paren unwrapping
|
|
|
|
test "#1492: Nested blocks don't cause double semicolons", ->
|
2011-07-17 16:43:50 -04:00
|
|
|
js = CoffeeScript.compile '(0;0)'
|
2011-07-16 10:34:46 -04:00
|
|
|
eq -1, js.indexOf ';;'
|
2011-09-04 12:18:38 -04:00
|
|
|
|
|
|
|
test "#1195 Ignore trailing semicolons (before newlines or as the last char in a program)", ->
|
|
|
|
preNewline = (numSemicolons) ->
|
|
|
|
"""
|
|
|
|
nonce = {}; nonce2 = {}
|
|
|
|
f = -> nonce#{Array(numSemicolons+1).join(';')}
|
|
|
|
nonce2
|
|
|
|
unless f() is nonce then throw new Error('; before linebreak should = newline')
|
|
|
|
"""
|
|
|
|
CoffeeScript.run(preNewline(n), bare: true) for n in [1,2,3]
|
2011-12-24 07:04:34 -05:00
|
|
|
|
2011-09-04 12:18:38 -04:00
|
|
|
lastChar = '-> lastChar;'
|
|
|
|
doesNotThrow -> CoffeeScript.compile lastChar, bare: true
|
2011-09-16 19:26:04 -04:00
|
|
|
|
|
|
|
test "#1299: Disallow token misnesting", ->
|
|
|
|
try
|
|
|
|
CoffeeScript.compile '''
|
|
|
|
[{
|
|
|
|
]}
|
|
|
|
'''
|
|
|
|
ok no
|
|
|
|
catch e
|
|
|
|
eq 'unmatched ] on line 2', e.message
|