123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- from ..htmlparser import parse_html_string, print_html_string
- def test_parser_handles_simple_html():
- root_node = parse_html_string("<p>Hello World!</p>")
- assert print_html_string(root_node) == "<p>Hello World!</p>"
- def test_parser_handles_html_with_brs():
- root_node = parse_html_string("<p>Hello<br />World!</p>")
- assert print_html_string(root_node) == "<p>Hello<br />World!</p>"
- def test_parser_handles_html_with_hrs():
- root_node = parse_html_string("<p>Hello</p><hr /><p>World!</p>")
- assert print_html_string(root_node) == "<p>Hello</p><hr /><p>World!</p>"
- def test_parser_escapes_html_in_text_nodes():
- root_node = parse_html_string("<span>Hello <br> World!</span>")
- assert print_html_string(root_node) == "<span>Hello <br> World!</span>"
- def test_parser_escapes_quotes_in_text_nodes():
- root_node = parse_html_string('<span>Hello "World"!</span>')
- assert print_html_string(root_node) == "<span>Hello "World"!</span>"
- def test_parser_handles_attributes():
- root_node = parse_html_string('<a href="/hello-world/">Hello World!</a>')
- assert print_html_string(root_node) == '<a href="/hello-world/">Hello World!</a>'
- def test_parser_escapes_html_in_attributes_names():
- root_node = parse_html_string('<span data-a<tt>r="<br>">Hello!</span>')
- assert print_html_string(root_node) == (
- "<span data-a<tt>r="<br />">Hello!</span>"
- )
- def test_parser_escapes_quotes_in_attributes_names():
- root_node = parse_html_string('<span "data-attr"="br">Hello!</span>')
- assert print_html_string(root_node) == (
- '<span "data-attr"="br">Hello!</span>'
- )
- def test_parser_escapes_html_in_attributes_values():
- root_node = parse_html_string('<span data-attr="<br>">Hello!</span>')
- assert print_html_string(root_node) == (
- '<span data-attr="<br>">Hello!</span>'
- )
- def test_parser_handles_escaped_attribute_values():
- root_node = parse_html_string('<span data-attr="<br>">Hello!</span>')
- assert print_html_string(root_node) == (
- '<span data-attr="<br>">Hello!</span>'
- )
- def test_parser_escapes_quotes_in_attributes_values():
- root_node = parse_html_string('<span data-attr="\'">Hello!</span>')
- assert print_html_string(root_node) == ('<span data-attr="'">Hello!</span>')
- def test_parser_handles_bool_attributes():
- root_node = parse_html_string("<button disabled>Hello World!</button>")
- assert print_html_string(root_node) == "<button disabled>Hello World!</button>"
|