def test_horrors(self): """Untangle a circus of interleaved tags, tags that start where others end, and other untold wretchedness.""" # This is a little brittle. All we really want to test is that each # span of text is within the right spans. We don't care what order the # span tags are in. eq_( list( build_lines( "this&that", [ Htmlifier( regions=[ (0, 9, "a"), (1, 8, "b"), (4, 7, "c"), (3, 4, "d"), (3, 5, "e"), (0, 4, "m"), (5, 9, "n"), ] ) ], ) ), [ u'<span class="a"><span class="m">t<span class="b">hi<span class="d"><span class="e">s</span></span></span></span><span class="b"><span class="e"><span class="c">&</span></span><span class="c"><span class="n">th</span></span><span class="n">a</span></span><span class="n">t</span></span>' ], )
def test_simple(self): """Sanity-check build_lines, which ties the whole shootin' match together.""" eq_( "".join(build_lines("hello", [Htmlifier(regions=[(0, 3, "a"), (3, 5, "b")])])), u'<span class="a">hel</span><span class="b">lo</span>', )
def test_empty_tag_boundaries(self): """Zero-length tags should be filtered out by ``tag_boundaries()``. If they are not, the start of a tag can sort after the end, crashing the tag balancer. """ list(build_lines("hello!", [Htmlifier(regions=[(3, 3, "a"), (3, 5, "b")])]))
def test_split_anchor_avoidance(self): """Don't split anchor tags when we can avoid it.""" eq_( ''.join( build_lines( 'this that', [Htmlifier(regions=[(0, 4, 'k')], refs=[(0, 9, {})])])), u'<a data-menu="{}"><span class="k">this</span> that</a>')
def test_simple(self): """Sanity-check build_lines, which ties the whole shootin' match together.""" eq_( ''.join( build_lines('hello', [Htmlifier(regions=[(0, 3, 'a'), (3, 5, 'b')])])), u'<span class="a">hel</span><span class="b">lo</span>')
def test_empty_tag_boundaries(self): """Zero-length tags should be filtered out by ``tag_boundaries()``. If they are not, the start of a tag can sort after the end, crashing the tag balancer. """ list( build_lines('hello!', [Htmlifier(regions=[(3, 3, 'a'), (3, 5, 'b')])]))
def test_horrors(self): """Untangle a circus of interleaved tags, tags that start where others end, and other untold wretchedness.""" # This is a little brittle. All we really want to test is that each # span of text is within the right spans. We don't care what order the # span tags are in. eq_( list( build_lines('this&that', [ Htmlifier(regions=[(0, 9, 'a'), (1, 8, 'b'), ( 4, 7, 'c'), (3, 4, 'd'), (3, 5, 'e'), (0, 4, 'm'), (5, 9, 'n')]) ])), [ u'<span class="a"><span class="m">t<span class="b">hi<span class="d"><span class="e">s</span></span></span></span><span class="b"><span class="e"><span class="c">&</span></span><span class="c"><span class="n">th</span></span><span class="n">a</span></span><span class="n">t</span></span>' ])
def test_split_anchor_across_lines(self): """Support unavoidable splits of an anchor across lines.""" eq_(list(build_lines('this\nthat', [Htmlifier(refs=[(0, 9, {})])])), [u'<a data-menu="{}">this</a>', u'<a data-menu="{}">that</a>'])
def test_split_anchor_avoidance(self): """Don't split anchor tags when we can avoid it.""" eq_(''.join(build_lines('this that', [Htmlifier(regions=[(0, 4, 'k')], refs=[(0, 9, {})])])), u'<a data-menu="{}"><span class="k">this</span> that</a>')
def test_split_anchor_avoidance(self): """Don't split anchor tags when we can avoid it.""" eq_( "".join(build_lines("this that", [Htmlifier(regions=[(0, 4, "k")], refs=[(0, 9, ({}, "", None))])])), u'<a data-menu="{}"><span class="k">this</span> that</a>', )