[前][次][番号順一覧][スレッド一覧]

ruby-changes:25970

From: knu <ko1@a...>
Date: Fri, 30 Nov 2012 12:56:37 +0900 (JST)
Subject: [ruby-changes:25970] knu:r38027 (trunk): Fix a line matching problem in Abbrev.abbrev(words, "prefix").

knu	2012-11-30 12:56:28 +0900 (Fri, 30 Nov 2012)

  New Revision: 38027

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38027

  Log:
    Fix a line matching problem in Abbrev.abbrev(words, "prefix").
    
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/abbrev.rb
    trunk/test/test_abbrev.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38026)
+++ ChangeLog	(revision 38027)
@@ -1,3 +1,9 @@
+Fri Nov 30 12:47:59 2012  Akinori MUSHA  <knu@i...>
+
+	* 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@i...>
 
 	* test/test_abbrev.rb: Add tests for lib/abbrev.rb.
Index: lib/abbrev.rb
===================================================================
--- lib/abbrev.rb	(revision 38026)
+++ lib/abbrev.rb	(revision 38027)
@@ -69,7 +69,7 @@
     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|
Index: test/test_abbrev.rb
===================================================================
--- test/test_abbrev.rb	(revision 38026)
+++ test/test_abbrev.rb	(revision 38027)
@@ -36,12 +36,19 @@
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]