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

ruby-changes:40992

From: knu <ko1@a...>
Date: Sun, 13 Dec 2015 14:22:48 +0900 (JST)
Subject: [ruby-changes:40992] knu:r53071 (trunk): * test/test_shellwords.rb (TestShellwords): Add many more tests

knu	2015-12-13 14:22:22 +0900 (Sun, 13 Dec 2015)

  New Revision: 53071

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

  Log:
    * test/test_shellwords.rb (TestShellwords): Add many more tests
      for handling whitespace characters and frozenness.

  Modified files:
    trunk/ChangeLog
    trunk/test/test_shellwords.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53070)
+++ ChangeLog	(revision 53071)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Dec 13 14:17:19 2015  Akinori MUSHA  <knu@i...>
+
+	* test/test_shellwords.rb (TestShellwords): Add many more tests
+	  for handling whitespace characters and frozenness.
+
 Sun Dec 13 14:16:09 2015  Akinori MUSHA  <knu@i...>
 
 	* lib/shellwords.rb (Shellwords#shellsplit): Document that this
Index: test/test_shellwords.rb
===================================================================
--- test/test_shellwords.rb	(revision 53070)
+++ test/test_shellwords.rb	(revision 53071)
@@ -50,15 +50,58 @@ class TestShellwords < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/test_shellwords.rb#L50
   def test_stringification
     three = shellescape(3)
     assert_equal '3', three
-    assert_not_predicate three, :frozen?
-
-    empty = shellescape('')
-    assert_equal "''", empty
-    assert_not_predicate empty, :frozen?
 
     joined = ['ps', '-p', $$].shelljoin
     assert_equal "ps -p #{$$}", joined
-    assert_not_predicate joined, :frozen?
+  end
+
+  def test_whitespace
+    empty = ''
+    space = " "
+    newline = "\n"
+    tab = "\t"
+
+    tokens = [
+      empty,
+      space,
+      space * 2,
+      newline,
+      newline * 2,
+      tab,
+      tab * 2,
+      empty,
+      space + newline + tab,
+      empty
+    ]
+
+    tokens.each { |token|
+      assert_equal [token], shellescape(token).shellsplit
+    }
+
+
+    assert_equal tokens, shelljoin(tokens).shellsplit
+  end
+
+  def test_frozenness
+    [
+      shellescape(String.new),
+      shellescape(String.new('foo')),
+      shellescape(''.freeze),
+      shellescape("\n".freeze),
+      shellescape('foo'.freeze),
+      shelljoin(['ps'.freeze, 'ax'.freeze]),
+    ].each { |object|
+      assert_not_predicate object, :frozen?
+    }
+
+    [
+      shellsplit('ps'),
+      shellsplit('ps ax'),
+    ].each { |array|
+      array.each { |arg|
+        assert_not_predicate arg, :frozen?, array.inspect
+      }
+    }
   end
 
   def test_multibyte_characters

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

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