mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_io.rb (TestIO#test_s_{,bin}write): do not create a file
under /tmp. [Bug #4846] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4d85a0df20
commit
e301f4c18e
2 changed files with 55 additions and 52 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Jun 7 03:18:45 2011 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||
|
||||
* test/ruby/test_io.rb (TestIO#test_s_{,bin}write): do not create a
|
||||
file under /tmp. [Bug #4846]
|
||||
|
||||
Mon Jun 6 22:51:43 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
|
||||
|
||||
* cont.c: use #if FIBER_USE_NATIVE instead of #ifdef.
|
||||
|
|
|
@ -1866,60 +1866,58 @@ End
|
|||
end
|
||||
|
||||
def test_s_write
|
||||
t = Tempfile.new("foo")
|
||||
path = t.path
|
||||
t.close(false)
|
||||
File.write(path, "foo\nbar\nbaz")
|
||||
assert_equal("foo\nbar\nbaz", File.read(path))
|
||||
File.write(path, "FOO", 0)
|
||||
assert_equal("FOO\nbar\nbaz", File.read(path))
|
||||
File.write(path, "BAR")
|
||||
assert_equal("BAR", File.read(path))
|
||||
File.write(path, "\u{3042}", mode: "w", encoding: "EUC-JP")
|
||||
assert_equal("\u{3042}".encode("EUC-JP"), File.read(path, encoding: "EUC-JP"))
|
||||
File.delete t
|
||||
assert_equal(6, File.write(path,'string',2))
|
||||
File.delete t
|
||||
assert_raise(Errno::EINVAL) { File.write('/tmp/nonexisting','string',-2) }
|
||||
assert_equal(6, File.write(path, 'string'))
|
||||
assert_equal(3, File.write(path, 'sub', 1))
|
||||
assert_equal("ssubng", File.read(path))
|
||||
File.delete t
|
||||
assert_equal(3, File.write(path, "foo", encoding: "UTF-8"))
|
||||
File.delete t
|
||||
assert_equal(3, File.write(path, "foo", 0, encoding: "UTF-8"))
|
||||
assert_equal("foo", File.read(path))
|
||||
assert_equal(1, File.write(path, "f", 1, encoding: "UTF-8"))
|
||||
assert_equal("ffo", File.read(path))
|
||||
File.delete t
|
||||
assert_equal(1, File.write(path, "f", 1, encoding: "UTF-8"))
|
||||
assert_equal("\00f", File.read(path))
|
||||
assert_equal(1, File.write(path, "f", 0, encoding: "UTF-8"))
|
||||
assert_equal("ff", File.read(path))
|
||||
t.unlink
|
||||
mkcdtmpdir do
|
||||
path = "test_s_write"
|
||||
File.write(path, "foo\nbar\nbaz")
|
||||
assert_equal("foo\nbar\nbaz", File.read(path))
|
||||
File.write(path, "FOO", 0)
|
||||
assert_equal("FOO\nbar\nbaz", File.read(path))
|
||||
File.write(path, "BAR")
|
||||
assert_equal("BAR", File.read(path))
|
||||
File.write(path, "\u{3042}", mode: "w", encoding: "EUC-JP")
|
||||
assert_equal("\u{3042}".encode("EUC-JP"), File.read(path, encoding: "EUC-JP"))
|
||||
File.delete path
|
||||
assert_equal(6, File.write(path, 'string', 2))
|
||||
File.delete path
|
||||
assert_raise(Errno::EINVAL) { File.write('nonexisting','string', -2) }
|
||||
assert_equal(6, File.write(path, 'string'))
|
||||
assert_equal(3, File.write(path, 'sub', 1))
|
||||
assert_equal("ssubng", File.read(path))
|
||||
File.delete path
|
||||
assert_equal(3, File.write(path, "foo", encoding: "UTF-8"))
|
||||
File.delete path
|
||||
assert_equal(3, File.write(path, "foo", 0, encoding: "UTF-8"))
|
||||
assert_equal("foo", File.read(path))
|
||||
assert_equal(1, File.write(path, "f", 1, encoding: "UTF-8"))
|
||||
assert_equal("ffo", File.read(path))
|
||||
File.delete path
|
||||
assert_equal(1, File.write(path, "f", 1, encoding: "UTF-8"))
|
||||
assert_equal("\00f", File.read(path))
|
||||
assert_equal(1, File.write(path, "f", 0, encoding: "UTF-8"))
|
||||
assert_equal("ff", File.read(path))
|
||||
end
|
||||
end
|
||||
|
||||
def test_s_binwrite
|
||||
t = Tempfile.new("foo")
|
||||
path = t.path
|
||||
t.close(false)
|
||||
File.binwrite(path, "foo\nbar\nbaz")
|
||||
assert_equal("foo\nbar\nbaz", File.read(path))
|
||||
File.binwrite(path, "FOO", 0)
|
||||
assert_equal("FOO\nbar\nbaz", File.read(path))
|
||||
File.binwrite(path, "BAR")
|
||||
assert_equal("BAR", File.read(path))
|
||||
File.binwrite(path, "\u{3042}")
|
||||
assert_equal("\u{3042}".force_encoding("ASCII-8BIT"), File.binread(path))
|
||||
File.delete t
|
||||
assert_equal(6, File.binwrite(path,'string',2))
|
||||
File.delete t
|
||||
assert_equal(6, File.binwrite(path, 'string'))
|
||||
assert_equal(3, File.binwrite(path, 'sub', 1))
|
||||
assert_equal("ssubng", File.binread(path))
|
||||
assert_equal(6, File.size(path))
|
||||
assert_raise(Errno::EINVAL) { File.binwrite('/tmp/nonexisting','string',-2) }
|
||||
assert_nothing_raised(TypeError) { File.binwrite(path, "string", mode: "w", encoding: "EUC-JP") }
|
||||
t.unlink
|
||||
mkcdtmpdir do
|
||||
path = "test_s_binwrite"
|
||||
File.binwrite(path, "foo\nbar\nbaz")
|
||||
assert_equal("foo\nbar\nbaz", File.read(path))
|
||||
File.binwrite(path, "FOO", 0)
|
||||
assert_equal("FOO\nbar\nbaz", File.read(path))
|
||||
File.binwrite(path, "BAR")
|
||||
assert_equal("BAR", File.read(path))
|
||||
File.binwrite(path, "\u{3042}")
|
||||
assert_equal("\u{3042}".force_encoding("ASCII-8BIT"), File.binread(path))
|
||||
File.delete path
|
||||
assert_equal(6, File.binwrite(path, 'string', 2))
|
||||
File.delete path
|
||||
assert_equal(6, File.binwrite(path, 'string'))
|
||||
assert_equal(3, File.binwrite(path, 'sub', 1))
|
||||
assert_equal("ssubng", File.binread(path))
|
||||
assert_equal(6, File.size(path))
|
||||
assert_raise(Errno::EINVAL) { File.binwrite('nonexisting', 'string', -2) }
|
||||
assert_nothing_raised(TypeError) { File.binwrite(path, "string", mode: "w", encoding: "EUC-JP") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue