aboutsummaryrefslogtreecommitdiffstats
path: root/spec/helpers/highlight_helper_spec.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-05-30 15:48:10 +0100
committerGareth Rees <gareth@mysociety.org>2014-06-25 10:40:37 +0100
commit4d9c89d0e416825eb52a720d74230f547454ba31 (patch)
tree7716d1bd5205beb872b949689f219b56d63f665c /spec/helpers/highlight_helper_spec.rb
parente5a73815f580d296572e11b71b5f3ed320bbe912 (diff)
Use regex based highlighting
Diffstat (limited to 'spec/helpers/highlight_helper_spec.rb')
-rw-r--r--spec/helpers/highlight_helper_spec.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/spec/helpers/highlight_helper_spec.rb b/spec/helpers/highlight_helper_spec.rb
index bd0c62226..675100f00 100644
--- a/spec/helpers/highlight_helper_spec.rb
+++ b/spec/helpers/highlight_helper_spec.rb
@@ -105,6 +105,13 @@ describe HighlightHelper do
assert_equal options, passed_options
end
+ it 'highlights with a block' do
+ assert_equal(
+ "<b>one</b> <b>two</b> <b>three</b>",
+ highlight_matches("one two three", ["one", "two", "three"]) { |word| "<b>#{word}</b>" }
+ )
+ end
+
end
describe :excerpt do
@@ -113,8 +120,6 @@ describe HighlightHelper do
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5))
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", :radius => 5))
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", :radius => 5))
- assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 5))
- assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 1, :separator => ' '))
assert_nil excerpt("This is a beautiful morning", "day")
end
@@ -142,6 +147,11 @@ describe HighlightHelper do
it 'excerpts with regex' do
assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', :radius => 5))
assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', :radius => 5))
+ assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', /\bbeau\w*\b/i, :radius => 5))
+ assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', /\b(beau\w*)\b/i, :radius => 5))
+ assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 5))
+ assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 1, :separator => ' '))
+ assert_equal("...was challenging for...", excerpt("This day was challenging for judge Allen and his colleagues.", /\b(\w*allen\w*)\b/i, :radius => 5))
end
it 'excerpts with omission' do