0
@@ -57,6 +57,12 @@ class TestString < Test::Unit::TestCase
0
assert_equal(S("Foo"), S("FooBar")[/([A-Z]..)([A-Z]..)/, -2])
0
assert_equal(nil, S("FooBar")[/([A-Z]..)([A-Z]..)/, -3])
0
+ assert_equal("o", "foo"[o])
0
+ assert_raise(ArgumentError) { "foo"[] }
0
@@ -136,6 +142,14 @@ class TestString < Test::Unit::TestCase
0
s[0..s.size] = S("another string")
0
assert_equal(S("another string"), s)
0
+ assert_equal("fobar", s)
0
+ assert_raise(ArgumentError) { "foo"[1, 2, 3] = "" }
0
@@ -150,6 +164,21 @@ class TestString < Test::Unit::TestCase
0
assert_equal(0, S("ABCDEF") <=> S("abcdef"))
0
+ assert_nil("foo" <=> Object.new)
0
+ def o.to_str; "bar"; end
0
+ assert_nil("foo" <=> o)
0
+ def o.<=>(x); nil; end
0
+ assert_nil("foo" <=> o)
0
+ assert_equal(-1, "foo" <=> o)
0
+ def o.<=>(x); 2**100; end
0
+ assert_equal(-(2**100), "foo" <=> o)
0
@@ -165,6 +194,13 @@ class TestString < Test::Unit::TestCase
0
assert(S("CAT") != S('cat'))
0
assert(S("CaT") != S('cAt'))
0
+ def o.==(x); false; end
0
+ assert_equal(false, "foo" == o)
0
+ def o.==(x); true; end
0
+ assert_equal(true, "foo" == o)
0
@@ -176,6 +212,11 @@ class TestString < Test::Unit::TestCase
0
assert_equal("a" * (2 << i), s)
0
+ assert_equal(l + 3, s.size)
0
@@ -187,6 +228,12 @@ class TestString < Test::Unit::TestCase
0
assert_equal(10, S("FeeFieFoo-Fum") =~ /FUM$/)
0
+ def o.=~(x); x + "bar"; end
0
+ assert_equal("foobar", S("foo") =~ o)
0
+ assert_raise(TypeError) { S("foo") =~ "foo" }
0
@@ -329,7 +376,22 @@ class TestString < Test::Unit::TestCase
0
assert_equal(S("hello"), a.chomp!)
0
assert_equal(S("hello\n"), b)
0
+ assert_equal("foo", s)
0
+ assert_equal("foo", s)
0
+ assert_equal("foo", s)
0
+ assert_equal("foo\r", s)
0
@@ -393,6 +455,8 @@ class TestString < Test::Unit::TestCase
0
assert_equal(4, a.count(S("hello"), S("^l")))
0
assert_equal(4, a.count(S("ej-m")))
0
assert_equal(0, S("y").count(S("a\\-z")))
0
+ assert_raise(ArgumentError) { "foo".count }
0
@@ -432,6 +496,12 @@ class TestString < Test::Unit::TestCase
0
assert_equal(S("he"), a)
0
assert_equal(S("hello"), b)
0
+ assert_equal(S("ell"), a)
0
+ assert_raise(ArgumentError) { S("foo").delete! }
0
@@ -525,6 +595,10 @@ class TestString < Test::Unit::TestCase
0
assert_equal(S("world"), res[1])
0
+ "foo\nbar".each_line(nil) {|s2| s = s2 }
0
+ assert_equal("foo\nbar", s)
0
@@ -549,6 +623,8 @@ class TestString < Test::Unit::TestCase
0
assert(a.gsub(/./, S('X')).tainted?)
0
+ assert_raise(ArgumentError) { "foo".gsub }
0
@@ -637,6 +713,14 @@ class TestString < Test::Unit::TestCase
0
assert_nil(S("hello").index(?z))
0
assert_nil(S("hello").index(S("z")))
0
assert_nil(S("hello").index(/z./))
0
+ def o.to_str; "bar"; end
0
+ assert_equal(3, "foobarbarbaz".index(o))
0
+ assert_raise(TypeError) { "foo".index(Object.new) }
0
+ assert_nil("foo".index(//, -100))
0
@@ -727,6 +811,15 @@ class TestString < Test::Unit::TestCase
0
b = a.replace(S("xyz"))
0
assert_equal(S("xyz"), b)
0
+ s2 = ("bar" * 100).dup
0
+ s2 = ["foo"].pack("p")
0
@@ -768,6 +861,14 @@ class TestString < Test::Unit::TestCase
0
assert_nil(S("hello").rindex(?z))
0
assert_nil(S("hello").rindex(S("z")))
0
assert_nil(S("hello").rindex(/z./))
0
+ def o.to_str; "bar"; end
0
+ assert_equal(6, "foobarbarbaz".rindex(o))
0
+ assert_raise(TypeError) { "foo".rindex(Object.new) }
0
+ assert_nil("foo".rindex(//, -100))
0
@@ -935,6 +1036,8 @@ class TestString < Test::Unit::TestCase
0
assert_nil(a.slice!(S("plugh")))
0
assert_equal(S("FooBar"), a)
0
+ assert_raise(ArgumentError) { "foo".slice! }
0
@@ -958,6 +1061,8 @@ class TestString < Test::Unit::TestCase
0
assert_equal([S("a"), S(""), S("b"), S("c")], S("a||b|c|").split(S('|')))
0
assert_equal([S("a"), S(""), S("b"), S("c"), S("")], S("a||b|c|").split(S('|'), -1))
0
+ assert_equal([], "".split(//, 1))
0
@@ -1048,6 +1153,20 @@ class TestString < Test::Unit::TestCase
0
assert(a.sub(/./, S('X')).tainted?)
0
+ def o.to_str; "bar"; end
0
+ assert_equal("fooBARbaz", "foobarbaz".sub(o, "BAR"))
0
+ assert_raise(TypeError) { "foo".sub(Object.new, "") }
0
+ assert_raise(ArgumentError) { "foo".sub }
0
+ assert_raise(IndexError) { "foo"[/(?:(o$)|(x))/, 2] = 'bar' }
0
+ assert_match(/^foo#<Object:0x.*>baz$/, "foobarbaz".sub("bar") { o })
0
@@ -1402,6 +1521,8 @@ class TestString < Test::Unit::TestCase
0
+ assert_raise(ArgumentError) { "foo" * (-1) }
0
@@ -1411,4 +1532,72 @@ class TestString < Test::Unit::TestCase
0
def o.==(other) "" == other end
0
assert_equal(false, "" == o)
0
+ assert_equal("bar", "foobarbaz".match(/bar/).to_s)
0
+ def o.match(x, y, z); x + y + z; end
0
+ assert_equal("foobarbaz", "foo".match(o, "bar", "baz"))
0
+ "foo".match(o, "bar", "baz") {|y| x = y }
0
+ assert_equal("foobarbaz", x)
0
+ assert_raise(ArgumentError) { "foo".match }
0
+ assert_equal("foo", s.to_s)
0
+ assert_instance_of(String, s.to_s)
0
+ assert_equal(%w(he l lo), "hello".partition(/l/))
0
+ assert_equal(%w(he l lo), "hello".partition("l"))
0
+ assert_raise(TypeError) { "hello".partition(1) }
0
+ assert_equal(%w(hel l o), "hello".rpartition(/l/))
0
+ assert_equal(%w(hel l o), "hello".rpartition("l"))
0
+ assert_raise(TypeError) { "hello".rpartition(1) }
0
+ assert_raise(TypeError) { $/ = 1 }
0
+ assert_raise(TypeError) do
0
+ c.class_eval { attr 1 }
0
+ def o.to_str; :foo; end
0
+ assert_raise(TypeError) do
0
+ c.class_eval { attr 1 }
0
+ def o.to_str; "foo"; end
0
+ assert_nothing_raised do
0
+ c.class_eval { attr o }
0
+ assert_equal(:foo, c.new.foo)
Comments
No one has commented yet.