diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-04 13:48:20 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-04 13:48:20 +0000 |
commit | ae2065a285b8ba32e7323ecf5875100ba546c2d9 (patch) | |
tree | 42f9a22ed3e2f92fb63378f196c4c5b2ef731cc1 /test | |
parent | 323e4f1cf06b70216b529013817010bfa666e99a (diff) | |
download | ruby-ae2065a285b8ba32e7323ecf5875100ba546c2d9.tar.gz |
* io.c (io_s_write, io_s_binwrite): add File#write and #binwrite.
[ruby-core:21701]
* test/ruby/test_io.rb: add tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-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 |