diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/abbrev.rb | 2 | ||||
-rw-r--r-- | test/test_abbrev.rb | 9 |
3 files changed, 15 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Fri Nov 30 12:47:59 2012 Akinori MUSHA <knu@iDaemons.org> + + * lib/abbrev.rb (Abbrev#abbrev): A fixed string prefix pattern + should only match the beginning of each word, not the beginning + of every line in it. + Fri Nov 30 12:30:55 2012 Akinori MUSHA <knu@iDaemons.org> * test/test_abbrev.rb: Add tests for lib/abbrev.rb. diff --git a/lib/abbrev.rb b/lib/abbrev.rb index 1aae0e1fcf..443ab6d8f1 100644 --- a/lib/abbrev.rb +++ b/lib/abbrev.rb @@ -69,7 +69,7 @@ module Abbrev seen = Hash.new(0) if pattern.is_a?(String) - pattern = /^#{Regexp.quote(pattern)}/ # regard as a prefix + pattern = /\A#{Regexp.quote(pattern)}/ # regard as a prefix end words.each do |word| diff --git a/test/test_abbrev.rb b/test/test_abbrev.rb index 13d673e8e1..f342c59e20 100644 --- a/test/test_abbrev.rb +++ b/test/test_abbrev.rb @@ -36,12 +36,19 @@ class TestAbbrev < Test::Unit::TestCase end def test_abbrev_lf + words = ["abc", "abc\nd", "de"] + assert_equal({ "abc" => "abc", "abc\n" => "abc\nd", "abc\nd" => "abc\nd", "d" => "de", "de" => "de", - }, Abbrev.abbrev(["abc", "abc\nd", "de"])) + }, words.abbrev) + + assert_equal({ + "d" => "de", + "de" => "de", + }, words.abbrev('d')) end end |