mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Add some error formatting tests
Thanks to them i discovered that the parser errors where indicating the wrong token ¬¬
This commit is contained in:
parent
f2efada0d4
commit
44e3a76881
2 changed files with 46 additions and 0 deletions
|
@ -141,5 +141,9 @@ parser.yy.parseError = (message, {loc, token}) ->
|
|||
# Disregard Jison's message, it contains redundant line numer information.
|
||||
message = "unexpected #{token}"
|
||||
|
||||
# FIXME The `loc` received does not correspond to the `token` token, but to
|
||||
# the one before it instead. That's why the test in error_messages.coffee is
|
||||
# failing. There should be a way to get the location data... maybe accessing
|
||||
# the lexer's tokens?
|
||||
{first_line, first_column, last_line, last_column} = loc
|
||||
throw new CompilerError message, first_line, first_column, last_line, last_column
|
42
test/error_messages.coffee
Normal file
42
test/error_messages.coffee
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Error Formating
|
||||
# ---------------
|
||||
|
||||
# Ensure that errors of different kinds (lexer, parser and compiler) are shown
|
||||
# in a consistent way.
|
||||
|
||||
assertErrorFormat = (code, expectedErrorFormat) ->
|
||||
throws (-> CoffeeScript.compile code), (err) ->
|
||||
eq expectedErrorFormat, (err.prettyMessage 'test.coffee', code)
|
||||
yes
|
||||
|
||||
test "lexer errors formating", ->
|
||||
assertErrorFormat '''
|
||||
normalObject = {}
|
||||
insideOutObject = }{
|
||||
''',
|
||||
'''
|
||||
test.coffee:2:19: error: unmatched }
|
||||
insideOutObject = }{
|
||||
^
|
||||
'''
|
||||
|
||||
# FIXME Test not passing. See "parser.yy.parseError" in coffee-script.coffee
|
||||
test "parser error formating", ->
|
||||
assertErrorFormat '''
|
||||
foo in bar or in baz
|
||||
''',
|
||||
'''
|
||||
test.coffee:1:12: error: unexpected RELATION
|
||||
foo in bar or in baz
|
||||
^^
|
||||
'''
|
||||
|
||||
test "compiler error formatting", ->
|
||||
assertErrorFormat '''
|
||||
evil = (foo, eval, bar) ->
|
||||
''',
|
||||
'''
|
||||
test.coffee:1:14: error: parameter name "eval" is not allowed
|
||||
evil = (foo, eval, bar) ->
|
||||
^^^^
|
||||
'''
|
Loading…
Add table
Reference in a new issue