diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-13 05:22:22 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-13 05:22:22 +0000 |
commit | f7ca4f30c401df017fc80db94daebd49a0e90f39 (patch) | |
tree | 97d0ecbe07b8b3534cf83e71c57eba4abeb9396c /test/test_shellwords.rb | |
parent | 273d5004bec3138b6ca7fd17f4f12e3c2f2abf2f (diff) |
* test/test_shellwords.rb (TestShellwords): Add many more tests
for handling whitespace characters and frozenness.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_shellwords.rb')
-rw-r--r-- | test/test_shellwords.rb | 55 |
1 files changed, 49 insertions, 6 deletions
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 |