# -*- coding: utf-8 -*- """ HTML Lexer Tests ~~~~~~~~~~~~~~~~ :copyright: Copyright 2020-2020 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 @pytest.fixture(scope='module') def lexer_html(): yield HtmlLexer() def test_simple_html(lexer_html): """ extremely basic happy-path case more tests are in test_examplefiles """ fragment = "\n\t\n\t\thello world\n\t\n" tokens = list(lexer_html.get_tokens(fragment)) assert all(x[1] != Token.Error for x in tokens) 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 < 5, '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 < 5, '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 = "