[Rubytests-commit] rubicon/builtin TestString.rb
holmberg at rubyforge.org
holmberg at rubyforge.org
Thu Aug 25 17:53:41 EDT 2005
Update of /var/cvs/rubytests/rubicon/builtin
In directory rubyforge.org:/tmp/cvs-serv20646
Modified Files:
TestString.rb
Log Message:
Added a test for String#scan with a regexp argument that may match
an empty string. This has not been tested earlier.
Also modified the S() utility method, so it now accepts either
a String or *an array of Strings*. The array-case makes the test
added to "test_scan" easier to read, and seems to be in line with
the purpose of the S() method: to do the conversion String --> @cls,
without cluttering the testcase code too much.
Example of what the S() change leads to:
before: [ S("foo"), S(""), S(""), S("bar"), ... ]
after: S( ["foo", "", "", "bar",...] )
Index: TestString.rb
===================================================================
RCS file: /var/cvs/rubytests/rubicon/builtin/TestString.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** TestString.rb 25 Aug 2005 20:57:28 -0000 1.8
--- TestString.rb 25 Aug 2005 21:53:39 -0000 1.9
***************
*** 36,41 ****
end
! def S(str)
! @cls.new(str)
end
--- 36,45 ----
end
! def S(str_or_array)
! if str_or_array.instance_of?(Array)
! str_or_array.map {|str| @cls.new(str) }
! else
! @cls.new(str_or_array)
! end
end
***************
*** 935,938 ****
--- 939,946 ----
a.scan(/(...)/) { |w| res << w }
assert_equal([[S("cru")], [S("el ")], [S("wor")]],res)
+
+ # with a pattern that match empty string
+ assert_equal(S(["", "", "1", "", "", "22", "", "", "333", ""]),
+ S("aa1bb22cc333").scan(/\d*/))
end
More information about the Rubytests-commit
mailing list