| 1 |
""" |
| 2 |
CoffeeScript tests |
| 3 |
~~~~~~~~~~~~~~~~~~ |
| 4 |
|
| 5 |
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS. |
| 6 |
:license: BSD, see LICENSE for details. |
| 7 |
""" |
| 8 |
|
| 9 |
import pytest |
| 10 |
|
| 11 |
from pygments.lexers import CoffeeScriptLexer |
| 12 |
from pygments.token import Token |
| 13 |
|
| 14 |
COFFEE_SLASH_GOLDEN = [ |
| 15 |
# input_str, slashes_are_regex_here |
| 16 |
(r'/\\/', True), |
| 17 |
(r'/\\/i', True), |
| 18 |
(r'/\//', True), |
| 19 |
(r'/(\s)/', True), |
| 20 |
('/a{2,8}/', True), |
| 21 |
('/b*c?d+/', True), |
| 22 |
('/(capture-match)/', True), |
| 23 |
('/(?:do-not-capture-match)/', True), |
| 24 |
('/this|or|that/', True), |
| 25 |
('/[char-set]/', True), |
| 26 |
('/[^neg-char_st]/', True), |
| 27 |
('/^.*$/', True), |
| 28 |
(r'/\n(\f)\0\1\d\b\cm\u1234/', True), |
| 29 |
(r'/^.?([^/\\\n\w]*)a\1+$/.something(or_other) # something more complex', True), |
| 30 |
("foo = (str) ->\n /'|\"/.test str", True), |
| 31 |
('a = a / b / c', False), |
| 32 |
('a = a/b/c', False), |
| 33 |
('a = a/b/ c', False), |
| 34 |
('a = a /b/c', False), |
| 35 |
('a = 1 + /d/.test(a)', True), |
| 36 |
] |
| 37 |
|
| 38 |
|
| 39 |
@pytest.fixture(scope='module') |
| 40 |
def lexer(): |
| 41 |
yield CoffeeScriptLexer() |
| 42 |
|
| 43 |
|
| 44 |
@pytest.mark.parametrize('golden', COFFEE_SLASH_GOLDEN) |
| 45 |
def test_coffee_slashes(lexer, golden): |
| 46 |
input_str, slashes_are_regex_here = golden |
| 47 |
output = list(lexer.get_tokens(input_str)) |
| 48 |
print(output) |
| 49 |
for t, s in output: |
| 50 |
if '/' in s: |
| 51 |
is_regex = t is Token.String.Regex |
| 52 |
assert is_regex == slashes_are_regex_here, (t, s) |