From 1701ddea73cf482289361c7559ad42e2694f65f1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 7 Nov 2024 19:33:41 +0900 Subject: [Bug #20802] Copy encodings at reopen as well --- test/ruby/test_io.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index a623fd1d15..5d4ede1e4f 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2655,6 +2655,17 @@ class TestIO < Test::Unit::TestCase } end + def test_reopen_binmode + f1 = File.open(__FILE__) + f2 = File.open(__FILE__) + f1.binmode + f1.reopen(f2) + assert_not_operator(f1, :binmode?) + ensure + f2.close + f1.close + end + def make_tempfile_for_encoding t = make_tempfile open(t.path, "rb+:utf-8") {|f| f.puts "\u7d05\u7389bar\n"} @@ -2685,6 +2696,16 @@ class TestIO < Test::Unit::TestCase } end + def test_reopen_encoding_from_io + f1 = File.open(__FILE__, "rb:UTF-16LE") + f2 = File.open(__FILE__, "r:UTF-8") + f1.reopen(f2) + assert_equal(Encoding::UTF_8, f1.external_encoding) + ensure + f2.close + f1.close + end + def test_reopen_opt_encoding feature7103 = '[ruby-core:47806]' make_tempfile_for_encoding {|t| -- cgit v1.2.3