diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-16 13:45:59 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-16 13:45:59 +0000 |
commit | 1d6acc66c52fb7ba83120c763d222227f47dc38c (patch) | |
tree | 452cd1947e70f68fc9daae2c0fc3e5caaa53692f /test/ruby/test_dir_m17n.rb | |
parent | e2277a5eaf663b0d1eb7d4985ffca1fdb00be0d1 (diff) | |
download | ruby-1d6acc66c52fb7ba83120c763d222227f47dc38c.tar.gz ruby-1d6acc66c52fb7ba83120c763d222227f47dc38c.tar.xz ruby-1d6acc66c52fb7ba83120c763d222227f47dc38c.zip |
add tests.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_dir_m17n.rb')
-rw-r--r-- | test/ruby/test_dir_m17n.rb | 105 |
1 files changed, 88 insertions, 17 deletions
diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb index 209189ab4..44a421874 100644 --- a/test/ruby/test_dir_m17n.rb +++ b/test/ruby/test_dir_m17n.rb @@ -11,6 +11,93 @@ class TestDir_M17N < Test::Unit::TestCase } end + ## UTF-8 default_external, no default_internal + + def test_filename_extutf8 + with_tmpdir {|d| + assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) + filename = "\u3042" + File.open(filename, "w") {} + ents = Dir.entries(".") + exit ents.include?(filename) + EOS + } + end + + def test_filename_extutf8_invalid + with_tmpdir {|d| + assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d) + filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8 + File.open(filename, "w") {} + ents = Dir.entries(".") + exit ents.include?(filename) + EOS + assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) + filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8 + File.open(filename, "w") {} + ents = Dir.entries(".") + exit ents.include?(filename) + EOS + } + end + + ## UTF-8 default_external, EUC-JP default_internal + + def test_filename_extutf8_inteucjp_representable + with_tmpdir {|d| + assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) + filename = "\u3042" + File.open(filename, "w") {} + ents = Dir.entries(".") + exit ents.include?(filename) + EOS + assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) + filename = "\xA4\xA2".force_encoding("euc-jp") + ents = Dir.entries(".") + exit ents.include?(filename) + EOS + assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) + filename = "\xA4\xA2".force_encoding("euc-jp") + begin + open(filename) {} + exit true + rescue Errno::ENOENT + exit false + end + EOS + } + end + + def test_filename_extutf8_inteucjp_unrepresentable + with_tmpdir {|d| + assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) + filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP + filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP + File.open(filename1, "w") {} + File.open(filename2, "w") {} + ents = Dir.entries(".") + exit ents.include?(filename1) && ents.include?(filename2) + EOS + assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) + filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP + filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP + ents = Dir.entries(".") + exit ents.include?(filename1) && ents.include?(filename2) + EOS + assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) + filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP + filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP + filename3 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP + s1 = File.stat(filename1) rescue nil + s2 = File.stat(filename2) rescue nil + s3 = File.stat(filename3) rescue nil + exit (s1 && s2 && s3) ? true : false + EOS + } + end + + ## others + def test_filename_bytes_euc_jp with_tmpdir {|d| assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d) @@ -39,7 +126,7 @@ class TestDir_M17N < Test::Unit::TestCase } end - def test_filename_utf_8 + def test_filename_utf8_raw_name with_tmpdir {|d| assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) filename = "\u3042".force_encoding("utf-8") @@ -71,21 +158,5 @@ class TestDir_M17N < Test::Unit::TestCase } end - def test_filename_ext_utf_8_and_int_euc_jp - with_tmpdir {|d| - assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) - filename = "\u3042" - File.open(filename, "w") {} - ents = Dir.entries(".") - exit ents.include?(filename) - EOS - assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) - filename = "\xA4\xA2".force_encoding("euc-jp") - ents = Dir.entries(".") - exit ents.include?(filename) - EOS - } - end - end |