forked from calmjs/calmjs.parse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct position reporting and test that it works.
- Changes via rspivak/slimit@8f9a39c776 (which got pulled in via import of rspivak/slimit#65 did not have tests, so it naturally never worked.
- Loading branch information
1 parent
4be7c03
commit b08fabc
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
__author__ = 'Ruslan Spivak <[email protected]>' | ||
|
||
import unittest | ||
import textwrap | ||
|
||
from calmjs.parse.lexers.es5 import Lexer | ||
from calmjs.parse.exceptions import ECMASyntaxError | ||
|
@@ -407,3 +408,64 @@ def run_lex(value): | |
'())))', | ||
)], ECMASyntaxError, | ||
) | ||
|
||
|
||
def run_lex_pos(value): | ||
lexer = Lexer() | ||
lexer.input(textwrap.dedent(value).strip()) | ||
return [ | ||
'%s %d:%d' % (token.value, token.lineno, token.lexpos) | ||
for token in lexer | ||
] | ||
|
||
|
||
LexerPosTestCase = build_equality_testcase( | ||
'LexerPosTestCase', run_lex_pos, [( | ||
'single_line', | ||
""" | ||
var foo = bar; // line 1 | ||
""", [ | ||
'var 1:0', 'foo 1:4', '= 1:8', 'bar 1:10', '; 1:13' | ||
] | ||
), ( | ||
'multi_line', | ||
""" | ||
var foo = bar; // line 1 | ||
var bar = baz; // line 4 | ||
""", [ | ||
'var 1:0', 'foo 1:4', '= 1:8', 'bar 1:10', '; 1:13', | ||
'var 4:28', 'bar 4:32', '= 4:36', 'baz 4:38', '; 4:41', | ||
] | ||
), ( | ||
'inline_comment', | ||
""" | ||
// this is a comment // line 1 | ||
var foo = bar; // line 2 | ||
// another one // line 4 | ||
var bar = baz; // line 5 | ||
""", [ | ||
'var 2:32', 'foo 2:36', '= 2:40', 'bar 2:42', '; 2:45', | ||
'var 5:85', 'bar 5:89', '= 5:93', 'baz 5:95', '; 5:98', | ||
] | ||
), ( | ||
'block_comment', | ||
""" | ||
/* | ||
This is a block comment | ||
*/ | ||
var foo = bar; // line 4 | ||
/* block single line */ // line 6 | ||
var bar = baz; // line 7 | ||
/* oops */bar(); // line 9 | ||
""", [ | ||
'var 4:30', 'foo 4:34', '= 4:38', 'bar 4:40', '; 4:43', | ||
'var 7:91', 'bar 7:95', '= 7:99', 'baz 7:101', '; 7:104', | ||
'bar 9:128', '( 9:131', ') 9:132', '; 9:133', | ||
] | ||
)] | ||
) |