1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/csv/test_csv.rb: close opened files for CSV::IOBuf explicitly. opened

file cannot be removed under win32 box.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nahi 2003-09-04 16:06:41 +00:00
parent e168b64b03
commit 822a72b8ee
2 changed files with 182 additions and 147 deletions

View file

@ -1,3 +1,8 @@
Wed Sep 5 01:03:59 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* test/csv/test_csv.rb: close opened files for CSV::IOBuf explicitly.
opened file cannot be removed under win32 box.
Thu Sep 4 23:59:40 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (tokadd_string): newlines have no special meanings in

View file

@ -2,7 +2,7 @@ require 'test/unit'
require 'tempfile'
require 'fileutils'
require 'csv'
require '../lib/csv'
class CSV
class StreamBuf
@ -381,7 +381,8 @@ public
reader = CSV::Reader.create("abc")
assert_instance_of(CSV::StringReader, reader, "With a String")
reader = CSV::Reader.create(File.open(@infile, "rb"))
file = File.open(@infile, "rb")
reader = CSV::Reader.create(file)
assert_instance_of(CSV::IOReader, reader, 'With an IO')
obj = Object.new
@ -398,6 +399,7 @@ public
# fors other tests.
reader = CSV::Reader.create(Tempfile.new("in.csv"))
assert_instance_of(CSV::IOReader, reader, "With an pseudo IO.")
file.close
end
def test_Reader_s_parse
@ -521,6 +523,7 @@ public
writer = CSV::BasicWriter.create(f)
writer.close
assert(!f.closed?)
f.close
f = File.open(@outfile, "w")
writer = CSV::BasicWriter.create(f)
@ -1093,10 +1096,12 @@ public
assert_equal([["foo"], ["bar"]], rows)
rows = []
CSV::Reader.parse(File.open(@bomfile).read) do |row|
file = File.open(@bomfile)
CSV::Reader.parse(file.read) do |row|
rows << row.to_a
end
assert_equal([["foo"], ["bar"]], rows)
file.close
end
@ -1122,7 +1127,15 @@ public
File.open(@outfile, "wb") do |f|
f << (InputStreamPattern * m)[0, size]
end
CSV::IOBuf.new(File.open(@outfile, "rb"))
file = File.open(@outfile, "rb")
buf = CSV::IOBuf.new(file)
if block_given?
yield(buf)
file.close
nil
else
buf
end
end
def setBufSize(size)
@ -1227,7 +1240,7 @@ public
end
def test_StreamBuf_AREF # '[idx]'
s = setupInputStream(22, 1024)
setupInputStream(22, 1024) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expChar(idx), s[idx], idx.to_s)
end
@ -1235,24 +1248,27 @@ public
assert_equal(nil, s[idx], idx.to_s)
end
assert_equal(nil, s[-1])
end
s = setupInputStream(22, 1)
setupInputStream(22, 1) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expChar(idx), s[idx], idx.to_s)
end
[22, 23].each do |idx|
assert_equal(nil, s[idx], idx.to_s)
end
end
s = setupInputStream(1024, 1)
setupInputStream(1024, 1) do |s|
[1023, 0].each do |idx|
assert_equal(expChar(idx), s[idx], idx.to_s)
end
[1024, 1025].each do |idx|
assert_equal(nil, s[idx], idx.to_s)
end
end
s = setupInputStream(1, 1)
setupInputStream(1, 1) do |s|
[0].each do |idx|
assert_equal(expChar(idx), s[idx], idx.to_s)
end
@ -1260,41 +1276,46 @@ public
assert_equal(nil, s[idx], idx.to_s)
end
end
end
def test_StreamBuf_AREF_n # '[idx, n]'
# At first, check ruby's behaviour.
assert_equal("", "abc"[3, 1])
assert_equal(nil, "abc"[4, 1])
s = setupInputStream(22, 1024)
setupInputStream(22, 1024) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expStr(idx, 1), s[idx, 1], idx.to_s)
end
assert_equal("", s[22, 1])
assert_equal(nil, s[23, 1])
end
s = setupInputStream(22, 1)
setupInputStream(22, 1) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expStr(idx, 1), s[idx, 1], idx.to_s)
end
assert_equal("", s[22, 1])
assert_equal(nil, s[23, 1])
end
s = setupInputStream(1024, 1)
setupInputStream(1024, 1) do |s|
[1023, 0].each do |idx|
assert_equal(expStr(idx, 1), s[idx, 1], idx.to_s)
end
assert_equal("", s[1024, 1])
assert_equal(nil, s[1025, 1])
end
s = setupInputStream(1, 1)
setupInputStream(1, 1) do |s|
[0].each do |idx|
assert_equal(expStr(idx, 1), s[idx, 1], idx.to_s)
end
assert_equal("", s[1, 1])
assert_equal(nil, s[2, 1])
end
s = setupInputStream(22, 11)
setupInputStream(22, 11) do |s|
[0, 1, 10, 11, 20].each do |idx|
assert_equal(expStr(idx, 2), s[idx, 2], idx.to_s)
end
@ -1312,9 +1333,10 @@ public
assert_equal(nil, s[-1, 10])
assert_equal(nil, s[-1, -1])
end
end
def test_StreamBuf_get
s = setupInputStream(22, 1024)
setupInputStream(22, 1024) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expChar(idx), s.get(idx), idx.to_s)
end
@ -1323,9 +1345,10 @@ public
end
assert_equal(nil, s.get(-1))
end
end
def test_StreamBuf_get_n
s = setupInputStream(22, 1024)
setupInputStream(22, 1024) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expStr(idx, 1), s.get(idx, 1), idx.to_s)
end
@ -1335,9 +1358,10 @@ public
assert_equal(nil, s.get(-1, 1))
assert_equal(nil, s.get(-1, -1))
end
end
def test_StreamBuf_drop
s = setupInputStream(22, 1024)
setupInputStream(22, 1024) do |s|
assert_equal(expChar(0), s[0])
assert_equal(expChar(21), s[21])
assert_equal(nil, s[22])
@ -1359,8 +1383,9 @@ public
assert_equal(1, dropped)
assert_equal(expChar(2), s[0])
assert_equal(expChar(3), s[1])
end
s = setupInputStream(4, 2)
setupInputStream(4, 2) do |s|
dropped = s.drop(2)
assert_equal(2, dropped)
assert_equal(expChar(2), s[0])
@ -1377,8 +1402,9 @@ public
assert_equal(0, dropped)
assert_equal(nil, s[0])
assert_equal(nil, s[1])
end
s = setupInputStream(6, 3)
setupInputStream(6, 3) do |s|
dropped = s.drop(2)
assert_equal(2, dropped)
dropped = s.drop(2)
@ -1390,9 +1416,10 @@ public
assert_equal(nil, s[0])
assert_equal(nil, s[1])
end
end
def test_StreamBuf_is_eos?
s = setupInputStream(3, 1024)
setupInputStream(3, 1024) do |s|
assert(!s.is_eos?)
s.drop(1)
assert(!s.is_eos?)
@ -1402,8 +1429,9 @@ public
assert(s.is_eos?)
s.drop(1)
assert(s.is_eos?)
end
s = setupInputStream(3, 2)
setupInputStream(3, 2) do |s|
assert(!s.is_eos?)
s.drop(1)
assert(!s.is_eos?)
@ -1414,6 +1442,7 @@ public
s.drop(1)
assert(s.is_eos?)
end
end
def test_StreamBuf_s_new
# NotImplementedError should be raised from StreamBuf#read.
@ -1431,6 +1460,7 @@ public
iobuf = CSV::IOBuf.new(f)
iobuf.close
assert(true) # iobuf.close does not raise any exception.
f.close
end
def test_IOBuf_s_new