diff --git a/html5lib/tests/test_parser2.py b/html5lib/tests/test_parser2.py index 47738405..0ec5b049 100644 --- a/html5lib/tests/test_parser2.py +++ b/html5lib/tests/test_parser2.py @@ -1,11 +1,13 @@ from __future__ import absolute_import, division, unicode_literals +from six import PY2, text_type + import io from . import support # noqa from html5lib.constants import namespaces -from html5lib import parse +from html5lib import parse, HTMLParser # tests that aren't autogenerated from text files @@ -56,3 +58,33 @@ def test_duplicate_attribute(): doc = parse('

') el = doc[1][0] assert el.get("class") == "a" + + +def test_debug_log(): + parser = HTMLParser(debug=True) + parser.parse("a

bd

e") + + expected = [('dataState', 'InitialPhase', 'InitialPhase', 'processDoctype', {'type': 'Doctype'}), + ('dataState', 'BeforeHtmlPhase', 'BeforeHtmlPhase', 'processStartTag', {'name': 'title', 'type': 'StartTag'}), + ('dataState', 'BeforeHeadPhase', 'BeforeHeadPhase', 'processStartTag', {'name': 'title', 'type': 'StartTag'}), + ('dataState', 'InHeadPhase', 'InHeadPhase', 'processStartTag', {'name': 'title', 'type': 'StartTag'}), + ('rcdataState', 'TextPhase', 'TextPhase', 'processCharacters', {'type': 'Characters'}), + ('dataState', 'TextPhase', 'TextPhase', 'processEndTag', {'name': 'title', 'type': 'EndTag'}), + ('dataState', 'InHeadPhase', 'InHeadPhase', 'processStartTag', {'name': 'p', 'type': 'StartTag'}), + ('dataState', 'AfterHeadPhase', 'AfterHeadPhase', 'processStartTag', {'name': 'p', 'type': 'StartTag'}), + ('dataState', 'InBodyPhase', 'InBodyPhase', 'processStartTag', {'name': 'p', 'type': 'StartTag'}), + ('dataState', 'InBodyPhase', 'InBodyPhase', 'processCharacters', {'type': 'Characters'}), + ('dataState', 'InBodyPhase', 'InBodyPhase', 'processStartTag', {'name': 'script', 'type': 'StartTag'}), + ('dataState', 'InBodyPhase', 'InHeadPhase', 'processStartTag', {'name': 'script', 'type': 'StartTag'}), + ('scriptDataState', 'TextPhase', 'TextPhase', 'processCharacters', {'type': 'Characters'}), + ('dataState', 'TextPhase', 'TextPhase', 'processEndTag', {'name': 'script', 'type': 'EndTag'}), + ('dataState', 'InBodyPhase', 'InBodyPhase', 'processCharacters', {'type': 'Characters'}), + ('dataState', 'InBodyPhase', 'InBodyPhase', 'processEndTag', {'name': 'p', 'type': 'EndTag'}), + ('dataState', 'InBodyPhase', 'InBodyPhase', 'processCharacters', {'type': 'Characters'})] + + if PY2: + for i, log in enumerate(expected): + log = [x.encode("ascii") if isinstance(x, text_type) else x for x in log] + expected[i] = tuple(log) + + assert parser.log == expected