def test_highlight_args(self): eq_( 'The c<strong class="highlight">at</strong> in the h<strong class="highlight">at</strong>.', highlight("The cat in the hat.", "AT"), ) eq_("The cat in the hat.", highlight("The cat in the hat.", "AT", case_sensitive=True)) eq_( 'The c<strong style="color:red">at</strong> in the h<strong style="color:red">at</strong>.', highlight("The cat in the hat.", "at", class_=None, style="color:red"), )
def test_highlight_phrases(self): eq_( 'The c<strong class="highlight">at</strong> in the h<strong class="highlight">at</strong>.', highlight("The cat in the hat.", "at"), ) eq_( 'The <strong class="highlight">cat</strong> in the <strong class="highlight">hat</strong>.', highlight("The cat in the hat.", ["cat", "hat"]), ) eq_( 'The <strong class="highlight">cat</strong> is <strong class="highlight">cut</strong>.', highlight("The cat is cut.", re.compile(r"c.t")), )
def test_highlight(self): eq_( 'This is a <strong class="highlight">beautiful</strong> morning', highlight("This is a beautiful morning", "beautiful"), ) eq_( 'This is a <strong class="highlight">beautiful</strong> morning, but also a <strong class="highlight">beautiful</strong> day', highlight("This is a beautiful morning, but also a beautiful day", "beautiful"), ) eq_( "This text is not changed because we supplied an empty phrase", highlight("This text is not changed because we supplied an empty phrase", None), )
def test_highlight_with_regex(self): eq_( 'This is a <strong class="highlight">beautiful!</strong> morning', highlight("This is a beautiful! morning", "beautiful!"), ) eq_( 'This is a <strong class="highlight">beautiful! morning</strong>', highlight("This is a beautiful! morning", "beautiful! morning"), ) eq_( 'This is a <strong class="highlight">beautiful? morning</strong>', highlight("This is a beautiful? morning", "beautiful? morning"), )
def test_highlight_legacy_highlighter(self): eq_( "This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day", highlight("This is a beautiful morning, but also a beautiful day", "beautiful", r"<b>\1</b>"), )
def test_highlight_literal(self): eq_(literal(u'The <red> c<strong class="highlight">at</strong>.'), highlight("The <red> cat.", "at")) eq_(literal(u'The <red> c<strong class="highlight">at</strong>.'), highlight(literal("The <red> cat."), "at"))