ruby-changes:5071
From: akr <ko1@a...>
Date: Sat, 24 May 2008 11:12:27 +0900 (JST)
Subject: [ruby-changes:5071] Ruby:r16566 (trunk): add a test for .
akr 2008-05-24 10:48:21 +0900 (Sat, 24 May 2008)
New Revision: 16566
Modified files:
trunk/test/ruby/test_string.rb
Log:
add a test for [ruby-dev:34828].
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_string.rb?r1=16566&r2=16565&diff_format=u
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb (revision 16565)
+++ test/ruby/test_string.rb (revision 16566)
@@ -1,4 +1,5 @@
require 'test/unit'
+require_relative 'envutil'
# use of $= is deprecated after 1.7.1
def pre_1_7_1
@@ -1506,6 +1507,73 @@
assert_equal(676, count)
end
+ def test_mod_check
+ assert_raise(RuntimeError) {
+ s = ""
+ s.sub!(/\A/) { s.replace "z" * 2000; "zzz" }
+ }
+ end
+
+ def test_frozen_check
+ assert_raise(RuntimeError) {
+ s = ""
+ s.sub!(/\A/) { s.freeze; "zzz" }
+ }
+ end
+
+ def test_tainted_str_new
+ a = []
+ a << a
+ s = a.inspect
+ assert(s.tainted?)
+ assert_equal("[[...]]", s)
+ end
+
+ class S2 < String
+ end
+ def test_str_new4
+ s = (0..54).to_a.join # length = 100
+ s2 = S2.new(s[10,90])
+ s3 = s2[10,80]
+ assert_equal((10..54).to_a.to_a.join, s2)
+ assert_equal((15..54).to_a.to_a.join, s3)
+ end
+
+ def test_rb_str_new4
+ s = "a" * 100
+ s2 = s[10,90]
+ assert_equal("a" * 90, s2)
+ s3 = s2[10,80]
+ assert_equal("a" * 80, s3)
+ end
+
+ class StringLike
+ def initialize(str)
+ @str = str
+ end
+
+ def to_str
+ @str
+ end
+ end
+
+ def test_rb_str_to_str
+ assert_equal("ab", "a" + StringLike.new("b"))
+ end
+
+ def test_rb_str_shared_replace
+ s = "a" * 100
+ s.succ!
+ assert_equal("a" * 99 + "b", s)
+ s = ""
+ s.succ!
+ assert_equal("", s)
+ end
+
+ def test_times
+ assert_raise(ArgumentError) { "a" * (-1) }
+ end
+
def test_splice!
l = S("1234\n234\n34\n4\n")
assert_equal(S("1234\n"), l.slice!(/\A.*\n/), "[ruby-dev:31665]")
@@ -1605,4 +1673,8 @@
end
assert_equal(:foo, c.new.foo)
end
+
+ def test_gsub_enumerator
+ assert_normal_exit %q{"abc".gsub(/./).next}, "[ruby-dev:34828]"
+ end
end
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/