summaryrefslogtreecommitdiffstats
path: root/tests/test_java.py
blob: a50e862e753f7ba07443db6523ba6ab93dd6a018 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
    Basic JavaLexer Test
    ~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import time

import pytest

from pygments.token import String
from pygments.lexers import JavaLexer


@pytest.fixture(scope='module')
def lexer():
    yield JavaLexer()


@pytest.mark.parametrize(
    'text',
    (
        '""', '"abc"', '"ひらがな"', '"123"',
        '"\\\\"', '"\\t"' '"\\""',
    ),
)
def test_string_literals_positive_match(lexer, text):
    """Test positive matches for string literals."""
    tokens = list(lexer.get_tokens_unprocessed(text))
    assert all([token is String for _, token, _ in tokens])
    assert ''.join([value for _, _, value in tokens]) == text


def test_string_literals_backtracking(lexer):
    """Test catastrophic backtracking for string literals."""
    start_time = time.time()
    list(lexer.get_tokens_unprocessed('"' + '\\' * 100))
    assert time.time() - start_time < 1, 'possible backtracking bug'