* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
require 'test/unit'
|
2003-09-03 08:45:36 -04:00
|
|
|
require 'tempfile'
|
2003-09-04 05:08:30 -04:00
|
|
|
require 'fileutils'
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2004-05-26 22:26:15 -04:00
|
|
|
require 'csv'
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
class CSV
|
|
|
|
class StreamBuf
|
|
|
|
# Let buffer work hard.
|
2003-09-04 05:08:30 -04:00
|
|
|
remove_const("BufSize")
|
2003-09-03 08:45:36 -04:00
|
|
|
BufSize = 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
module CSVTestSupport
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
def d(data)
|
|
|
|
data
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
2003-09-15 06:07:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class TestCSV < Test::Unit::TestCase
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
file = Tempfile.new("crlf")
|
|
|
|
file << "\n"
|
|
|
|
file.open
|
|
|
|
file.binmode
|
|
|
|
RSEP = file.read
|
|
|
|
file.close
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
include CSVTestSupport
|
|
|
|
|
|
|
|
class << self
|
|
|
|
include CSVTestSupport
|
|
|
|
end
|
|
|
|
|
|
|
|
@@simpleCSVData = {
|
|
|
|
[nil] => '',
|
|
|
|
[''] => '""',
|
|
|
|
[nil, nil] => ',',
|
|
|
|
[nil, nil, nil] => ',,',
|
|
|
|
['foo'] => 'foo',
|
|
|
|
[','] => '","',
|
|
|
|
[',', ','] => '",",","',
|
|
|
|
[';'] => ';',
|
|
|
|
[';', ';'] => ';,;',
|
|
|
|
["\"\r", "\"\r"] => "\"\"\"\r\",\"\"\"\r\"",
|
|
|
|
["\"\n", "\"\n"] => "\"\"\"\n\",\"\"\"\n\"",
|
|
|
|
["\t"] => "\t",
|
|
|
|
["\t", "\t"] => "\t,\t",
|
|
|
|
['foo', 'bar'] => 'foo,bar',
|
|
|
|
['foo', '"bar"', 'baz'] => 'foo,"""bar""",baz',
|
|
|
|
['foo', 'foo,bar', 'baz'] => 'foo,"foo,bar",baz',
|
|
|
|
['foo', '""', 'baz'] => 'foo,"""""",baz',
|
|
|
|
['foo', '', 'baz'] => 'foo,"",baz',
|
|
|
|
['foo', nil, 'baz'] => 'foo,,baz',
|
|
|
|
[nil, 'foo', 'bar'] => ',foo,bar',
|
|
|
|
['foo', 'bar', nil] => 'foo,bar,',
|
|
|
|
['foo', "\r", 'baz'] => "foo,\"\r\",baz",
|
|
|
|
['foo', "\n", 'baz'] => "foo,\"\n\",baz",
|
|
|
|
['foo', "\r\n\r", 'baz'] => "foo,\"\r\n\r\",baz",
|
|
|
|
['foo', "\r\n", 'baz'] => "foo,\"\r\n\",baz",
|
|
|
|
['foo', "\r.\n", 'baz'] => "foo,\"\r.\n\",baz",
|
|
|
|
['foo', "\r\n\n", 'baz'] => "foo,\"\r\n\n\",baz",
|
|
|
|
['foo', '"', 'baz'] => 'foo,"""",baz',
|
|
|
|
}
|
|
|
|
|
|
|
|
@@fullCSVData = {
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
[d(nil)] => '',
|
2003-09-15 06:07:42 -04:00
|
|
|
[d('')] => '""',
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
[d(nil), d(nil)] => ',',
|
|
|
|
[d(nil), d(nil), d(nil)] => ',,',
|
2003-09-15 06:07:42 -04:00
|
|
|
[d('foo')] => 'foo',
|
|
|
|
[d('foo'), d('bar')] => 'foo,bar',
|
|
|
|
[d('foo'), d('"bar"'), d('baz')] => 'foo,"""bar""",baz',
|
|
|
|
[d('foo'), d('foo,bar'), d('baz')] => 'foo,"foo,bar",baz',
|
|
|
|
[d('foo'), d('""'), d('baz')] => 'foo,"""""",baz',
|
|
|
|
[d('foo'), d(''), d('baz')] => 'foo,"",baz',
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
[d('foo'), d(nil), d('baz')] => 'foo,,baz',
|
2003-09-15 06:07:42 -04:00
|
|
|
[d('foo'), d("\r"), d('baz')] => "foo,\"\r\",baz",
|
|
|
|
[d('foo'), d("\n"), d('baz')] => "foo,\"\n\",baz",
|
|
|
|
[d('foo'), d("\r\n"), d('baz')] => "foo,\"\r\n\",baz",
|
|
|
|
[d('foo'), d("\r.\n"), d('baz')] => "foo,\"\r.\n\",baz",
|
|
|
|
[d('foo'), d("\r\n\n"), d('baz')] => "foo,\"\r\n\n\",baz",
|
|
|
|
[d('foo'), d('"'), d('baz')] => 'foo,"""",baz',
|
|
|
|
}
|
|
|
|
|
|
|
|
@@fullCSVDataArray = @@fullCSVData.collect { |key, value| key }
|
|
|
|
|
|
|
|
def ssv2csv(ssvStr, row_sep = nil)
|
|
|
|
sepConv(ssvStr, ?;, ?,, row_sep)
|
|
|
|
end
|
|
|
|
|
|
|
|
def csv2ssv(csvStr, row_sep = nil)
|
|
|
|
sepConv(csvStr, ?,, ?;, row_sep)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tsv2csv(tsvStr, row_sep = nil)
|
|
|
|
sepConv(tsvStr, ?\t, ?,, row_sep)
|
|
|
|
end
|
|
|
|
|
|
|
|
def csv2tsv(csvStr, row_sep = nil)
|
|
|
|
sepConv(csvStr, ?,, ?\t, row_sep)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sepConv(srcStr, srcSep, destSep, row_sep = nil)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
rows = []
|
2003-09-15 06:07:42 -04:00
|
|
|
cols, idx = CSV.parse_row(srcStr, 0, rows, srcSep, row_sep)
|
|
|
|
destStr = ''
|
|
|
|
cols = CSV.generate_row(rows, rows.size, destStr, destSep, row_sep)
|
|
|
|
destStr
|
|
|
|
end
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@tmpdir = File.join(Dir.tmpdir, "ruby_test_csv_tmp_#{$$}")
|
|
|
|
Dir.mkdir(@tmpdir)
|
|
|
|
@infile = File.join(@tmpdir, 'in.csv')
|
|
|
|
@infiletsv = File.join(@tmpdir, 'in.tsv')
|
|
|
|
@emptyfile = File.join(@tmpdir, 'empty.csv')
|
|
|
|
@outfile = File.join(@tmpdir, 'out.csv')
|
2003-12-27 22:52:15 -05:00
|
|
|
@bomfile = File.join(@tmpdir, "bom.csv")
|
|
|
|
@macfile = File.join(@tmpdir, "mac.csv")
|
2003-09-15 06:07:42 -04:00
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
CSV.open(@infile, "wb") do |writer|
|
2003-09-15 06:07:42 -04:00
|
|
|
@@fullCSVDataArray.each do |row|
|
|
|
|
writer.add_row(row)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
CSV.open(@infiletsv, "wb", ?\t) do |writer|
|
2003-09-15 06:07:42 -04:00
|
|
|
@@fullCSVDataArray.each do |row|
|
|
|
|
writer.add_row(row)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
CSV.generate(@emptyfile) do |writer|
|
|
|
|
# Create empty file.
|
|
|
|
end
|
2003-12-27 22:52:15 -05:00
|
|
|
|
|
|
|
File.open(@bomfile, "wb") do |f|
|
|
|
|
f.write("\357\273\277\"foo\"\r\n\"bar\"\r\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open(@macfile, "wb") do |f|
|
|
|
|
f.write("\"Avenches\",\"aus Umgebung\"\r\"Bad Hersfeld\",\"Ausgrabung\"")
|
|
|
|
end
|
2003-09-15 06:07:42 -04:00
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
def teardown
|
|
|
|
FileUtils.rm_rf(@tmpdir)
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
#### CSV::Reader unit test
|
2003-09-05 13:36:32 -04:00
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
def test_Reader_each
|
2003-09-04 05:08:30 -04:00
|
|
|
file = File.open(@infile, "rb")
|
2003-09-03 08:45:36 -04:00
|
|
|
begin
|
|
|
|
reader = CSV::Reader.create(file)
|
|
|
|
expectedArray = @@fullCSVDataArray.dup
|
|
|
|
first = true
|
|
|
|
ret = reader.each { |row|
|
|
|
|
if first
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
first = false
|
|
|
|
end
|
|
|
|
expected = expectedArray.shift
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(expected, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
}
|
|
|
|
assert_nil(ret, "Return is nil")
|
|
|
|
assert(expectedArray.empty?)
|
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
end
|
|
|
|
|
|
|
|
# Illegal format.
|
|
|
|
reader = CSV::Reader.create("a,b\r\na,b,\"c\"\ra")
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
reader.each do |row|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
reader = CSV::Reader.create("a,b\r\n\"")
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
reader.each do |row|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Reader_shift
|
2003-09-04 05:08:30 -04:00
|
|
|
file = File.open(@infile, "rb")
|
2003-09-03 08:45:36 -04:00
|
|
|
begin
|
|
|
|
reader = CSV::Reader.create(file)
|
|
|
|
first = true
|
|
|
|
checked = 0
|
|
|
|
@@fullCSVDataArray.each do |expected|
|
|
|
|
actual = reader.shift
|
|
|
|
if first
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, actual)
|
2003-09-03 08:45:36 -04:00
|
|
|
first = false
|
|
|
|
end
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(expected, actual)
|
2003-09-03 08:45:36 -04:00
|
|
|
checked += 1
|
|
|
|
end
|
|
|
|
assert(checked == @@fullCSVDataArray.size)
|
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
end
|
|
|
|
|
|
|
|
# Illegal format.
|
|
|
|
reader = CSV::Reader.create("a,b\r\na,b,\"c\"\ra")
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
reader.shift
|
|
|
|
reader.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
reader = CSV::Reader.create("a,b\r\na,b,\"c\"\ra")
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
reader.shift
|
|
|
|
reader.shift
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Reader_getRow
|
|
|
|
if CSV::Reader.respond_to?(:allocate)
|
|
|
|
obj = CSV::Reader.allocate
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(NotImplementedError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
row = []
|
|
|
|
obj.shift
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_IOReader_close_on_terminate
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@infile, "r")
|
2003-09-03 08:45:36 -04:00
|
|
|
reader = CSV::IOReader.create(f)
|
|
|
|
reader.close
|
|
|
|
assert(!f.closed?)
|
|
|
|
f.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@infile, "r")
|
2003-09-03 08:45:36 -04:00
|
|
|
writer = CSV::IOReader.create(f)
|
|
|
|
writer.close_on_terminate
|
|
|
|
writer.close
|
|
|
|
assert(f.closed?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Reader_close
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@infile, "r")
|
2003-09-03 08:45:36 -04:00
|
|
|
reader = CSV::IOReader.create(f)
|
|
|
|
reader.close_on_terminate
|
|
|
|
reader.close
|
|
|
|
assert(f.closed?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Reader_s_new
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(RuntimeError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV::Reader.new(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Reader_s_create
|
|
|
|
reader = CSV::Reader.create("abc")
|
|
|
|
assert_instance_of(CSV::StringReader, reader, "With a String")
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
file = File.open(@infile, "rb")
|
|
|
|
reader = CSV::Reader.create(file)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::IOReader, reader, 'With an IO')
|
|
|
|
|
|
|
|
obj = Object.new
|
|
|
|
def obj.sysread(size)
|
|
|
|
"abc"
|
|
|
|
end
|
|
|
|
def obj.read(size)
|
|
|
|
"abc"
|
|
|
|
end
|
|
|
|
reader = CSV::Reader.create(obj)
|
|
|
|
assert_instance_of(CSV::IOReader, reader, "With not an IO or String")
|
|
|
|
|
|
|
|
# No need to test Tempfile because it's a pseudo IO. I test this here
|
|
|
|
# fors other tests.
|
|
|
|
reader = CSV::Reader.create(Tempfile.new("in.csv"))
|
|
|
|
assert_instance_of(CSV::IOReader, reader, "With an pseudo IO.")
|
2003-09-04 12:06:41 -04:00
|
|
|
file.close
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-10-06 10:03:58 -04:00
|
|
|
def test_IOReader_s_create_binmode
|
|
|
|
file = File.open(@outfile, "wb")
|
|
|
|
file << "\"\r\n\",\"\r\",\"\n\"\r1,2,3"
|
|
|
|
file.close
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
file = File.open(@outfile, "rb")
|
2003-10-06 10:03:58 -04:00
|
|
|
begin
|
|
|
|
reader = CSV::IOReader.new(file, ?,, ?\r)
|
|
|
|
assert_equal(["\r\n", "\r", "\n"], reader.shift.to_a)
|
|
|
|
assert_equal(["1", "2", "3"], reader.shift.to_a)
|
|
|
|
reader.close
|
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
end
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
|
|
|
|
file = File.open(@outfile, "r") # not "rb"
|
|
|
|
begin
|
|
|
|
lfincell = (RSEP == "\n" ? "\r\n" : "\n")
|
|
|
|
reader = CSV::IOReader.new(file, ?,, ?\r)
|
|
|
|
assert_equal([lfincell, "\r", "\n"], reader.shift.to_a)
|
|
|
|
assert_equal(["1", "2", "3"], reader.shift.to_a)
|
|
|
|
reader.close
|
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
end
|
2003-10-06 10:03:58 -04:00
|
|
|
end
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
def test_Reader_s_parse
|
|
|
|
ret = CSV::Reader.parse("a,b,c") { |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row, "Block parameter")
|
2003-09-03 08:45:36 -04:00
|
|
|
}
|
|
|
|
assert_nil(ret, "Return is nil")
|
|
|
|
|
|
|
|
ret = CSV::Reader.parse("a;b;c", ?;) { |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row, "Block parameter")
|
2003-09-03 08:45:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
file = Tempfile.new("in.csv")
|
|
|
|
file << "a,b,c"
|
|
|
|
file.open
|
|
|
|
ret = CSV::Reader.parse(file) { |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row, "Block parameter")
|
2003-09-03 08:45:36 -04:00
|
|
|
}
|
|
|
|
assert_nil(ret, "Return is nil")
|
|
|
|
|
|
|
|
file = Tempfile.new("in.csv")
|
|
|
|
file << "a,b,c"
|
|
|
|
file.open
|
|
|
|
ret = CSV::Reader.parse(file, ?,) { |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row, "Block parameter")
|
2003-09-03 08:45:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Illegal format.
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV::Reader.parse("a,b\r\na,b,\"c\"\ra") do |row|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV::Reader.parse("a,b\r\na,b\"") do |row|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#### CSV::Writer unit test
|
2003-09-05 13:36:32 -04:00
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
def test_Writer_s_new
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(RuntimeError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV::Writer.new(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Writer_s_generate
|
|
|
|
ret = CSV::Writer.generate(STDOUT) { |writer|
|
|
|
|
assert_instance_of(CSV::BasicWriter, writer, "Block parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = CSV::Writer.generate(STDOUT, ?;) { |writer|
|
|
|
|
assert_instance_of(CSV::BasicWriter, writer, "Block parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_nil(ret, "Return is nil")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Writer_s_create
|
|
|
|
writer = CSV::Writer.create(STDERR)
|
|
|
|
assert_instance_of(CSV::BasicWriter, writer, "String")
|
|
|
|
|
|
|
|
writer = CSV::Writer.create(STDERR, ?;)
|
|
|
|
assert_instance_of(CSV::BasicWriter, writer, "String")
|
|
|
|
|
|
|
|
writer = CSV::Writer.create(Tempfile.new("out.csv"))
|
|
|
|
assert_instance_of(CSV::BasicWriter, writer, "IO")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_Writer_LSHIFT # '<<'
|
|
|
|
file = Tempfile.new("out.csv")
|
|
|
|
CSV::Writer.generate(file) do |writer|
|
|
|
|
ret = writer << ['a', 'b', 'c']
|
|
|
|
assert_instance_of(CSV::BasicWriter, ret, 'Return is self')
|
|
|
|
|
|
|
|
writer << [nil, 'e', 'f'] << [nil, nil, '']
|
|
|
|
end
|
2003-10-06 10:03:58 -04:00
|
|
|
file.open
|
|
|
|
file.binmode
|
|
|
|
str = file.read
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("a,b,c#{RSEP},e,f#{RSEP},,\"\"#{RSEP}", str, 'Normal')
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
file = Tempfile.new("out2.csv")
|
|
|
|
CSV::Writer.generate(file) do |writer|
|
|
|
|
ret = writer << [d('a'), d('b'), d('c')]
|
|
|
|
assert_instance_of(CSV::BasicWriter, ret, 'Return is self')
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
writer << [d(nil), d('e'), d('f')] << [d(nil), d(nil), d('')]
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
2003-10-06 10:03:58 -04:00
|
|
|
file.open
|
|
|
|
file.binmode
|
|
|
|
str = file.read
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("a,b,c#{RSEP},e,f#{RSEP},,\"\"#{RSEP}", str, 'Normal')
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_Writer_add_row
|
|
|
|
file = Tempfile.new("out.csv")
|
|
|
|
CSV::Writer.generate(file) do |writer|
|
|
|
|
ret = writer.add_row(
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
[d('a'), d('b'), d('c')])
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, ret, 'Return is self')
|
|
|
|
|
|
|
|
writer.add_row(
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
[d(nil), d('e'), d('f')]
|
2003-09-03 08:45:36 -04:00
|
|
|
).add_row(
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
[d(nil), d(nil), d('')]
|
2003-09-03 08:45:36 -04:00
|
|
|
)
|
|
|
|
end
|
2003-10-06 10:03:58 -04:00
|
|
|
file.open
|
|
|
|
file.binmode
|
|
|
|
str = file.read
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("a,b,c#{RSEP},e,f#{RSEP},,\"\"#{RSEP}", str, 'Normal')
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_Writer_close
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@outfile, "w")
|
2003-09-03 08:45:36 -04:00
|
|
|
writer = CSV::BasicWriter.create(f)
|
|
|
|
writer.close_on_terminate
|
|
|
|
writer.close
|
|
|
|
assert(f.closed?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_BasicWriter_close_on_terminate
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@outfile, "w")
|
2003-09-03 08:45:36 -04:00
|
|
|
writer = CSV::BasicWriter.create(f)
|
|
|
|
writer.close
|
|
|
|
assert(!f.closed?)
|
2003-09-04 12:06:41 -04:00
|
|
|
f.close
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@outfile, "w")
|
2003-10-06 10:03:58 -04:00
|
|
|
writer = CSV::BasicWriter.new(f)
|
2003-09-03 08:45:36 -04:00
|
|
|
writer.close_on_terminate
|
|
|
|
writer.close
|
|
|
|
assert(f.closed?)
|
|
|
|
end
|
|
|
|
|
2003-10-06 10:03:58 -04:00
|
|
|
def test_BasicWriter_s_create_binmode
|
|
|
|
file = File.open(@outfile, "w") # not "wb"
|
|
|
|
begin
|
|
|
|
writer = CSV::BasicWriter.new(file, ?,, ?\r)
|
|
|
|
writer << ["\r\n", "\r", "\n"]
|
|
|
|
writer << ["1", "2", "3"]
|
|
|
|
writer.close
|
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
end
|
|
|
|
|
|
|
|
file = File.open(@outfile, "rb")
|
|
|
|
str = file.read
|
|
|
|
file.close
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("\"\r#{RSEP}\",\"\r\",\"#{RSEP}\"\r1,2,3\r", str)
|
2003-10-06 10:03:58 -04:00
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
#### CSV unit test
|
|
|
|
|
|
|
|
def test_s_open_reader
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(ArgumentError, 'Illegal mode') do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV.open("temp", "a")
|
|
|
|
end
|
|
|
|
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(ArgumentError, 'Illegal mode') do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV.open("temp", "a", ?;)
|
|
|
|
end
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
reader = CSV.open(@infile, "r")
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::IOReader, reader)
|
|
|
|
reader.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
reader = CSV.open(@infile, "rb")
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::IOReader, reader)
|
|
|
|
reader.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
reader = CSV.open(@infile, "r", ?;)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::IOReader, reader)
|
|
|
|
reader.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@infile, "r") do |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@infiletsv, "r", ?\t) do |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(Errno::ENOENT) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV.open("NoSuchFileOrDirectory", "r")
|
|
|
|
end
|
|
|
|
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(Errno::ENOENT) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV.open("NoSuchFileOrDirectory", "r", ?;)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Illegal format.
|
2003-10-06 10:03:58 -04:00
|
|
|
File.open(@outfile, "wb") do |f|
|
2003-09-03 08:45:36 -04:00
|
|
|
f << "a,b\r\na,b,\"c\"\ra"
|
|
|
|
end
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@outfile, "r") do |row|
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-06 10:03:58 -04:00
|
|
|
File.open(@outfile, "wb") do |f|
|
2003-09-03 08:45:36 -04:00
|
|
|
f << "a,b\r\na,b\""
|
|
|
|
end
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@outfile, "r") do |row|
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@emptyfile, "r") do |row|
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_fail("Must not reach here")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_parse
|
2004-05-26 10:30:30 -04:00
|
|
|
result = CSV.parse(File.read(@infile))
|
|
|
|
assert_instance_of(Array, result)
|
|
|
|
assert_instance_of(Array, result[0])
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
result = CSV.parse(File.read(@infile))
|
|
|
|
assert_instance_of(Array, result)
|
|
|
|
assert_instance_of(Array, result[0])
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
assert_equal([], CSV.parse(""))
|
|
|
|
assert_equal([[nil]], CSV.parse("\n"))
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
CSV.parse(File.read(@infile)) do |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
CSV.parse(File.read(@infiletsv), ?\t) do |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
CSV.parse("") do |row|
|
|
|
|
assert(false)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
count = 0
|
|
|
|
CSV.parse("\n") do |row|
|
|
|
|
assert_equal([nil], row)
|
|
|
|
count += 1
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
2004-05-26 10:30:30 -04:00
|
|
|
assert_equal(1, count)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
assert_equal([["a|b-c|d"]], CSV.parse("a|b-c|d"))
|
|
|
|
assert_equal([["a", "b"], ["c", "d"]], CSV.parse("a|b-c|d", "|", "-"))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_open_writer
|
2003-09-04 05:08:30 -04:00
|
|
|
writer = CSV.open(@outfile, "w")
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
writer.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
writer = CSV.open(@outfile, "wb")
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
writer.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
writer = CSV.open(@outfile, "wb", ?;)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
writer.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@outfile, "w") do |writer|
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
end
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@outfile, "w", ?;) do |writer|
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@tmpdir, "w")
|
2003-09-03 08:45:36 -04:00
|
|
|
assert(false)
|
|
|
|
rescue Exception => ex
|
2003-09-04 05:08:30 -04:00
|
|
|
assert(ex.is_a?(Errno::EEXIST) || ex.is_a?(Errno::EISDIR) || ex.is_a?(Errno::EACCES))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_generate
|
2003-09-04 05:08:30 -04:00
|
|
|
writer = CSV.generate(@outfile)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
writer.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
writer = CSV.generate(@outfile, ?;)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
writer.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.generate(@outfile) do |writer|
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
end
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.generate(@outfile, ?;) do |writer|
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_instance_of(CSV::BasicWriter, writer)
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.generate(@tmpdir)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert(false)
|
|
|
|
rescue Exception => ex
|
2003-09-04 05:08:30 -04:00
|
|
|
assert(ex.is_a?(Errno::EEXIST) || ex.is_a?(Errno::EISDIR) || ex.is_a?(Errno::EACCES))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_generate_line
|
|
|
|
str = CSV.generate_line([])
|
|
|
|
assert_equal('', str, "Extra boundary check.")
|
|
|
|
|
|
|
|
str = CSV.generate_line([], ?;)
|
|
|
|
assert_equal('', str, "Extra boundary check.")
|
|
|
|
|
|
|
|
@@simpleCSVData.each do |col, str|
|
|
|
|
buf = CSV.generate_line(col)
|
|
|
|
assert_equal(str, buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
@@simpleCSVData.each do |col, str|
|
|
|
|
buf = CSV.generate_line(col, ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(str + "\n", ssv2csv(buf))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@simpleCSVData.each do |col, str|
|
|
|
|
buf = CSV.generate_line(col, ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(str + "\n", tsv2csv(buf))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
2004-05-20 13:24:04 -04:00
|
|
|
|
|
|
|
str = CSV.generate_line(['a', 'b'], nil, ?|)
|
|
|
|
assert_equal('a,b', str)
|
|
|
|
|
|
|
|
str = CSV.generate_line(['a', 'b'], nil, "a")
|
|
|
|
assert_equal('"a",b', str)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_generate_row
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row([], 0, buf)
|
|
|
|
assert_equal(0, cols)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("\n", buf, "Extra boundary check.")
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row([], 0, buf, ?;)
|
|
|
|
assert_equal(0, cols)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("\n", buf, "Extra boundary check.")
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row([], 0, buf, ?\t)
|
|
|
|
assert_equal(0, cols)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal("\n", buf, "Extra boundary check.")
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row([], 0, buf, ?\t, ?|)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal("|", buf, "Extra boundary check.")
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1')], 2, buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal('1,', buf)
|
|
|
|
|
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1')], 2, buf, ?;)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal('1;', buf)
|
|
|
|
|
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1')], 2, buf, ?\t)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal("1\t", buf)
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1')], 2, buf, ?\t, ?|)
|
2003-09-15 06:07:42 -04:00
|
|
|
assert_equal("1\t", buf)
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1'), d('2')], 1, buf)
|
|
|
|
assert_equal("1\n", buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1'), d('2')], 1, buf, ?;)
|
|
|
|
assert_equal("1\n", buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1'), d('2')], 1, buf, ?\t)
|
|
|
|
assert_equal("1\n", buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1'), d('2')], 1, buf, ?\t, ?\n)
|
2003-09-15 06:07:42 -04:00
|
|
|
assert_equal("1\n", buf)
|
|
|
|
|
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1'), d('2')], 1, buf, ?\t, ?\r)
|
2003-09-15 06:07:42 -04:00
|
|
|
assert_equal("1\r", buf)
|
|
|
|
|
|
|
|
buf = ''
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols = CSV.generate_row([d('1'), d('2')], 1, buf, ?\t, ?|)
|
2003-09-15 06:07:42 -04:00
|
|
|
assert_equal("1|", buf)
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row(col, col.size, buf)
|
|
|
|
assert_equal(col.size, cols)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(str + "\n", buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row(col, col.size, buf, ?;)
|
|
|
|
assert_equal(col.size, cols)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(str + "\n", ssv2csv(buf))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row(col, col.size, buf, ?\t)
|
|
|
|
assert_equal(col.size, cols)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(str + "\n", tsv2csv(buf))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
# row separator
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row(col, col.size, buf, ?,, ?|)
|
|
|
|
assert_equal(col.size, cols)
|
|
|
|
assert_equal(str + "|", buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
# col and row separator
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf = ''
|
|
|
|
cols = CSV.generate_row(col, col.size, buf, ?\t, ?|)
|
|
|
|
assert_equal(col.size, cols)
|
|
|
|
assert_equal(str + "|", tsv2csv(buf, ?|))
|
|
|
|
end
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
buf = ''
|
|
|
|
toBe = ''
|
|
|
|
cols = 0
|
|
|
|
colsToBe = 0
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
cols += CSV.generate_row(col, col.size, buf)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
toBe << str << "\n"
|
2003-09-03 08:45:36 -04:00
|
|
|
colsToBe += col.size
|
|
|
|
end
|
|
|
|
assert_equal(colsToBe, cols)
|
|
|
|
assert_equal(toBe, buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
toBe = ''
|
|
|
|
cols = 0
|
|
|
|
colsToBe = 0
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
lineBuf = ''
|
|
|
|
cols += CSV.generate_row(col, col.size, lineBuf, ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf << ssv2csv(lineBuf) << "\n"
|
|
|
|
toBe << ssv2csv(lineBuf) << "\n"
|
2003-09-03 08:45:36 -04:00
|
|
|
colsToBe += col.size
|
|
|
|
end
|
|
|
|
assert_equal(colsToBe, cols)
|
|
|
|
assert_equal(toBe, buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
toBe = ''
|
|
|
|
cols = 0
|
|
|
|
colsToBe = 0
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
lineBuf = ''
|
|
|
|
cols += CSV.generate_row(col, col.size, lineBuf, ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf << tsv2csv(lineBuf) << "\n"
|
|
|
|
toBe << tsv2csv(lineBuf) << "\n"
|
2003-09-03 08:45:36 -04:00
|
|
|
colsToBe += col.size
|
|
|
|
end
|
|
|
|
assert_equal(colsToBe, cols)
|
|
|
|
assert_equal(toBe, buf)
|
2003-09-15 06:07:42 -04:00
|
|
|
|
|
|
|
buf = ''
|
|
|
|
toBe = ''
|
|
|
|
cols = 0
|
|
|
|
colsToBe = 0
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
lineBuf = ''
|
|
|
|
cols += CSV.generate_row(col, col.size, lineBuf, ?|)
|
|
|
|
buf << tsv2csv(lineBuf, ?|)
|
|
|
|
toBe << tsv2csv(lineBuf, ?|)
|
|
|
|
colsToBe += col.size
|
|
|
|
end
|
|
|
|
assert_equal(colsToBe, cols)
|
|
|
|
assert_equal(toBe, buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_parse_line
|
|
|
|
@@simpleCSVData.each do |col, str|
|
|
|
|
row = CSV.parse_line(str)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(col.size, row.size)
|
|
|
|
assert_equal(col, row)
|
|
|
|
end
|
|
|
|
|
|
|
|
@@simpleCSVData.each do |col, str|
|
|
|
|
str = csv2ssv(str)
|
|
|
|
row = CSV.parse_line(str, ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
|
|
|
assert_equal(col.size, row.size, str.inspect)
|
|
|
|
assert_equal(col, row, str.inspect)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@simpleCSVData.each do |col, str|
|
|
|
|
str = csv2tsv(str)
|
|
|
|
row = CSV.parse_line(str, ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(col.size, row.size)
|
|
|
|
assert_equal(col, row)
|
|
|
|
end
|
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
assert_equal(['a', 'b', 'c'], CSV.parse_line("a,b,c", nil, nil))
|
|
|
|
assert_equal(['a', nil], CSV.parse_line("a,b,c", nil, ?b))
|
|
|
|
assert_equal(['a', 'b', nil], CSV.parse_line("a,b,c", nil, "c"))
|
|
|
|
assert_equal([nil], CSV.parse_line(""))
|
|
|
|
assert_equal([nil], CSV.parse_line("\n"))
|
|
|
|
assert_equal([""], CSV.parse_line("\"\"\n"))
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
# Illegal format.
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = []
|
2003-09-03 08:45:36 -04:00
|
|
|
row = CSV.parse_line("a,b,\"c\"\ra")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
row = CSV.parse_line("a;b;\"c\"\ra", ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
row = CSV.parse_line("a\tb\t\"c\"\ra", ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("a,b\"")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("a;b\"", ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("a\tb\"", ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("\"a,b\"\r,")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("\"a;b\"\r;", ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("\"a\tb\"\r\t", ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("\"a,b\"\r\"")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("\"a;b\"\r\"", ?;)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
|
|
|
|
row = CSV.parse_line("\"a\tb\"\r\"", ?\t)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_instance_of(Array, row)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(0, row.size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_parse_row
|
|
|
|
@@fullCSVData.each do |col, str|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row(str + "\r\n", 0, buf)
|
|
|
|
assert_equal(cols, buf.size, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf, str.inspect)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
|
|
|
cols, idx = CSV.parse_row(str + "\n", 0, buf, ?,, ?\n)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(cols, buf.size, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf, str.inspect)
|
2003-09-15 06:07:42 -04:00
|
|
|
|
|
|
|
# separator: |
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-15 06:07:42 -04:00
|
|
|
cols, idx = CSV.parse_row(str + "|", 0, buf, ?,)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_not_equal(col, buf)
|
|
|
|
buf = Array.new
|
2003-09-15 06:07:42 -04:00
|
|
|
cols, idx = CSV.parse_row(str + "|", 0, buf, ?,, ?|)
|
|
|
|
assert_equal(cols, buf.size, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf, str.inspect)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
str = csv2ssv(str)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row(str + "\r\n", 0, buf, ?;)
|
|
|
|
assert_equal(cols, buf.size, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf, str)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
str = csv2tsv(str)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row(str + "\r\n", 0, buf, ?\t)
|
|
|
|
assert_equal(cols, buf.size, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf, str)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
str = csv2tsv(str, ?|)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-15 06:07:42 -04:00
|
|
|
cols, idx = CSV.parse_row(str + "|", 0, buf, ?\t, ?|)
|
|
|
|
assert_equal(cols, buf.size, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf, str)
|
2003-09-15 06:07:42 -04:00
|
|
|
end
|
|
|
|
|
2004-05-20 13:24:04 -04:00
|
|
|
buf = []
|
|
|
|
CSV.parse_row("a,b,c", 0, buf, nil, nil)
|
|
|
|
assert_equal(['a', 'b', 'c'], buf)
|
|
|
|
|
|
|
|
buf = []
|
|
|
|
CSV.parse_row("a,b,c", 0, buf, nil, ?b)
|
|
|
|
assert_equal(['a', nil], buf)
|
|
|
|
|
|
|
|
buf = []
|
|
|
|
CSV.parse_row("a,b,c", 0, buf, nil, "c")
|
|
|
|
assert_equal(['a', 'b', nil], buf)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a,b,\"c\r\"", 0, buf)
|
|
|
|
assert_equal(["a", "b", "c\r"], buf.to_a)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a;b;\"c\r\"", 0, buf, ?;)
|
|
|
|
assert_equal(["a", "b", "c\r"], buf.to_a)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a\tb\t\"c\r\"", 0, buf, ?\t)
|
|
|
|
assert_equal(["a", "b", "c\r"], buf.to_a)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
|
|
|
cols, idx = CSV.parse_row("a,b,c\n", 0, buf, ?,, ?\n)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(["a", "b", "c"], buf.to_a)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
|
|
|
cols, idx = CSV.parse_row("a\tb\tc\n", 0, buf, ?\t, ?\n)
|
2003-09-03 08:45:36 -04:00
|
|
|
assert_equal(["a", "b", "c"], buf.to_a)
|
|
|
|
|
|
|
|
# Illegal format.
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a,b,c\"", 0, buf)
|
|
|
|
assert_equal(0, cols, "Illegal format; unbalanced double-quote.")
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a;b;c\"", 0, buf, ?;)
|
|
|
|
assert_equal(0, cols, "Illegal format; unbalanced double-quote.")
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a,b,\"c\"\ra", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a,b,\"c\"\ra", 0, buf, ?;)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a,b\"", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a;b\"", 0, buf, ?;)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("\"a,b\"\r,", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a\r,", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a\r", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a\rbc", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a\r\"\"", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("a\r\rabc,", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("\"a;b\"\r;", 0, buf, ?;)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("\"a,b\"\r\"", 0, buf)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row("\"a;b\"\r\"", 0, buf, ?;)
|
|
|
|
assert_equal(0, cols)
|
|
|
|
assert_equal(0, idx)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_parse_rowEOF
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
if str == ''
|
|
|
|
# String "" is not allowed.
|
|
|
|
next
|
|
|
|
end
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
buf = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
cols, idx = CSV.parse_row(str, 0, buf)
|
|
|
|
assert_equal(col.size, cols, "Reported size.")
|
|
|
|
assert_equal(col.size, buf.size, "Size.")
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(col, buf)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_parse_rowConcat
|
|
|
|
buf = ''
|
|
|
|
toBe = []
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf << str << "\r\n"
|
|
|
|
toBe.concat(col)
|
|
|
|
end
|
|
|
|
idx = 0
|
|
|
|
cols = 0
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
parsed = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
parsedCols = 0
|
|
|
|
begin
|
|
|
|
cols, idx = CSV.parse_row(buf, idx, parsed)
|
|
|
|
parsedCols += cols
|
|
|
|
end while cols > 0
|
|
|
|
assert_equal(toBe.size, parsedCols)
|
|
|
|
assert_equal(toBe.size, parsed.size)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(toBe, parsed)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
buf = ''
|
|
|
|
toBe = []
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf << str << "\n"
|
|
|
|
toBe.concat(col)
|
|
|
|
end
|
|
|
|
idx = 0
|
|
|
|
cols = 0
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
parsed = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
parsedCols = 0
|
|
|
|
begin
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols, idx = CSV.parse_row(buf, idx, parsed, ?,, ?\n)
|
2003-09-03 08:45:36 -04:00
|
|
|
parsedCols += cols
|
|
|
|
end while cols > 0
|
|
|
|
assert_equal(toBe.size, parsedCols)
|
|
|
|
assert_equal(toBe.size, parsed.size)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(toBe, parsed)
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
buf = ''
|
|
|
|
toBe = []
|
|
|
|
@@fullCSVData.sort { |a, b|
|
|
|
|
a[0].length <=> b[0].length
|
|
|
|
}.each do |col, str|
|
|
|
|
buf << str << "\n"
|
|
|
|
toBe.concat(col)
|
|
|
|
end
|
|
|
|
idx = 0
|
|
|
|
cols = 0
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
parsed = Array.new
|
2003-09-03 08:45:36 -04:00
|
|
|
parsedCols = 0
|
|
|
|
begin
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
cols, idx = CSV.parse_row(buf, idx, parsed, ?,, ?\n)
|
2003-09-03 08:45:36 -04:00
|
|
|
parsedCols += cols
|
|
|
|
end while cols > 0
|
|
|
|
assert_equal(toBe.size, parsedCols)
|
|
|
|
assert_equal(toBe.size, parsed.size)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(toBe, parsed)
|
2003-09-15 06:07:42 -04:00
|
|
|
|
|
|
|
buf = ''
|
|
|
|
toBe = []
|
|
|
|
@@fullCSVData.each do |col, str|
|
|
|
|
buf << str << "|"
|
|
|
|
toBe.concat(col)
|
|
|
|
end
|
|
|
|
idx = 0
|
|
|
|
cols = 0
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
parsed = []
|
2003-09-15 06:07:42 -04:00
|
|
|
parsedCols = 0
|
|
|
|
begin
|
|
|
|
cols, idx = CSV.parse_row(buf, idx, parsed, ?,, ?|)
|
|
|
|
parsedCols += cols
|
|
|
|
end while cols > 0
|
|
|
|
assert_equal(toBe.size, parsedCols)
|
|
|
|
assert_equal(toBe.size, parsed.size)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal(toBe, parsed)
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_utf8
|
|
|
|
rows = []
|
2003-09-04 05:08:30 -04:00
|
|
|
CSV.open(@bomfile, "r") do |row|
|
2003-09-03 08:45:36 -04:00
|
|
|
rows << row.to_a
|
|
|
|
end
|
|
|
|
assert_equal([["foo"], ["bar"]], rows)
|
|
|
|
|
|
|
|
rows = []
|
2003-09-04 12:06:41 -04:00
|
|
|
file = File.open(@bomfile)
|
2003-10-06 10:03:58 -04:00
|
|
|
CSV::Reader.parse(file) do |row|
|
2003-09-03 08:45:36 -04:00
|
|
|
rows << row.to_a
|
|
|
|
end
|
|
|
|
assert_equal([["foo"], ["bar"]], rows)
|
2003-09-04 12:06:41 -04:00
|
|
|
file.close
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
def test_macCR
|
|
|
|
rows = []
|
|
|
|
CSV.open(@macfile, "r", ?,, ?\r) do |row|
|
|
|
|
rows << row.to_a
|
|
|
|
end
|
|
|
|
assert_equal([["Avenches", "aus Umgebung"], ["Bad Hersfeld", "Ausgrabung"]], rows)
|
|
|
|
|
2003-09-16 09:26:10 -04:00
|
|
|
rows = []
|
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
|
|
|
CSV.open(@macfile, "r") do |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
rows << row.to_a
|
2003-09-16 09:26:10 -04:00
|
|
|
end
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
assert_equal([["Avenches", "aus Umgebung\r\"Bad Hersfeld", "Ausgrabung"]], rows)
|
2003-09-16 09:26:10 -04:00
|
|
|
end
|
|
|
|
|
2003-09-15 06:07:42 -04:00
|
|
|
rows = []
|
|
|
|
file = File.open(@macfile)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
begin
|
|
|
|
CSV::Reader.parse(file, ?,, ?\r) do |row|
|
|
|
|
rows << row.to_a
|
|
|
|
end
|
|
|
|
assert_equal([["Avenches", "aus Umgebung"], ["Bad Hersfeld", "Ausgrabung"]], rows)
|
|
|
|
ensure
|
|
|
|
file.close
|
2003-09-15 06:07:42 -04:00
|
|
|
end
|
2003-09-16 09:26:10 -04:00
|
|
|
|
|
|
|
rows = []
|
|
|
|
file = File.open(@macfile)
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
begin
|
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
|
|
|
CSV::Reader.parse(file, ?,) do |row|
|
|
|
|
rows << row.to_a
|
|
|
|
end
|
|
|
|
assert_equal([["Avenches", "aus Umgebung\r\"Bad Hersfeld", "Ausgrabung"]], rows)
|
2003-09-16 09:26:10 -04:00
|
|
|
end
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
ensure
|
|
|
|
file.close
|
2003-09-16 09:26:10 -04:00
|
|
|
end
|
2003-09-15 06:07:42 -04:00
|
|
|
end
|
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
#### CSV unit test
|
|
|
|
|
|
|
|
InputStreamPattern = '0123456789'
|
|
|
|
InputStreamPatternSize = InputStreamPattern.size
|
|
|
|
def expChar(idx)
|
|
|
|
InputStreamPattern[idx % InputStreamPatternSize]
|
|
|
|
end
|
|
|
|
|
|
|
|
def expStr(idx, n)
|
|
|
|
if n > InputStreamPatternSize
|
|
|
|
InputStreamPattern + expStr(0, n - InputStreamPatternSize)
|
|
|
|
else
|
|
|
|
InputStreamPattern[idx % InputStreamPatternSize, n]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setupInputStream(size, bufSize = nil)
|
|
|
|
setBufSize(bufSize) if bufSize
|
|
|
|
m = ((size / InputStreamPatternSize) + 1).to_i
|
2003-09-04 05:08:30 -04:00
|
|
|
File.open(@outfile, "wb") do |f|
|
2003-09-03 08:45:36 -04:00
|
|
|
f << (InputStreamPattern * m)[0, size]
|
|
|
|
end
|
2003-09-04 12:06:41 -04:00
|
|
|
file = File.open(@outfile, "rb")
|
|
|
|
buf = CSV::IOBuf.new(file)
|
|
|
|
if block_given?
|
|
|
|
yield(buf)
|
|
|
|
file.close
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
buf
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def setBufSize(size)
|
2003-09-05 13:36:32 -04:00
|
|
|
CSV::StreamBuf.module_eval('remove_const("BufSize")')
|
|
|
|
CSV::StreamBuf.module_eval("BufSize = #{ size }")
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class StrBuf < CSV::StreamBuf
|
|
|
|
private
|
|
|
|
def initialize(string)
|
|
|
|
@str = string
|
|
|
|
@idx = 0
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(size)
|
|
|
|
str = @str[@idx, size]
|
|
|
|
if str.empty?
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
@idx += str.size
|
|
|
|
str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ErrBuf < CSV::StreamBuf
|
|
|
|
class Error < RuntimeError; end
|
|
|
|
private
|
|
|
|
def initialize
|
|
|
|
@first = true
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(size)
|
|
|
|
if @first
|
|
|
|
@first = false
|
|
|
|
"a" * size
|
|
|
|
else
|
|
|
|
raise ErrBuf::Error.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_StreamBuf_MyBuf
|
|
|
|
# At first, check ruby's behaviour.
|
|
|
|
s = "abc"
|
|
|
|
assert_equal(?a, s[0])
|
|
|
|
assert_equal(?b, s[1])
|
|
|
|
assert_equal(?c, s[2])
|
|
|
|
assert_equal(nil, s[3])
|
|
|
|
assert_equal("a", s[0, 1])
|
|
|
|
assert_equal("b", s[1, 1])
|
|
|
|
assert_equal("c", s[2, 1])
|
|
|
|
assert_equal("", s[3, 1])
|
|
|
|
assert_equal(nil, s[4, 1])
|
|
|
|
|
|
|
|
s = StrBuf.new("abc")
|
|
|
|
assert_equal(?a, s[0])
|
|
|
|
assert_equal(?b, s.get(1))
|
|
|
|
assert_equal(?c, s[2])
|
|
|
|
assert_equal(nil, s.get(3))
|
|
|
|
assert_equal("a", s[0, 1])
|
|
|
|
assert_equal("b", s.get(1, 1))
|
|
|
|
assert_equal("c", s[2, 1])
|
|
|
|
assert_equal("", s.get(3, 1))
|
|
|
|
assert_equal(nil, s[4, 1])
|
|
|
|
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(?b, s[0])
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(?c, s[0])
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(nil, s[0])
|
|
|
|
assert(s.is_eos?)
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(0, dropped)
|
|
|
|
assert_equal(nil, s[0])
|
|
|
|
assert(s.is_eos?)
|
|
|
|
|
|
|
|
s = StrBuf.new("")
|
|
|
|
assert_equal(nil, s[0])
|
|
|
|
|
|
|
|
s = StrBuf.new("")
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(0, dropped)
|
|
|
|
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(TestCSV::ErrBuf::Error) do
|
2003-09-03 08:45:36 -04:00
|
|
|
s = ErrBuf.new
|
|
|
|
s[1024]
|
|
|
|
end
|
|
|
|
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(TestCSV::ErrBuf::Error) do
|
2003-09-03 08:45:36 -04:00
|
|
|
s = ErrBuf.new
|
|
|
|
s.drop(1024)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_StreamBuf_AREF # '[idx]'
|
2003-09-04 12:06:41 -04:00
|
|
|
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
|
|
|
|
[22, 23].each do |idx|
|
|
|
|
assert_equal(nil, s[idx], idx.to_s)
|
|
|
|
end
|
|
|
|
assert_equal(nil, s[-1])
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
setupInputStream(1, 1) do |s|
|
|
|
|
[0].each do |idx|
|
|
|
|
assert_equal(expChar(idx), s[idx], idx.to_s)
|
|
|
|
end
|
|
|
|
[1, 2].each do |idx|
|
|
|
|
assert_equal(nil, s[idx], idx.to_s)
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
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])
|
2003-09-05 13:36:32 -04:00
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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])
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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])
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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])
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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])
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
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
|
|
|
|
assert_equal(expStr(21, 1), s[21, 2])
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
assert_equal(expStr(0, 12), s[0, 12])
|
|
|
|
assert_equal(expStr(10, 12), s[10, 12])
|
|
|
|
assert_equal(expStr(10, 12), s[10, 13])
|
|
|
|
assert_equal(expStr(10, 12), s[10, 14])
|
|
|
|
assert_equal(expStr(10, 12), s[10, 1024])
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
assert_equal(nil, s[0, -1])
|
|
|
|
assert_equal(nil, s[21, -1])
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
assert_equal(nil, s[-1, 10])
|
|
|
|
assert_equal(nil, s[-1, -1])
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_StreamBuf_get
|
2003-09-04 12:06:41 -04:00
|
|
|
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
|
|
|
|
[22, 23].each do |idx|
|
|
|
|
assert_equal(nil, s.get(idx), idx.to_s)
|
|
|
|
end
|
|
|
|
assert_equal(nil, s.get(-1))
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
2003-09-05 13:36:32 -04:00
|
|
|
|
2003-09-03 08:45:36 -04:00
|
|
|
def test_StreamBuf_get_n
|
2003-09-04 12:06:41 -04:00
|
|
|
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
|
|
|
|
assert_equal("", s.get(22, 1))
|
|
|
|
assert_equal(nil, s.get(23, 1))
|
2003-09-03 08:45:36 -04:00
|
|
|
|
2003-09-04 12:06:41 -04:00
|
|
|
assert_equal(nil, s.get(-1, 1))
|
|
|
|
assert_equal(nil, s.get(-1, -1))
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_StreamBuf_drop
|
2003-09-04 12:06:41 -04:00
|
|
|
setupInputStream(22, 1024) do |s|
|
|
|
|
assert_equal(expChar(0), s[0])
|
|
|
|
assert_equal(expChar(21), s[21])
|
|
|
|
assert_equal(nil, s[22])
|
|
|
|
|
|
|
|
dropped = s.drop(-1)
|
|
|
|
assert_equal(0, dropped)
|
|
|
|
assert_equal(expChar(0), s[0])
|
|
|
|
|
|
|
|
dropped = s.drop(0)
|
|
|
|
assert_equal(0, dropped)
|
|
|
|
assert_equal(expChar(0), s[0])
|
|
|
|
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(expChar(1), s[0])
|
|
|
|
assert_equal(expChar(2), s[1])
|
|
|
|
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(expChar(2), s[0])
|
|
|
|
assert_equal(expChar(3), s[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
setupInputStream(4, 2) do |s|
|
|
|
|
dropped = s.drop(2)
|
|
|
|
assert_equal(2, dropped)
|
|
|
|
assert_equal(expChar(2), s[0])
|
|
|
|
assert_equal(expChar(3), s[1])
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(expChar(3), s[0])
|
|
|
|
assert_equal(nil, s[1])
|
|
|
|
dropped = s.drop(1)
|
|
|
|
assert_equal(1, dropped)
|
|
|
|
assert_equal(nil, s[0])
|
|
|
|
assert_equal(nil, s[1])
|
|
|
|
dropped = s.drop(0)
|
|
|
|
assert_equal(0, dropped)
|
|
|
|
assert_equal(nil, s[0])
|
|
|
|
assert_equal(nil, s[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
setupInputStream(6, 3) do |s|
|
|
|
|
dropped = s.drop(2)
|
|
|
|
assert_equal(2, dropped)
|
|
|
|
dropped = s.drop(2)
|
|
|
|
assert_equal(2, dropped)
|
|
|
|
assert_equal(expChar(4), s[0])
|
|
|
|
assert_equal(expChar(5), s[1])
|
|
|
|
dropped = s.drop(3)
|
|
|
|
assert_equal(2, dropped)
|
|
|
|
assert_equal(nil, s[0])
|
|
|
|
assert_equal(nil, s[1])
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_StreamBuf_is_eos?
|
2003-09-04 12:06:41 -04:00
|
|
|
setupInputStream(3, 1024) do |s|
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(s.is_eos?)
|
|
|
|
end
|
|
|
|
|
|
|
|
setupInputStream(3, 2) do |s|
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(!s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(s.is_eos?)
|
|
|
|
s.drop(1)
|
|
|
|
assert(s.is_eos?)
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_StreamBuf_s_new
|
|
|
|
# NotImplementedError should be raised from StreamBuf#read.
|
2003-09-04 02:41:00 -04:00
|
|
|
assert_raises(NotImplementedError) do
|
2003-09-03 08:45:36 -04:00
|
|
|
CSV::StreamBuf.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_IOBuf_close
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@outfile, "wb")
|
2003-09-03 08:45:36 -04:00
|
|
|
f << "tst"
|
|
|
|
f.close
|
|
|
|
|
2003-09-04 05:08:30 -04:00
|
|
|
f = File.open(@outfile, "rb")
|
2003-09-03 08:45:36 -04:00
|
|
|
iobuf = CSV::IOBuf.new(f)
|
2003-09-04 02:41:00 -04:00
|
|
|
iobuf.close
|
|
|
|
assert(true) # iobuf.close does not raise any exception.
|
2003-09-04 12:06:41 -04:00
|
|
|
f.close
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_IOBuf_s_new
|
|
|
|
iobuf = CSV::IOBuf.new(Tempfile.new("in.csv"))
|
|
|
|
assert_instance_of(CSV::IOBuf, iobuf)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#### CSV functional test
|
|
|
|
|
|
|
|
# sample data
|
|
|
|
#
|
|
|
|
# 1 2 3 4 5 6 7 8
|
|
|
|
# +------+-------+---------+-------+--------+------+----+------+
|
|
|
|
# | foo | "foo" | foo,bar | "" |(empty) |(null)| \r | \r\n |
|
|
|
|
# +------+-------+---------+-------+--------+------+----+------+
|
|
|
|
# | NaHi | "Na" | Na,Hi | \r.\n | \r\n\n | " | \n | \r\n |
|
|
|
|
# +------+-------+---------+-------+--------+------+----+------+
|
|
|
|
#
|
|
|
|
def test_s_parseAndCreate
|
|
|
|
colSize = 8
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
csvStr = "foo,!!!foo!!!,!foo,bar!,!!!!!!,!!,,!\r!,!\r\n!\nNaHi,!!!Na!!!,!Na,Hi!,!\r.\n!,!\r\n\n!,!!!!,!\n!,!\r\n!".gsub!('!', '"')
|
|
|
|
csvStrTerminated = csvStr + "\n"
|
2003-09-03 08:45:36 -04:00
|
|
|
|
|
|
|
myStr = csvStr.dup
|
|
|
|
res1 = []; res2 = []
|
|
|
|
idx = 0
|
|
|
|
col, idx = CSV::parse_row(myStr, 0, res1)
|
|
|
|
col, idx = CSV::parse_row(myStr, idx, res2)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
col = CSV::generate_row(res1, colSize, buf)
|
|
|
|
col = CSV::generate_row(res2, colSize, buf)
|
|
|
|
assert_equal(csvStrTerminated, buf)
|
|
|
|
|
|
|
|
parsed = []
|
|
|
|
CSV::Reader.parse(csvStrTerminated) do |row|
|
|
|
|
parsed << row
|
|
|
|
end
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf) do |writer|
|
|
|
|
parsed.each do |row|
|
|
|
|
writer.add_row(row)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal(csvStrTerminated, buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf) do |writer|
|
|
|
|
parsed.each do |row|
|
* lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".
* lib/csv.rb: [CAUTION] API change
* CSV::Row removed. a row is represented as just an Array. since
CSV::Row was a subclass of Array, it won't hurt almost all programs
except one which depended CSV::Row#match.
* CSV::Cell removed. a cell is represented as just a String or
nil(NULL). this change will cause widespread destruction.
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # Cell#is_null
p "(NULL)"
else
p cell.data # Cell#data
end
end
end
must be just;
CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.nil?
p "(NULL)"
else
p cell
end
end
end
* lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
change. CSV.open, CSV.parse, and CSV,generate now do not force
opened file binmode. formerly it set binmode explicitly.
with CSV.open, binmode of opened file depends the given mode
parameter "r", "w", "rb", and "wb". CSV.parse and CSV.generate open
file with "r" and "w".
setting mode properly is user's responsibility now.
* lib/csv.rb: accepts String as a fs (field separator/column separator)
and rs (record separator/row separator)
* lib/csv.rb: added CSV.foreach(path, rs = nil, &block). CSV.foreach
now does not handle "| cmd" as a path different from IO.foreach.
needed?
* test/csv/test_csv.rb: updated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 08:34:33 -04:00
|
|
|
writer << row
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_equal(csvStrTerminated, buf)
|
|
|
|
end
|
2004-05-20 13:24:04 -04:00
|
|
|
|
|
|
|
def test_writer_fs_rs_generate
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, ",,") do |writer|
|
|
|
|
writer << []
|
|
|
|
end
|
|
|
|
assert_equal("\n", buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, ",,") do |writer|
|
|
|
|
writer << [] << []
|
|
|
|
end
|
|
|
|
assert_equal("\n\n", buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, ",,") do |writer|
|
|
|
|
writer << [1]
|
|
|
|
end
|
|
|
|
assert_equal("1\n", buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, ",,") do |writer|
|
|
|
|
writer << [1, 2, 3]
|
|
|
|
writer << [4, ",,", 5]
|
|
|
|
end
|
|
|
|
assert_equal("1,,2,,3\n4,,\",,\",,5\n", buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, ",,:", ",,;") do |writer|
|
|
|
|
writer << [nil, nil, nil]
|
|
|
|
writer << [nil, ",,", nil]
|
|
|
|
end
|
|
|
|
assert_equal(",,:,,:,,;,,:,,,,:,,;", buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, "---") do |writer|
|
|
|
|
writer << [1, 2, 3]
|
|
|
|
writer << [4, "---\"---", 5]
|
|
|
|
end
|
|
|
|
assert_equal("1---2---3\n4---\"---\"\"---\"---5\n", buf)
|
|
|
|
|
|
|
|
buf = ''
|
|
|
|
CSV::Writer.generate(buf, nil) do |writer|
|
|
|
|
writer << [1, 2, 3]
|
|
|
|
writer << [4, ",\",", 5]
|
|
|
|
end
|
|
|
|
assert_equal("1,2,3\n4,\",\"\",\",5\n", buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_writer_fs_rs_parse
|
|
|
|
reader = CSV::Reader.create('a||b--c||d', '||', '--')
|
|
|
|
assert_equal(['a', 'b'], reader.shift)
|
|
|
|
assert_equal(['c', 'd'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create("a@|b@-c@|d", "@|", "@-")
|
|
|
|
assert_equal(['a', 'b'], reader.shift)
|
|
|
|
assert_equal(['c', 'd'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create("ababfsababrs", "abfs", "abrs")
|
|
|
|
assert_equal(['ab', 'ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create('"ab"abfsababrs', "abfs", "abrs")
|
|
|
|
assert_equal(['ab', 'ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create('"ab"aabfsababrs', "abfs", "abrs")
|
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
|
|
|
reader.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
# fs match while matching rs progress
|
|
|
|
reader = CSV::Reader.create("ab,ababrs", nil, "abrs")
|
|
|
|
assert_equal(['ab', 'ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create(',ababrs', nil, "abrs")
|
|
|
|
assert_equal([nil, 'ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create('"",ababrs', nil, "abrs")
|
|
|
|
assert_equal(['', 'ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create('ab,"ab"abrs', nil, "abrs")
|
|
|
|
assert_equal(['ab', 'ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create('ab,"ab"aabrs', nil, "abrs")
|
|
|
|
assert_raises(CSV::IllegalFormatError) do
|
|
|
|
reader.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
# rs match while matching fs progress
|
|
|
|
reader = CSV::Reader.create("ab|abc", 'ab-', "ab|")
|
|
|
|
assert_equal([nil], reader.shift)
|
|
|
|
assert_equal(['abc'], reader.shift)
|
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
reader = CSV::Reader.create("ab\ncdabcef", "abc", "\n")
|
|
|
|
assert_equal(['ab'], reader.shift)
|
|
|
|
assert_equal(['cd', "ef"], reader.shift)
|
|
|
|
|
2004-05-20 13:24:04 -04:00
|
|
|
# EOF while fs/rs matching
|
|
|
|
reader = CSV::Reader.create("ab", 'ab-', "xyz")
|
|
|
|
assert_equal(['ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create("ab", 'xyz', "ab|")
|
|
|
|
assert_equal(['ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create("ab", 'ab-', "ab|")
|
|
|
|
assert_equal(['ab'], reader.shift)
|
|
|
|
|
|
|
|
reader = CSV::Reader.create(",,:,,:,,;,,:,,,,:,,;", ",,:", ",,;")
|
|
|
|
assert_equal([nil, nil, nil], reader.shift)
|
|
|
|
assert_equal([nil, ",,", nil], reader.shift)
|
|
|
|
end
|
|
|
|
|
2004-05-26 10:30:30 -04:00
|
|
|
def test_s_foreach
|
2004-05-20 13:24:04 -04:00
|
|
|
File.open(@outfile, "w") do |f|
|
|
|
|
f << "1,2,3\n4,5,6"
|
|
|
|
end
|
|
|
|
row = []
|
|
|
|
CSV.foreach(@outfile) { |line|
|
|
|
|
row << line
|
|
|
|
}
|
|
|
|
assert_equal([['1', '2', '3'], ['4', '5', '6']], row)
|
|
|
|
|
|
|
|
File.open(@outfile, "w") do |f|
|
|
|
|
f << "1,2,3\r4,5,6"
|
|
|
|
end
|
|
|
|
row = []
|
|
|
|
CSV.foreach(@outfile, "\r") { |line|
|
|
|
|
row << line
|
|
|
|
}
|
|
|
|
assert_equal([['1', '2', '3'], ['4', '5', '6']], row)
|
|
|
|
end
|
2004-05-26 10:30:30 -04:00
|
|
|
|
|
|
|
def test_s_readlines
|
|
|
|
File.open(@outfile, "w") do |f|
|
|
|
|
f << "1,2,3\n4,5,6"
|
|
|
|
end
|
|
|
|
assert_equal([["1", "2", "3"], ["4", "5", "6"]], CSV.readlines(@outfile))
|
|
|
|
assert_equal([["1", "2", nil], [nil, "5", "6"]], CSV.readlines(@outfile, "3\n4"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_s_read
|
|
|
|
File.open(@outfile, "w") do |f|
|
|
|
|
f << "1,2,3\n4,5,6"
|
|
|
|
end
|
|
|
|
assert_equal([["1", "2", "3"], ["4", "5", "6"]], CSV.read(@outfile))
|
|
|
|
assert_equal([["1", "2"]], CSV.read(@outfile, 3))
|
|
|
|
assert_equal([[nil], ["4", nil]], CSV.read(@outfile, 3, 5))
|
|
|
|
end
|
2003-09-03 08:45:36 -04:00
|
|
|
end
|