Skip to content

Commit a8a188e

Browse files
committed
[ruby/pathname] Add more tests for Pathname#initialize
ruby/pathname@a2edd25bc1
1 parent 806f2d3 commit a8a188e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/pathname/test_pathname.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ def test_initialize
485485
p2 = Pathname.new(p1)
486486
assert_equal(p1, p2)
487487

488+
obj = Object.new
489+
assert_raise(TypeError) { Pathname.new(obj) }
490+
491+
obj = Object.new
492+
def obj.to_path; "a/path"; end
493+
assert_equal("a/path", Pathname.new(obj).to_s)
494+
488495
obj = Object.new
489496
def obj.to_str; "a/b"; end
490497
assert_equal("a/b", Pathname.new(obj).to_s)
@@ -494,6 +501,10 @@ def test_initialize_nul
494501
assert_raise(ArgumentError) { Pathname.new("a\0") }
495502
end
496503

504+
def test_initialize_encoding
505+
assert_raise(Encoding::CompatibilityError) { Pathname.new("a".encode(Encoding::UTF_32BE)) }
506+
end
507+
497508
def test_global_constructor
498509
p = Pathname.new('a')
499510
assert_equal(p, Pathname('a'))

0 commit comments

Comments
 (0)