Last active
December 9, 2017 15:54
-
-
Save tadd/634b6e4b09b6dfe7c8b97bca138d31ec to your computer and use it in GitHub Desktop.
Tests for String#undump (based on the testcases in `string_undump` gem)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test-unit' | |
class TestUndump < Test::Unit::TestCase | |
def test_undump | |
assert_equal('foo', '"foo"'.undump) | |
assert_equal('foo#$bar#@baz#{quxx}', '"foo\#$bar\#@baz\#{quxx}"'.undump) | |
assert_equal('\\', '"\\\\"'.undump) | |
assert_equal(%(\\"), '"\\\\\""'.undump) | |
assert_equal("\n", '"\n"'.undump) | |
assert_equal(%(\\"\n), '"\\\\\"\n"'.undump) | |
assert_equal('すごーい', '"\u3059\u3054\u30FC\u3044"'.undump) | |
assert_equal('\\a\\', '"\\\\a\\\\"'.undump) | |
assert_equal("\nn", '"\nn"'.undump) | |
assert_equal("\u30593059", '"\u30593059"'.undump) | |
assert_equal('たのしー', '"\xE3\x81\x9F\xE3\x81\xAE\xE3\x81\x97\xE3\x83\xBC"'.undump) | |
assert_equal('🐾', '"\u{1F43E}"'.undump) | |
assert_equal(%(すごーい\\🐾たのしー\n\#{foo}), | |
('"\u3059\u3054\u30FC\u3044\\\\\u{1F43E}' + | |
'\xE3\x81\x9F\xE3\x81\xAE\xE3\x81\x97\xE3\x83\xBC\\n\#{foo}"').undump) | |
end | |
def test_undump_force_encoding | |
assert_equal("abc".encode(Encoding::UTF_16LE), | |
'"a\x00b\x00c\x00".force_encoding("UTF-16LE")'.undump) | |
end | |
def test_undump_error | |
assert_raise(ArgumentError.new('invalid Unicode escape')) {'"\u"'.undump} | |
assert_raise(ArgumentError.new('unterminated Unicode escape')) {'"\u{"'.undump} | |
assert_raise(ArgumentError.new('unterminated Unicode escape')) {'"\u{3042"'.undump} | |
assert_raise(ArgumentError.new('invalid hex escape')) {'"\x"'.undump} | |
assert_equal('#', '"\#"'.undump) | |
assert_raise(ArgumentError.new('invalid escape')) {'"\\"'.undump} | |
assert_raise(ArgumentError.new('unknown encoding name - UNKNOWN')) { | |
'"".force_encoding("UNKNOWN")'.undump | |
} | |
end | |
def test_undump_taintedness | |
assert_true('""'.taint.undump.tainted?) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: euc-jp | |
# test for multibyte and non-Unicode string | |
require 'test-unit' | |
class TestUndumpEucJp < Test::Unit::TestCase | |
def test_undump | |
assert_equal('すごーい', '\xA4\xB9\xA4\xB4\xA1\xBC\xA4\xA4'.undump) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment