Skip to content

Commit

Permalink
Adding position checking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
metatoaster committed Apr 22, 2018
1 parent 6fe44ff commit 9fd68d7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/calmjs/parse/tests/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,43 @@
)
]

es2015_pos_cases = [
(
'single_line_template',
"""
var foo = `bar`;
""", ([
'var 1:0', 'foo 1:4', '= 1:8', '`bar` 1:10', '; 1:15'
], [
'var 1:1', 'foo 1:5', '= 1:9', '`bar` 1:11', '; 1:16',
])
), (
'multi_line',
"""
var foo = `bar
${1}`;
""", ([
'var 1:0', 'foo 1:4', '= 1:8', '`bar\n${ 1:10',
'1 2:17', '}` 2:18', '; 2:20',
], [
'var 1:1', 'foo 1:5', '= 1:9', '`bar\n${ 1:11',
'1 2:3', '}` 2:4', '; 2:6',
])
), (
'multi_line_joined',
r"""
var foo = `bar\
${1}`;
""", ([
'var 1:0', 'foo 1:4', '= 1:8', '`bar\\\n${ 1:10',
'1 2:18', '}` 2:19', '; 2:21',
], [
'var 1:1', 'foo 1:5', '= 1:9', '`bar\n${ 1:11',
'1 2:3', '}` 2:4', '; 2:6',
])
)
]


def run_lexer(value, lexer_cls):
lexer = lexer_cls()
Expand Down
5 changes: 5 additions & 0 deletions src/calmjs/parse/tests/test_es2015_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
es5_cases,
es5_pos_cases,
es2015_cases,
es2015_pos_cases,
)


Expand Down Expand Up @@ -75,3 +76,7 @@ def test_initial_template_character(self):
LexerES2015TestCase = build_equality_testcase(
'LexerES2015TestCase', partial(run_lexer, lexer_cls=Lexer), (
(label, data[0], data[1],) for label, data in es2015_cases))

LexerES2015PosTestCase = build_equality_testcase(
'LexerES2015PosTestCase', partial(
run_lexer_pos, lexer_cls=Lexer), es2015_pos_cases)

0 comments on commit 9fd68d7

Please sign in to comment.