summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-12-07 12:29:41 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2025-12-07 23:20:24 +0900
commita8a188e1fc8568185c2ca460b5a2e800e9cac4bd (patch)
treeb42371e405efb2128cc4ae323b77142f6072ef5a
parent806f2d3533ec5bbf6b4d598b36b1c9de7e786659 (diff)
[ruby/pathname] Add more tests for `Pathname#initialize`
https://github.com/ruby/pathname/commit/a2edd25bc1
-rw-r--r--test/pathname/test_pathname.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index e2d6a09fb2..10ab154220 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -486,6 +486,13 @@ class TestPathname < Test::Unit::TestCase
assert_equal(p1, p2)
obj = Object.new
+ assert_raise(TypeError) { Pathname.new(obj) }
+
+ obj = Object.new
+ def obj.to_path; "a/path"; end
+ assert_equal("a/path", Pathname.new(obj).to_s)
+
+ obj = Object.new
def obj.to_str; "a/b"; end
assert_equal("a/b", Pathname.new(obj).to_s)
end
@@ -494,6 +501,10 @@ class TestPathname < Test::Unit::TestCase
assert_raise(ArgumentError) { Pathname.new("a\0") }
end
+ def test_initialize_encoding
+ assert_raise(Encoding::CompatibilityError) { Pathname.new("a".encode(Encoding::UTF_32BE)) }
+ end
+
def test_global_constructor
p = Pathname.new('a')
assert_equal(p, Pathname('a'))