summaryrefslogtreecommitdiff
path: root/test/ruby/test_dir_m17n.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-20 02:16:31 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-20 18:34:04 +0900
commit5b98b2ce39ed979aec614365a2dc3e1c30052bca (patch)
tree975744f4a5cd9e523f8e319dd6d017c08580de21 /test/ruby/test_dir_m17n.rb
parentfeea436febb50eb4265bd985a550e384c606122c (diff)
win32: Use UTF-8 as filesystem encoding [Feature #12654]
Co-Authored-By: Dāvis Mosāns <davispuh@gmail.com>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3948
Diffstat (limited to 'test/ruby/test_dir_m17n.rb')
-rw-r--r--test/ruby/test_dir_m17n.rb53
1 files changed, 16 insertions, 37 deletions
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)