diff options
author | nicholas a. evans <nicholas.evans@gmail.com> | 2021-05-04 14:52:38 -0400 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-05-06 15:20:34 +0900 |
commit | 337c0e312bc4e8a13ee90b9d7b102664661cf9a7 (patch) | |
tree | 09dfc8084af66b3f683f27741aba92d4e30ef784 /test/net | |
parent | 4dc7b82427bafab4878f120931ef5b0988778b75 (diff) | |
download | ruby-337c0e312bc4e8a13ee90b9d7b102664661cf9a7.tar.gz |
[ruby/net-imap] Move UTF7 & datetime formatting to net/imap/data_encoding
Partially implements #10.
https://github.com/ruby/net-imap/commit/0d43c5e856
Diffstat (limited to 'test/net')
-rw-r--r-- | test/net/imap/test_imap.rb | 38 | ||||
-rw-r--r-- | test/net/imap/test_imap_data_encoding.rb | 46 |
2 files changed, 46 insertions, 38 deletions
diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb index 49e146718e..46008b0531 100644 --- a/test/net/imap/test_imap.rb +++ b/test/net/imap/test_imap.rb @@ -22,44 +22,6 @@ class IMAPTest < Test::Unit::TestCase Socket.do_not_reverse_lookup = @do_not_reverse_lookup end - def test_encode_utf7 - assert_equal("foo", Net::IMAP.encode_utf7("foo")) - assert_equal("&-", Net::IMAP.encode_utf7("&")) - - utf8 = "\357\274\241\357\274\242\357\274\243".dup.force_encoding("UTF-8") - s = Net::IMAP.encode_utf7(utf8) - assert_equal("&,yH,Iv8j-", s) - s = Net::IMAP.encode_utf7("foo&#{utf8}-bar".encode("EUC-JP")) - assert_equal("foo&-&,yH,Iv8j--bar", s) - - utf8 = "\343\201\202&".dup.force_encoding("UTF-8") - s = Net::IMAP.encode_utf7(utf8) - assert_equal("&MEI-&-", s) - s = Net::IMAP.encode_utf7(utf8.encode("EUC-JP")) - assert_equal("&MEI-&-", s) - end - - def test_decode_utf7 - assert_equal("&", Net::IMAP.decode_utf7("&-")) - assert_equal("&-", Net::IMAP.decode_utf7("&--")) - - s = Net::IMAP.decode_utf7("&,yH,Iv8j-") - utf8 = "\357\274\241\357\274\242\357\274\243".dup.force_encoding("UTF-8") - assert_equal(utf8, s) - end - - def test_format_date - time = Time.mktime(2009, 7, 24) - s = Net::IMAP.format_date(time) - assert_equal("24-Jul-2009", s) - end - - def test_format_datetime - time = Time.mktime(2009, 7, 24, 1, 23, 45) - s = Net::IMAP.format_datetime(time) - assert_match(/\A24-Jul-2009 01:23 [+\-]\d{4}\z/, s) - end - if defined?(OpenSSL::SSL::SSLError) def test_imaps_unknown_ca assert_raise(OpenSSL::SSL::SSLError) do diff --git a/test/net/imap/test_imap_data_encoding.rb b/test/net/imap/test_imap_data_encoding.rb new file mode 100644 index 0000000000..2ca1c1822b --- /dev/null +++ b/test/net/imap/test_imap_data_encoding.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require "net/imap" +require "test/unit" + +class IMAPDataEncodingTest < Test::Unit::TestCase + + def test_encode_utf7 + assert_equal("foo", Net::IMAP.encode_utf7("foo")) + assert_equal("&-", Net::IMAP.encode_utf7("&")) + + utf8 = "\357\274\241\357\274\242\357\274\243".dup.force_encoding("UTF-8") + s = Net::IMAP.encode_utf7(utf8) + assert_equal("&,yH,Iv8j-", s) + s = Net::IMAP.encode_utf7("foo&#{utf8}-bar".encode("EUC-JP")) + assert_equal("foo&-&,yH,Iv8j--bar", s) + + utf8 = "\343\201\202&".dup.force_encoding("UTF-8") + s = Net::IMAP.encode_utf7(utf8) + assert_equal("&MEI-&-", s) + s = Net::IMAP.encode_utf7(utf8.encode("EUC-JP")) + assert_equal("&MEI-&-", s) + end + + def test_decode_utf7 + assert_equal("&", Net::IMAP.decode_utf7("&-")) + assert_equal("&-", Net::IMAP.decode_utf7("&--")) + + s = Net::IMAP.decode_utf7("&,yH,Iv8j-") + utf8 = "\357\274\241\357\274\242\357\274\243".dup.force_encoding("UTF-8") + assert_equal(utf8, s) + end + + def test_format_date + time = Time.mktime(2009, 7, 24) + s = Net::IMAP.format_date(time) + assert_equal("24-Jul-2009", s) + end + + def test_format_datetime + time = Time.mktime(2009, 7, 24, 1, 23, 45) + s = Net::IMAP.format_datetime(time) + assert_match(/\A24-Jul-2009 01:23 [+\-]\d{4}\z/, s) + end + +end |