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

ruby-changes:45742

From: nobu <ko1@a...>
Date: Thu, 9 Mar 2017 10:55:48 +0900 (JST)
Subject: [ruby-changes:45742] nobu:r57815 (trunk): test_utf16.rb: refine valid_encoding tests

nobu	2017-03-09 10:55:43 +0900 (Thu, 09 Mar 2017)

  New Revision: 57815

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57815

  Log:
    test_utf16.rb: refine valid_encoding tests
    
    * test/ruby/enc/test_utf16.rb (test_utf16be_valid_encoding):
      assert all data and use assert_predicate.
    
    * test/ruby/enc/test_utf16.rb (test_utf16le_valid_encoding):
      ditto.

  Modified files:
    trunk/test/ruby/enc/test_utf16.rb
Index: test/ruby/enc/test_utf16.rb
===================================================================
--- test/ruby/enc/test_utf16.rb	(revision 57814)
+++ test/ruby/enc/test_utf16.rb	(revision 57815)
@@ -56,59 +56,71 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/enc/test_utf16.rb#L56
   # tests start
 
   def test_utf16be_valid_encoding
-    [
-      "\x00\x00",
-      "\xd7\xff",
-      "\xd8\x00\xdc\x00",
-      "\xdb\xff\xdf\xff",
-      "\xe0\x00",
-      "\xff\xff",
-    ].each {|s|
-      s.force_encoding("utf-16be")
-      assert_equal(true, s.valid_encoding?, "#{encdump s}.valid_encoding?")
-    }
-    [
-      "\x00",
-      "\xd7",
-      "\xd8\x00",
-      "\xd8\x00\xd8\x00",
-      "\xdc\x00",
-      "\xdc\x00\xd8\x00",
-      "\xdc\x00\xdc\x00",
-      "\xe0",
-      "\xff",
-    ].each {|s|
-      s.force_encoding("utf-16be")
-      assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
-    }
+    all_assertions do |a|
+      [
+        "\x00\x00",
+        "\xd7\xff",
+        "\xd8\x00\xdc\x00",
+        "\xdb\xff\xdf\xff",
+        "\xe0\x00",
+        "\xff\xff",
+      ].each {|s|
+        s.force_encoding("utf-16be")
+        a.for(s) {
+          assert_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
+        }
+      }
+      [
+        "\x00",
+        "\xd7",
+        "\xd8\x00",
+        "\xd8\x00\xd8\x00",
+        "\xdc\x00",
+        "\xdc\x00\xd8\x00",
+        "\xdc\x00\xdc\x00",
+        "\xe0",
+        "\xff",
+      ].each {|s|
+        s.force_encoding("utf-16be")
+        a.for(s) {
+          assert_not_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
+        }
+      }
+    end
   end
 
   def test_utf16le_valid_encoding
-    [
-      "\x00\x00",
-      "\xff\xd7",
-      "\x00\xd8\x00\xdc",
-      "\xff\xdb\xff\xdf",
-      "\x00\xe0",
-      "\xff\xff",
-    ].each {|s|
-      s.force_encoding("utf-16le")
-      assert_equal(true, s.valid_encoding?, "#{encdump s}.valid_encoding?")
-    }
-    [
-      "\x00",
-      "\xd7",
-      "\x00\xd8",
-      "\x00\xd8\x00\xd8",
-      "\x00\xdc",
-      "\x00\xdc\x00\xd8",
-      "\x00\xdc\x00\xdc",
-      "\xe0",
-      "\xff",
-    ].each {|s|
-      s.force_encoding("utf-16le")
-      assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
-    }
+    all_assertions do |a|
+      [
+        "\x00\x00",
+        "\xff\xd7",
+        "\x00\xd8\x00\xdc",
+        "\xff\xdb\xff\xdf",
+        "\x00\xe0",
+        "\xff\xff",
+      ].each {|s|
+        s.force_encoding("utf-16le")
+        a.for(s) {
+          assert_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
+        }
+      }
+      [
+        "\x00",
+        "\xd7",
+        "\x00\xd8",
+        "\x00\xd8\x00\xd8",
+        "\x00\xdc",
+        "\x00\xdc\x00\xd8",
+        "\x00\xdc\x00\xdc",
+        "\xe0",
+        "\xff",
+      ].each {|s|
+        s.force_encoding("utf-16le")
+        a.for(s) {
+          assert_not_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
+        }
+      }
+    end
   end
 
   def test_strftime

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

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