From 00cfd0d5bae2e7688754dfc458016d42abfcd037 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 14 Mar 2016 08:10:01 +0000 Subject: Add HTML AST with strip_empty function --- tests/html/__init__.py | 1 + tests/html/strip_empty_tests.py | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/html/__init__.py create mode 100644 tests/html/strip_empty_tests.py (limited to 'tests/html') diff --git a/tests/html/__init__.py b/tests/html/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/html/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/html/strip_empty_tests.py b/tests/html/strip_empty_tests.py new file mode 100644 index 0000000..eb28f30 --- /dev/null +++ b/tests/html/strip_empty_tests.py @@ -0,0 +1,65 @@ +from nose.tools import istest, assert_equal + +from mammoth import html + + +@istest +def text_nodes_with_text_are_not_stripped(): + assert_equal( + [html.text("H")], + html.strip_empty([html.text("H")])) + + +@istest +def empty_text_nodes_are_stripped(): + assert_equal( + [], + html.strip_empty([html.text("")])) + + +@istest +def elements_with_non_empty_children_are_not_stripped(): + assert_equal( + [html.element("p", {}, [html.text("H")])], + html.strip_empty([html.element("p", {}, [html.text("H")])])) + + +@istest +def elements_with_no_children_are_stripped(): + assert_equal( + [], + html.strip_empty([html.element("p")])) + + +@istest +def elements_with_only_empty_children_are_stripped(): + assert_equal( + [], + html.strip_empty([html.element("p", {}, [html.text("")])])) + + +@istest +def empty_children_are_removed(): + assert_equal( + html.strip_empty([html.element("ul", {}, [ + html.element("li", {}, [html.text("")]), + html.element("li", {}, [html.text("H")]), + ])]), + + [html.element("ul", {}, [ + html.element("li", {}, [html.text("H")]) + ])]) + + +@istest +def self_closing_elements_are_never_empty(): + assert_equal( + [html.self_closing_element("br")], + html.strip_empty([html.self_closing_element("br")])) + + +@istest +def force_writes_are_never_empty(): + assert_equal( + [html.force_write], + html.strip_empty([html.force_write])) -- cgit v1.2.3