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

ruby-changes:70786

From: Nobuyoshi <ko1@a...>
Date: Sat, 8 Jan 2022 15:50:15 +0900 (JST)
Subject: [ruby-changes:70786] 64eccbf578 (master): Run the tests on a subclass of String

https://git.ruby-lang.org/ruby.git/commit/?id=64eccbf578

From 64eccbf578b82b30299418444a1b77027c2abdd9 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 8 Jan 2022 13:53:10 +0900
Subject: Run the tests on a subclass of String

---
 test/ruby/test_string.rb | 543 ++++++++++++++++++++++++-----------------------
 1 file changed, 273 insertions(+), 270 deletions(-)

diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 3f7c06e0756..52e83ebc1fb 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -83,7 +83,7 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L83
   end
 
   def test_initialize_shared
-    String.new(str = "mystring" * 10).__send__(:initialize, capacity: str.bytesize)
+    S(str = "mystring" * 10).__send__(:initialize, capacity: str.bytesize)
     assert_equal("mystring", str[0, 8])
   end
 
@@ -240,23 +240,23 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L240
 
     assert_equal(-1, S("ABCDEF") <=> S("abcdef"))
 
-    assert_nil("foo" <=> Object.new)
+    assert_nil(S("foo") <=> Object.new)
 
     o = Object.new
     def o.to_str; "bar"; end
-    assert_equal(1, "foo" <=> o)
+    assert_equal(1, S("foo") <=> o)
 
     class << o;remove_method :to_str;end
     def o.<=>(x); nil; end
-    assert_nil("foo" <=> o)
+    assert_nil(S("foo") <=> o)
 
     class << o;remove_method :<=>;end
     def o.<=>(x); 1; end
-    assert_equal(-1, "foo" <=> o)
+    assert_equal(-1, S("foo") <=> o)
 
     class << o;remove_method :<=>;end
     def o.<=>(x); 2**100; end
-    assert_equal(-1, "foo" <=> o)
+    assert_equal(-1, S("foo") <=> o)
   end
 
   def test_EQUAL # '=='
@@ -270,10 +270,10 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L270
     o = Object.new
     def o.to_str; end
     def o.==(x); false; end
-    assert_equal(false, "foo" == o)
+    assert_equal(false, S("foo") == o)
     class << o;remove_method :==;end
     def o.==(x); true; end
-    assert_equal(true, "foo" == o)
+    assert_equal(true, S("foo") == o)
   end
 
   def test_LSHIFT # '<<'
@@ -648,12 +648,12 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L648
     result << 0x0300
     expected = S("\u0300".encode(Encoding::UTF_16LE))
     assert_equal(expected, result, bug7090)
-    assert_raise(TypeError) { 'foo' << :foo }
-    assert_raise(FrozenError) { 'foo'.freeze.concat('bar') }
+    assert_raise(TypeError) { S('foo') << :foo }
+    assert_raise(FrozenError) { S('foo').freeze.concat('bar') }
   end
 
   def test_concat_literals
-    s="." * 50
+    s=S("." * 50)
     assert_equal(Encoding::UTF_8, "#{s}x".encoding)
   end
 
@@ -664,18 +664,18 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L664
     assert_equal(4, a.count(S("hello"), S("^l")))
     assert_equal(4, a.count(S("ej-m")))
     assert_equal(0, S("y").count(S("a\\-z")))
-    assert_equal(5, "abc\u{3042 3044 3046}".count("^a"))
-    assert_equal(1, "abc\u{3042 3044 3046}".count("\u3042"))
-    assert_equal(5, "abc\u{3042 3044 3046}".count("^\u3042"))
-    assert_equal(2, "abc\u{3042 3044 3046}".count("a-z", "^a"))
-    assert_equal(0, "abc\u{3042 3044 3046}".count("a", "\u3042"))
-    assert_equal(0, "abc\u{3042 3044 3046}".count("\u3042", "a"))
-    assert_equal(0, "abc\u{3042 3044 3046}".count("\u3042", "\u3044"))
-    assert_equal(4, "abc\u{3042 3044 3046}".count("^a", "^\u3044"))
-    assert_equal(4, "abc\u{3042 3044 3046}".count("^\u3044", "^a"))
-    assert_equal(4, "abc\u{3042 3044 3046}".count("^\u3042", "^\u3044"))
+    assert_equal(5, S("abc\u{3042 3044 3046}").count("^a"))
+    assert_equal(1, S("abc\u{3042 3044 3046}").count("\u3042"))
+    assert_equal(5, S("abc\u{3042 3044 3046}").count("^\u3042"))
+    assert_equal(2, S("abc\u{3042 3044 3046}").count("a-z", "^a"))
+    assert_equal(0, S("abc\u{3042 3044 3046}").count("a", "\u3042"))
+    assert_equal(0, S("abc\u{3042 3044 3046}").count("\u3042", "a"))
+    assert_equal(0, S("abc\u{3042 3044 3046}").count("\u3042", "\u3044"))
+    assert_equal(4, S("abc\u{3042 3044 3046}").count("^a", "^\u3044"))
+    assert_equal(4, S("abc\u{3042 3044 3046}").count("^\u3044", "^a"))
+    assert_equal(4, S("abc\u{3042 3044 3046}").count("^\u3042", "^\u3044"))
 
-    assert_raise(ArgumentError) { "foo".count }
+    assert_raise(ArgumentError) { S("foo").count }
   end
 
   def crypt_supports_des_crypt?
@@ -717,17 +717,17 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L717
     assert_equal(S("hell"), S("hello").delete(S("aeiou"), S("^e")))
     assert_equal(S("ho"),   S("hello").delete(S("ej-m")))
 
-    assert_equal("a".hash, "a\u0101".delete("\u0101").hash, '[ruby-talk:329267]')
-    assert_equal(true, "a\u0101".delete("\u0101").ascii_only?)
-    assert_equal(true, "a\u3041".delete("\u3041").ascii_only?)
-    assert_equal(false, "a\u3041\u3042".delete("\u3041").ascii_only?)
+    assert_equal(S("a").hash, S("a\u0101").delete("\u0101").hash, '[ruby-talk:329267]')
+    assert_equal(true, S("a\u0101").delete("\u0101").ascii_only?)
+    assert_equal(true, S("a\u3041").delete("\u3041").ascii_only?)
+    assert_equal(false, S("a\u3041\u3042").delete("\u3041").ascii_only?)
 
-    assert_equal("a", "abc\u{3042 3044 3046}".delete("^a"))
-    assert_equal("bc\u{3042 3044 3046}", "abc\u{3042 3044 3046}".delete("a"))
-    assert_equal("\u3042", "abc\u{3042 3044 3046}".delete("^\u3042"))
+    assert_equal("a", S("abc\u{3042 3044 3046}").delete("^a"))
+    assert_equal("bc\u{3042 3044 3046}", S("abc\u{3042 3044 3046}").delete("a"))
+    assert_equal("\u3042", S("abc\u{3042 3044 3046}").delete("^\u3042"))
 
     bug6160 = '[ruby-dev:45374]'
-    assert_equal("", '\\'.delete('\\'), bug6160)
+    assert_equal("", S('\\').delete('\\'), bug6160)
   end
 
   def test_delete!
@@ -832,10 +832,10 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L832
     assert_equal(Encoding::UTF_8, S('"\\u3042"').encode(Encoding::EUC_JP).undump.encoding)
 
     assert_equal("abc".encode(Encoding::UTF_16LE),
-                 '"a\x00b\x00c\x00".force_encoding("UTF-16LE")'.undump)
+                 S('"a\x00b\x00c\x00".force_encoding("UTF-16LE")').undump)
 
-    assert_equal('\#', '"\\\\#"'.undump)
-    assert_equal('\#{', '"\\\\\#{"'.undump)
+    assert_equal('\#', S('"\\\\#"').undump)
+    assert_equal('\#{', S('"\\\\\#{"').undump)
 
     assert_raise(RuntimeError) { S('\u3042').undump }
     assert_raise(RuntimeError) { S('"\x82\xA0\u3042"'.force_encoding("SJIS")).undump }
@@ -867,7 +867,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L867
     assert_raise(RuntimeError) { S('"\\"').undump }
     assert_raise(RuntimeError) { S(%("\0")).undump }
     assert_raise_with_message(RuntimeError, /invalid/) {
-      '"\\u{007F}".xxxxxx'.undump
+      S('"\\u{007F}".xxxxxx').undump
     }
   end
 
@@ -1047,9 +1047,9 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1047
       g = g.encode(enc)
       assert_equal g.chars, g.grapheme_clusters
     end
-    assert_equal ["a", "b", "c"], "abc".b.grapheme_clusters
+    assert_equal ["a", "b", "c"], S("abc").b.grapheme_clusters
 
-    s = "ABC".b
+    s = S("ABC").b
     res = []
     assert_same s, s.grapheme_clusters {|x| res << x }
     assert_equal(3, res.size)
@@ -1095,7 +1095,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1095
     $/ = save
 
     s = nil
-    "foo\nbar".each_line(nil) {|s2| s = s2 }
+    S("foo\nbar").each_line(nil) {|s2| s = s2 }
     assert_equal("foo\nbar", s)
 
     assert_equal "hello\n", S("hello\nworld").each_line.next
@@ -1103,7 +1103,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1103
 
     bug7646 = "[ruby-dev:46827]"
     assert_nothing_raised(bug7646) do
-      "\n\u0100".each_line("\n") {}
+      S("\n\u0100").each_line("\n") {}
     end
   ensure
     $/ = save
@@ -1137,7 +1137,7 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1137
     assert_equal(S("a"), res[0])
 
     s = nil
-    "foo\nbar".each_line(nil, chomp: true) {|s2| s = s2 }
+    S("foo\nbar").each_line(nil, chomp: true) {|s2| s = s2 }
     assert_equal("foo\nbar", s)
 
     assert_equal "hello", S("hello\nworld").each_line(chomp: true).next
@@ -1202,9 +1202,9 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1202
                  S("hello").gsub(/(hell)(.)/) { |s| $1.upcase + S('-') + $2 })
     assert_equal(S("<>h<>e<>l<>l<>o<>"), S("hello").gsub(S(''), S('<\0>')))
 
-    assert_equal("z", "abc".gsub(/./, "a" => "z"), "moved from btest/knownbug")
+    assert_equal("z", S("abc").gsub(/./, "a" => "z"), "moved from btest/knownbug")
 
-    assert_raise(ArgumentError) { "foo".gsub }
+    assert_raise(ArgumentError) { S("foo").gsub }
   end
 
   def test_gsub_encoding
@@ -1251,23 +1251,23 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1251
   end
 
   def test_sub_hash
-    assert_equal('azc', 'abc'.sub(/b/, "b" => "z"))
-    assert_equal('ac', 'abc'.sub(/b/, {}))
-    assert_equal('a1c', 'abc'.sub(/b/, "b" => 1))
-    assert_equal('aBc', 'abc'.sub(/b/, Hash.new {|h, k| k.upcase }))
-    assert_equal('a[\&]c', 'abc'.sub(/b/, "b" => '[\&]'))
-    assert_equal('aBcabc', 'abcabc'.sub(/b/, Hash.new {|h, k| h[k] = k.upcase }))
-    assert_equal('aBcdef', 'abcdef'.sub(/de|b/, "b" => "B", "de" => "DE"))
+    assert_equal('azc', S('abc').sub(/b/, "b" => "z"))
+    assert_equal('ac', S('abc').sub(/b/, {}))
+    assert_equal('a1c', S('abc').sub(/b/, "b" => 1))
+    assert_equal('aBc', S('abc').sub(/b/, Hash.new {|h, k| k.upcase }))
+    assert_equal('a[\&]c', S('abc').sub(/b/, "b" => '[\&]'))
+    assert_equal('aBcabc', S('abcabc').sub(/b/, Hash.new {|h, k| h[k] = k.upcase }))
+    assert_equal('aBcdef', S('abcdef').sub(/de|b/, "b" => "B", "de" => "DE"))
   end
 
   def test_gsub_hash
-    assert_equal('azc', 'abc'.gsub(/b/, "b" => "z"))
-     (... truncated)

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

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