summaryrefslogtreecommitdiff
path: root/spec/ruby/core/file
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2026-01-28 22:30:21 +0100
committerBenoit Daloze <eregontp@gmail.com>2026-01-28 23:01:22 +0100
commitdbd2ff7adca9b49e4bfa7bc3ec8b83bd437f8cb7 (patch)
tree5f4f1609d2015fde92c25b175b84078dfcf1c92f /spec/ruby/core/file
parenta8b877a843643fbdccd1a42efaf94ad27705dd55 (diff)
Update to ruby/spec@83e26c9
Diffstat (limited to 'spec/ruby/core/file')
-rw-r--r--spec/ruby/core/file/basename_spec.rb6
-rw-r--r--spec/ruby/core/file/dirname_spec.rb33
2 files changed, 34 insertions, 5 deletions
diff --git a/spec/ruby/core/file/basename_spec.rb b/spec/ruby/core/file/basename_spec.rb
index 87695ab97b..66a5b56ed9 100644
--- a/spec/ruby/core/file/basename_spec.rb
+++ b/spec/ruby/core/file/basename_spec.rb
@@ -162,11 +162,7 @@ describe "File.basename" do
it "rejects strings encoded with non ASCII-compatible encodings" do
Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc|
- begin
- path = "/foo/bar".encode(enc)
- rescue Encoding::ConverterNotFoundError
- next
- end
+ path = "/foo/bar".encode(enc)
-> {
File.basename(path)
diff --git a/spec/ruby/core/file/dirname_spec.rb b/spec/ruby/core/file/dirname_spec.rb
index 8e6016ce6f..1b006af783 100644
--- a/spec/ruby/core/file/dirname_spec.rb
+++ b/spec/ruby/core/file/dirname_spec.rb
@@ -78,7 +78,33 @@ describe "File.dirname" do
File.dirname("foo/../").should == "foo"
end
+ it "rejects strings encoded with non ASCII-compatible encodings" do
+ Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc|
+ path = "/foo/bar".encode(enc)
+ -> {
+ File.dirname(path)
+ }.should raise_error(Encoding::CompatibilityError)
+ end
+ end
+
+ it "works with all ASCII-compatible encodings" do
+ Encoding.list.select(&:ascii_compatible?).each do |enc|
+ File.dirname("/foo/bar".encode(enc)).should == "/foo".encode(enc)
+ end
+ end
+
+ it "handles Shift JIS 0x5C (\\) as second byte of a multi-byte sequence" do
+ # dir/fileソname.txt
+ path = "dir/file\x83\x5cname.txt".b.force_encoding(Encoding::SHIFT_JIS)
+ path.valid_encoding?.should be_true
+ File.dirname(path).should == "dir"
+ end
+
platform_is_not :windows do
+ it "ignores repeated leading / (edge cases on non-windows)" do
+ File.dirname("/////foo/bar/").should == "/foo"
+ end
+
it "returns all the components of filename except the last one (edge cases on non-windows)" do
File.dirname('/////').should == '/'
File.dirname("//foo//").should == "/"
@@ -94,6 +120,13 @@ describe "File.dirname" do
File.dirname("//foo//").should == "//foo"
File.dirname('/////').should == '//'
end
+
+ it "handles Shift JIS 0x5C (\\) as second byte of a multi-byte sequence (windows)" do
+ # dir\fileソname.txt
+ path = "dir\\file\x83\x5cname.txt".b.force_encoding(Encoding::SHIFT_JIS)
+ path.valid_encoding?.should be_true
+ File.dirname(path).should == "dir"
+ end
end
it "accepts an object that has a #to_path method" do