def collapsible_element_can_collapse_into_previous_fresh_element(): assert_equal( [html.element("p", {}, [html.text("One"), html.text("Two")])], html.collapse([ html.element("p", {}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def consecutive_collapsible_elements_are_collapsed_if_they_have_the_same_tag_and_attributes(): assert_equal( [html.collapsible_element("p", {}, [html.text("One"), html.text("Two")])], html.collapse([ html.collapsible_element("p", {}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def elements_with_different_tag_names_are_not_collapsed(): assert_equal([ html.collapsible_element("p", {}, [html.text("One")]), html.collapsible_element("div", {}, [html.text("Two")]) ], html.collapse([ html.collapsible_element("p", {}, [html.text("One")]), html.collapsible_element("div", {}, [html.text("Two")]) ]))
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")]) ])])
def consecutive_collapsible_elements_are_collapsed_if_they_have_the_same_tag_and_attributes( ): assert_equal([ html.collapsible_element( "p", {}, [html.text("One"), html.text("Two")]) ], html.collapse([ html.collapsible_element("p", {}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def elements_with_different_attributes_are_not_collapsed(): assert_equal([ html.collapsible_element("p", {"id": "a"}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ], html.collapse([ html.collapsible_element("p", {"id": "a"}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def elements_with_different_tag_names_are_not_collapsed(): assert_equal( [ html.collapsible_element("p", {}, [html.text("One")]), html.collapsible_element("div", {}, [html.text("Two")]) ], html.collapse([ html.collapsible_element("p", {}, [html.text("One")]), html.collapsible_element("div", {}, [html.text("Two")]) ]))
def elements_with_different_attributes_are_not_collapsed(): assert_equal( [ html.collapsible_element("p", {"id": "a"}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ], html.collapse([ html.collapsible_element("p", {"id": "a"}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def children_of_collapsed_element_can_collapse_with_children_of_previous_element( ): assert_equal([ html.collapsible_element("blockquote", {}, [ html.collapsible_element( "p", {}, [html.text("One"), html.text("Two")]) ]), ], html.collapse([ html.collapsible_element("blockquote", {}, [ html.collapsible_element("p", {}, [html.text("One")]) ]), html.collapsible_element("blockquote", {}, [ html.collapsible_element("p", {}, [html.text("Two")]) ]), ]))
def children_of_collapsed_element_can_collapse_with_children_of_previous_element(): assert_equal( [ html.collapsible_element("blockquote", {}, [ html.collapsible_element("p", {}, [ html.text("One"), html.text("Two") ]) ]), ], html.collapse([ html.collapsible_element("blockquote", {}, [ html.collapsible_element("p", {}, [html.text("One")]) ]), html.collapsible_element("blockquote", {}, [ html.collapsible_element("p", {}, [html.text("Two")]) ]), ]))
def table_nodes_are_reserved(): elements = [ html.element('table', {}, [ html.element('tr', {'rowspan': 2}, [ html.element('td', {}, [html.text('H')]), ]), html.element('tr', []), ]) ] assert_equal(elements, html.strip_empty(elements))
def when_separator_is_present_then_separator_is_prepended_to_collapsed_element(): assert_equal( [ html.element("pre", collapsible=False, children=[ html.text("Hello"), html.text("\n"), html.text(" the"), html.text("re") ]) ], html.collapse([ html.element("pre", collapsible=False, children=[html.text("Hello")]), html.element("pre", collapsible=True, separator="\n", children=[html.text(" the"), html.text("re")]), ]), )
def when_separator_is_present_then_separator_is_prepended_to_collapsed_element( ): assert_equal( [ html.element("pre", collapsible=False, children=[ html.text("Hello"), html.text("\n"), html.text(" the"), html.text("re") ]) ], html.collapse([ html.element("pre", collapsible=False, children=[html.text("Hello")]), html.element("pre", collapsible=True, separator="\n", children=[html.text(" the"), html.text("re")]), ]), )
def collapsing_does_nothing_to_single_text_node(): assert_equal(html.collapse([html.text("Bluebells")]), [html.text("Bluebells")])
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")])]))
def empty_text_nodes_are_stripped(): assert_equal( [], html.strip_empty([html.text("")]))
def text_nodes_with_text_are_not_stripped(): assert_equal( [html.text("H")], html.strip_empty([html.text("H")]))
def elements_with_only_empty_children_are_stripped(): assert_equal( [], html.strip_empty([html.element("p", {}, [html.text("")])]))
def collapsing_does_nothing_to_single_text_node(): assert_equal( html.collapse([html.text("Bluebells")]), [html.text("Bluebells")])
def empty_text_nodes_are_stripped(): assert_equal([], html.strip_empty([html.text("")]))
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")])]))
def elements_with_only_empty_children_are_stripped(): assert_equal([], html.strip_empty([html.element("p", {}, [html.text("")])]))
def text_nodes_with_text_are_not_stripped(): assert_equal([html.text("H")], html.strip_empty([html.text("H")]))