diff options
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r-- | test/ruby/test_io.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 5fc3b133dd..6ea128a880 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1512,4 +1512,34 @@ End t.close assert_raise(IOError) {t.binmode} end + + def test_s_write + t = Tempfile.new("foo") + path = t.path + t.close(false) + File.write(path, "foo\nbar\nbaz") + assert("foo\nbar\nbaz", File.read(path)) + File.write(path, "FOO", 0) + assert("FOO\nbar\nbaz", File.read(path)) + File.write(path, "BAR") + assert("BAR", File.read(path)) + File.write(path, "\u{3042}", mode: "w", encoding: "EUC-JP") + assert("\u{3042}".encode("EUC-JP"), File.read(path, encoding: "EUC-JP")) + t.unlink + end + + def test_s_binwrite + t = Tempfile.new("foo") + path = t.path + t.close(false) + File.binwrite(path, "foo\nbar\nbaz") + assert("foo\nbar\nbaz", File.read(path)) + File.binwrite(path, "FOO", 0) + assert("FOO\nbar\nbaz", File.read(path)) + File.binwrite(path, "BAR") + assert("BAR", File.read(path)) + File.binwrite(path, "\u{3042}") + assert("\u{3042}", File.read(path, encoding: "EUC-JP")) + t.unlink + end end |