# encoding: utf-8 require File.dirname(__FILE__) + '/spec_helper' class TestHitHighlighter include Twitter::HitHighlighter end describe Twitter::HitHighlighter do describe "highlight" do before do @highlighter = TestHitHighlighter.new end context "with options" do before do @original = "Testing this hit highliter" @hits = [[13,16]] end it "should default to tags" do @highlighter.hit_highlight(@original, @hits).should == "Testing this hit highliter" end it "should allow tag override" do @highlighter.hit_highlight(@original, @hits, :tag => 'b').should == "Testing this hit highliter" end end context "without links" do before do @original = "Hey! this is a test tweet" end it "should return original when no hits are provided" do @highlighter.hit_highlight(@original).should == @original end it "should highlight one hit" do @highlighter.hit_highlight(@original, hits = [[5, 9]]).should == "Hey! this is a test tweet" end it "should highlight two hits" do @highlighter.hit_highlight(@original, hits = [[5, 9], [15, 19]]).should == "Hey! this is a test tweet" end it "should correctly highlight first-word hits" do @highlighter.hit_highlight(@original, hits = [[0, 3]]).should == "Hey! this is a test tweet" end it "should correctly highlight last-word hits" do @highlighter.hit_highlight(@original, hits = [[20, 25]]).should == "Hey! this is a test tweet" end end context "with links" do it "should highlight with a single link" do @highlighter.hit_highlight("@bcherry this was a test tweet", [[9, 13]]).should == "@bcherry this was a test tweet" end it "should highlight with link at the end" do @highlighter.hit_highlight("test test test", [[5, 9]]).should == "test test test" end it "should highlight with a link at the beginning" do @highlighter.hit_highlight("test test test", [[5, 9]]).should == "test test test" end it "should highlight an entire link" do @highlighter.hit_highlight("test test test", [[5, 9]]).should == "test test test" end it "should highlight within a link" do @highlighter.hit_highlight("test test test", [[6, 8]]).should == "test test test" end it "should highlight around a link" do @highlighter.hit_highlight("test test test", [[3, 11]]).should == "test test test" end it "should fail gracefully with bad hits" do @highlighter.hit_highlight("test test", [[5, 20]]).should == "test test" end it "should not mess up with touching tags" do @highlighter.hit_highlight("foofoo", [[3,6]]).should == "foofoo" end end end end