""" HTML Lexer Tests ~~~~~~~~~~~~~~~~ :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import time import pytest from pygments.lexers.html import HtmlLexer from pygments.token import Token MAX_HL_TIME = 10 @pytest.fixture(scope='module') def lexer_html(): yield HtmlLexer() def test_happy_javascript_fragment(lexer_html): """valid, even long Javascript fragments should still get parsed ok""" fragment = "" start_time = time.time() tokens = list(lexer_html.get_tokens(fragment)) assert all(x[1] != Token.Error for x in tokens) assert time.time() - start_time < MAX_HL_TIME, \ 'The HTML lexer might have an expensive happy-path script case' def test_happy_css_fragment(lexer_html): """valid, even long CSS fragments should still get parsed ok""" fragment = "" start_time = time.time() tokens = list(lexer_html.get_tokens(fragment)) assert all(x[1] != Token.Error for x in tokens) assert time.time() - start_time < MAX_HL_TIME, \ 'The HTML lexer might have an expensive happy-path style case' def test_long_unclosed_javascript_fragment(lexer_html): """unclosed, long Javascript fragments should parse quickly""" reps = 2000 fragment = "