From 5b98b2ce39ed979aec614365a2dc3e1c30052bca Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 20 Dec 2020 02:16:31 +0900 Subject: win32: Use UTF-8 as filesystem encoding [Feature #12654] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Dāvis Mosāns --- test/ruby/test_dir_m17n.rb | 53 ++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) (limited to 'test/ruby/test_dir_m17n.rb') diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb index c2c0c4999e..67bad8a514 100644 --- a/test/ruby/test_dir_m17n.rb +++ b/test/ruby/test_dir_m17n.rb @@ -17,27 +17,19 @@ class TestDir_M17N < Test::Unit::TestCase assert_separately(["-E#{encoding}"], <<-EOS, :chdir=>dir) filename = #{code}.chr('UTF-8').force_encoding("#{encoding}") File.open(filename, "w") {} - opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM - ents = Dir.entries(".", **(opts||{})) + ents = Dir.entries(".") + if /mswin|mingw/ =~ RUBY_PLATFORM + filename = filename.encode("UTF-8") + end assert_include(ents, filename) EOS return if /cygwin/ =~ RUBY_PLATFORM assert_separately(%w[-EASCII-8BIT], <<-EOS, :chdir=>dir) filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT") - opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM - ents = Dir.entries(".", **(opts||{})) - expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?" - expected_filename = expected_filename.force_encoding("ASCII-8BIT") + ents = Dir.entries(".") if /mswin|mingw/ =~ RUBY_PLATFORM - case - when ents.include?(filename) - when ents.include?(expected_filename) - filename = expected_filename - else - ents = Dir.entries(".", :encoding => Encoding.find("filesystem")) - filename = expected_filename - end + filename.force_encoding("UTF-8") end assert_include(ents, filename) EOS @@ -199,27 +191,23 @@ class TestDir_M17N < Test::Unit::TestCase assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d) filename = "\xA4\xA2".force_encoding("euc-jp") File.open(filename, "w") {} - opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM - ents = Dir.entries(".", **(opts||{})) + ents = Dir.entries(".") if /darwin/ =~ RUBY_PLATFORM filename = filename.encode("utf-8").force_encoding("euc-jp") + elsif /mswin|mingw/ =~ RUBY_PLATFORM + filename = filename.encode("utf-8") end assert_include(ents, filename) EOS assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d) filename = "\xA4\xA2".force_encoding('ASCII-8BIT') - win_expected_filename = filename.encode(Encoding.find("filesystem"), "euc-jp") rescue "?" - opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM - ents = Dir.entries(".", **(opts||{})) + ents = Dir.entries(".") unless ents.include?(filename) case RUBY_PLATFORM when /darwin/ filename = filename.encode("utf-8", "euc-jp").b when /mswin|mingw/ - if ents.include?(win_expected_filename.b) - ents = Dir.entries(".", :encoding => Encoding.find("filesystem")) - filename = win_expected_filename - end + filename = filename.encode("utf-8", "euc-jp") end end assert_include(ents, filename) @@ -414,13 +402,8 @@ class TestDir_M17N < Test::Unit::TestCase orig.each {|n| open(n, "w") {}} enc = Encoding.find("filesystem") enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII - if /mswin|mingw/ =~ RUBY_PLATFORM - opts = {:encoding => enc} - orig.map! {|o| o.encode("filesystem") rescue o.tr("^a-z", "?")} - else - orig.each {|o| o.force_encoding(enc) } - end - ents = Dir.entries(".", **(opts||{})).reject {|n| /\A\./ =~ n} + orig.each {|o| o.force_encoding(enc) } + ents = Dir.entries(".").reject {|n| /\A\./ =~ n} ents.sort! PP.assert_equal(orig, ents, bug7267) } @@ -431,13 +414,9 @@ class TestDir_M17N < Test::Unit::TestCase expected = [] results = [] orig.each {|o| - if /mswin|mingw/ =~ RUBY_PLATFORM - n = (o.encode("filesystem") rescue next) - else - enc = Encoding.find("filesystem") - enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII - n = o.dup.force_encoding(enc) - end + enc = Encoding.find("filesystem") + enc = Encoding::ASCII_8BIT if enc == Encoding::US_ASCII + n = o.dup.force_encoding(enc) expected << n with_tmpdir { Dir.mkdir(o) -- cgit v1.2.3