* test/csv/test_interface.rb, test/csv/test_serialization.rb:

Trying more fixes some failing tests on Windows.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
jeg2 2009-03-30 23:20:44 +00:00
Родитель 2a58eebd8f
Коммит 8e2eedf46b
3 изменённых файлов: 26 добавлений и 21 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Mar 31 08:18:57 2009 James Edward Gray II <jeg2@ruby-lang.org>
* test/csv/test_interface.rb, test/csv/test_serialization.rb:
Trying more fixes some failing tests on Windows.
Mon Mar 30 19:04:25 2009 Tanaka Akira <akr@fsij.org> Mon Mar 30 19:04:25 2009 Tanaka Akira <akr@fsij.org>
* .gdbinit (rp): show negative fixnum correctly. * .gdbinit (rp): show negative fixnum correctly.

Просмотреть файл

@ -53,7 +53,7 @@ class TestCSVInterface < Test::Unit::TestCase
end end
def test_parse def test_parse
data = File.read(@path) data = File.binread(@path)
assert_equal( @expected, assert_equal( @expected,
CSV.parse(data, col_sep: "\t", row_sep: "\r\n") ) CSV.parse(data, col_sep: "\t", row_sep: "\r\n") )
@ -99,7 +99,7 @@ class TestCSVInterface < Test::Unit::TestCase
end end
def test_shift # aliased as gets() and readline() def test_shift # aliased as gets() and readline()
CSV.open(@path, "r+", col_sep: "\t", row_sep: "\r\n") do |csv| CSV.open(@path, "rb+", col_sep: "\t", row_sep: "\r\n") do |csv|
assert_equal(@expected.shift, csv.shift) assert_equal(@expected.shift, csv.shift)
assert_equal(@expected.shift, csv.shift) assert_equal(@expected.shift, csv.shift)
assert_equal(nil, csv.shift) assert_equal(nil, csv.shift)
@ -178,18 +178,18 @@ class TestCSVInterface < Test::Unit::TestCase
File.unlink(@path) File.unlink(@path)
lines = [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}] lines = [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]
CSV.open(@path, "w", headers: [:b, :a, :c]) do |csv| CSV.open(@path, "wb", headers: [:b, :a, :c]) do |csv|
lines.each { |line| csv << line } lines.each { |line| csv << line }
end end
# test writing fields in the correct order # test writing fields in the correct order
File.open(@path, "r") do |f| File.open(@path, "rb") do |f|
assert_equal("2,1,3", f.gets.strip) assert_equal("2,1,3", f.gets.strip)
assert_equal("5,4,6", f.gets.strip) assert_equal("5,4,6", f.gets.strip)
end end
# test reading CSV with headers # test reading CSV with headers
CSV.open( @path, "r", headers: [:b, :a, :c], CSV.open( @path, "rb", headers: [:b, :a, :c],
converters: :all ) do |csv| converters: :all ) do |csv|
csv.each { |line| assert_equal(lines.shift, line.to_hash) } csv.each { |line| assert_equal(lines.shift, line.to_hash) }
end end
@ -199,18 +199,18 @@ class TestCSVInterface < Test::Unit::TestCase
File.unlink(@path) File.unlink(@path)
lines = [{"a" => 1, "b" => 2, "c" => 3}, {"a" => 4, "b" => 5, "c" => 6}] lines = [{"a" => 1, "b" => 2, "c" => 3}, {"a" => 4, "b" => 5, "c" => 6}]
CSV.open(@path, "w", headers: "b|a|c", col_sep: "|") do |csv| CSV.open(@path, "wb", headers: "b|a|c", col_sep: "|") do |csv|
lines.each { |line| csv << line } lines.each { |line| csv << line }
end end
# test writing fields in the correct order # test writing fields in the correct order
File.open(@path, "r") do |f| File.open(@path, "rb") do |f|
assert_equal("2|1|3", f.gets.strip) assert_equal("2|1|3", f.gets.strip)
assert_equal("5|4|6", f.gets.strip) assert_equal("5|4|6", f.gets.strip)
end end
# test reading CSV with headers # test reading CSV with headers
CSV.open( @path, "r", headers: "b|a|c", CSV.open( @path, "rb", headers: "b|a|c",
col_sep: "|", col_sep: "|",
converters: :all ) do |csv| converters: :all ) do |csv|
csv.each { |line| assert_equal(lines.shift, line.to_hash) } csv.each { |line| assert_equal(lines.shift, line.to_hash) }
@ -221,21 +221,21 @@ class TestCSVInterface < Test::Unit::TestCase
File.unlink(@path) File.unlink(@path)
lines = [{"a" => 1, "b" => 2, "c" => 3}, {"a" => 4, "b" => 5, "c" => 6}] lines = [{"a" => 1, "b" => 2, "c" => 3}, {"a" => 4, "b" => 5, "c" => 6}]
CSV.open( @path, "w", headers: "b|a|c", CSV.open( @path, "wb", headers: "b|a|c",
write_headers: true, write_headers: true,
col_sep: "|" ) do |csv| col_sep: "|" ) do |csv|
lines.each { |line| csv << line } lines.each { |line| csv << line }
end end
# test writing fields in the correct order # test writing fields in the correct order
File.open(@path, "r") do |f| File.open(@path, "rb") do |f|
assert_equal("b|a|c", f.gets.strip) assert_equal("b|a|c", f.gets.strip)
assert_equal("2|1|3", f.gets.strip) assert_equal("2|1|3", f.gets.strip)
assert_equal("5|4|6", f.gets.strip) assert_equal("5|4|6", f.gets.strip)
end end
# test reading CSV with headers # test reading CSV with headers
CSV.open( @path, "r", headers: true, CSV.open( @path, "rb", headers: true,
col_sep: "|", col_sep: "|",
converters: :all ) do |csv| converters: :all ) do |csv|
csv.each { |line| assert_equal(lines.shift, line.to_hash) } csv.each { |line| assert_equal(lines.shift, line.to_hash) }
@ -245,7 +245,7 @@ class TestCSVInterface < Test::Unit::TestCase
def test_append # aliased add_row() and puts() def test_append # aliased add_row() and puts()
File.unlink(@path) File.unlink(@path)
CSV.open(@path, "w", col_sep: "\t", row_sep: "\r\n") do |csv| CSV.open(@path, "wb", col_sep: "\t", row_sep: "\r\n") do |csv|
@expected.each { |row| csv << row } @expected.each { |row| csv << row }
end end
@ -254,7 +254,7 @@ class TestCSVInterface < Test::Unit::TestCase
# same thing using CSV::Row objects # same thing using CSV::Row objects
File.unlink(@path) File.unlink(@path)
CSV.open(@path, "w", col_sep: "\t", row_sep: "\r\n") do |csv| CSV.open(@path, "wb", col_sep: "\t", row_sep: "\r\n") do |csv|
@expected.each { |row| csv << CSV::Row.new(Array.new, row) } @expected.each { |row| csv << CSV::Row.new(Array.new, row) }
end end

Просмотреть файл

@ -133,7 +133,7 @@ class TestSerialization < Test::Unit::TestCase
test_class_dump test_class_dump
data_file = File.join(File.dirname(__FILE__), "temp_test_data.csv") data_file = File.join(File.dirname(__FILE__), "temp_test_data.csv")
CSV.dump(@names, File.open(data_file, "w")) CSV.dump(@names, File.open(data_file, "wb"))
assert(File.exist?(data_file)) assert(File.exist?(data_file))
assert_equal(<<-END_IO_DUMP.gsub(/^\s*/, ""), File.read(data_file)) assert_equal(<<-END_IO_DUMP.gsub(/^\s*/, ""), File.read(data_file))