# 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 expect(@highlighter.hit_highlight(@original, @hits)).to be == "Testing this hit highliter" end it "should allow tag override" do expect(@highlighter.hit_highlight(@original, @hits, :tag => 'b')).to be == "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 expect(@highlighter.hit_highlight(@original)).to be == @original end it "should highlight one hit" do expect(@highlighter.hit_highlight(@original, hits = [[5, 9]])).to be == "Hey! this is a test tweet" end it "should highlight two hits" do expect(@highlighter.hit_highlight(@original, hits = [[5, 9], [15, 19]])).to be == "Hey! this is a test tweet" end it "should correctly highlight first-word hits" do expect(@highlighter.hit_highlight(@original, hits = [[0, 3]])).to be == "Hey! this is a test tweet" end it "should correctly highlight last-word hits" do expect(@highlighter.hit_highlight(@original, hits = [[20, 25]])).to be == "Hey! this is a test tweet" end end context "with links" do it "should highlight with a single link" do expect(@highlighter.hit_highlight("@bcherry this was a test tweet", [[9, 13]])).to be == "@bcherry this was a test tweet" end it "should highlight with link at the end" do expect(@highlighter.hit_highlight("test test test", [[5, 9]])).to be == "test test test" end it "should highlight with a link at the beginning" do expect(@highlighter.hit_highlight("test test test", [[5, 9]])).to be == "test test test" end it "should highlight an entire link" do expect(@highlighter.hit_highlight("test test test", [[5, 9]])).to be == "test test test" end it "should highlight within a link" do expect(@highlighter.hit_highlight("test test test", [[6, 8]])).to be == "test test test" end it "should highlight around a link" do expect(@highlighter.hit_highlight("test test test", [[3, 11]])).to be == "test test test" end it "should fail gracefully with bad hits" do expect(@highlighter.hit_highlight("test test", [[5, 20]])).to be == "test test" end it "should not mess up with touching tags" do expect(@highlighter.hit_highlight("foofoo", [[3,6]])).to be == "foofoo" end end end end