summaryrefslogtreecommitdiff
path: root/tests/html/strip_empty_tests.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-03-14 08:10:01 +0000
committerMichael Williamson <mike@zwobble.org>2016-03-14 20:09:13 +0000
commit00cfd0d5bae2e7688754dfc458016d42abfcd037 (patch)
tree24b49bdad94d9c34c755ec50e0db5fb39a34aee8 /tests/html/strip_empty_tests.py
parent2329dbcbbc945437256569c789b127e454069c98 (diff)
Add HTML AST with strip_empty function
Diffstat (limited to 'tests/html/strip_empty_tests.py')
-rw-r--r--tests/html/strip_empty_tests.py65
1 files changed, 65 insertions, 0 deletions
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]))