Skip to content

Commit a2edd25

Browse files
committed
Add more tests for Pathname#initialize
1 parent f2bd3d6 commit a2edd25

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)
@@ -495,6 +502,10 @@ def test_initialize_nul
495502
assert_raise(ArgumentError) { Pathname.new("a\0") }
496503
end
497504

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

0 commit comments

Comments
 (0)