2012-12-24 13:34:16 +00:00
|
|
|
testScript = '''
|
|
|
|
if true
|
|
|
|
x = 6
|
|
|
|
console.log "A console #{x + 7} log"
|
|
|
|
|
|
|
|
foo = "bar"
|
|
|
|
z = /// ^ (a#{foo}) ///
|
|
|
|
|
|
|
|
x = () ->
|
|
|
|
try
|
|
|
|
console.log "foo"
|
|
|
|
catch err
|
|
|
|
# Rewriter will generate explicit indentation here.
|
|
|
|
|
|
|
|
return null
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "Verify location of generated tokens", ->
|
2013-01-14 22:11:07 +00:00
|
|
|
tokens = CoffeeScript.tokens "a = 79"
|
2012-12-24 13:34:16 +00:00
|
|
|
|
|
|
|
eq tokens.length, 4
|
2013-01-14 22:11:07 +00:00
|
|
|
|
|
|
|
aToken = tokens[0]
|
|
|
|
eq aToken[2].first_line, 0
|
|
|
|
eq aToken[2].first_column, 0
|
|
|
|
eq aToken[2].last_line, 0
|
|
|
|
eq aToken[2].last_column, 0
|
|
|
|
|
|
|
|
equalsToken = tokens[1]
|
|
|
|
eq equalsToken[2].first_line, 0
|
|
|
|
eq equalsToken[2].first_column, 2
|
|
|
|
eq equalsToken[2].last_line, 0
|
|
|
|
eq equalsToken[2].last_column, 2
|
|
|
|
|
|
|
|
numberToken = tokens[2]
|
|
|
|
eq numberToken[2].first_line, 0
|
|
|
|
eq numberToken[2].first_column, 4
|
|
|
|
eq numberToken[2].last_line, 0
|
|
|
|
eq numberToken[2].last_column, 5
|
|
|
|
|
2013-03-01 18:38:55 +00:00
|
|
|
test "Verify location of generated tokens (with indented first line)", ->
|
|
|
|
tokens = CoffeeScript.tokens " a = 83"
|
|
|
|
|
2013-06-13 22:21:47 +00:00
|
|
|
eq tokens.length, 4
|
|
|
|
[aToken, equalsToken, numberToken] = tokens
|
2013-03-01 18:38:55 +00:00
|
|
|
|
|
|
|
eq aToken[2].first_line, 0
|
|
|
|
eq aToken[2].first_column, 2
|
|
|
|
eq aToken[2].last_line, 0
|
|
|
|
eq aToken[2].last_column, 2
|
|
|
|
|
|
|
|
eq equalsToken[2].first_line, 0
|
|
|
|
eq equalsToken[2].first_column, 4
|
|
|
|
eq equalsToken[2].last_line, 0
|
|
|
|
eq equalsToken[2].last_column, 4
|
|
|
|
|
|
|
|
eq numberToken[2].first_line, 0
|
|
|
|
eq numberToken[2].first_column, 6
|
|
|
|
eq numberToken[2].last_line, 0
|
|
|
|
eq numberToken[2].last_column, 7
|
2012-12-24 13:34:16 +00:00
|
|
|
|
2014-06-12 20:03:10 +00:00
|
|
|
test "Verify locations in string interpolation", ->
|
|
|
|
tokens = CoffeeScript.tokens '"a#{b}c"'
|
|
|
|
|
|
|
|
eq tokens.length, 8
|
|
|
|
[openParen, a, firstPlus, b, secondPlus, c, closeParen] = tokens
|
|
|
|
|
|
|
|
eq a[2].first_line, 0
|
|
|
|
eq a[2].first_column, 1
|
|
|
|
eq a[2].last_line, 0
|
|
|
|
eq a[2].last_column, 1
|
|
|
|
|
|
|
|
eq b[2].first_line, 0
|
|
|
|
eq b[2].first_column, 4
|
|
|
|
eq b[2].last_line, 0
|
|
|
|
eq b[2].last_column, 4
|
|
|
|
|
|
|
|
eq c[2].first_line, 0
|
|
|
|
eq c[2].first_column, 6
|
|
|
|
eq c[2].last_line, 0
|
|
|
|
eq c[2].last_column, 6
|
|
|
|
|
2012-12-24 13:34:16 +00:00
|
|
|
test "Verify all tokens get a location", ->
|
|
|
|
doesNotThrow ->
|
|
|
|
tokens = CoffeeScript.tokens testScript
|
|
|
|
for token in tokens
|
2013-01-14 20:20:47 +00:00
|
|
|
ok !!token[2]
|