summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/test_shellwords.rb55
2 files changed, 54 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a66c0b21e..0aa067f28d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Dec 13 14:17:19 2015 Akinori MUSHA <knu@iDaemons.org>
+
+ * 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@iDaemons.org>
* lib/shellwords.rb (Shellwords#shellsplit): Document that this
diff --git a/test/test_shellwords.rb b/test/test_shellwords.rb
index 3ead5f7c49..c160ed9d1c 100644
--- a/test/test_shellwords.rb
+++ b/test/test_shellwords.rb
@@ -50,15 +50,58 @@ class TestShellwords < Test::Unit::TestCase
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