From 287a34ae0dfc23e4158f67cb7783d239f202c368 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 6 Mar 2009 03:56:38 +0000 Subject: * {ext,lib,test}/**/*.rb: removed trailing spaces. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/csv/test_interface.rb | 66 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'test/csv/test_interface.rb') diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb index b9e634a559..a6028f92f3 100644 --- a/test/csv/test_interface.rb +++ b/test/csv/test_interface.rb @@ -14,7 +14,7 @@ require "csv" class TestCSVInterface < Test::Unit::TestCase def setup @path = File.join(File.dirname(__FILE__), "temp_test_data.csv") - + File.open(@path, "w") do |file| file << "1\t2\t3\r\n" file << "4\t5\r\n" @@ -22,19 +22,19 @@ class TestCSVInterface < Test::Unit::TestCase @expected = [%w{1 2 3}, %w{4 5}] end - + def teardown File.unlink(@path) end - + ### Test Read Interface ### - + def test_foreach CSV.foreach(@path, col_sep: "\t", row_sep: "\r\n") do |row| assert_equal(@expected.shift, row) end end - + def test_open_and_close csv = CSV.open(@path, "r+", col_sep: "\t", row_sep: "\r\n") assert_not_nil(csv) @@ -42,7 +42,7 @@ class TestCSVInterface < Test::Unit::TestCase assert_equal(false, csv.closed?) csv.close assert(csv.closed?) - + ret = CSV.open(@path) do |new_csv| csv = new_csv assert_instance_of(CSV, new_csv) @@ -51,7 +51,7 @@ class TestCSVInterface < Test::Unit::TestCase assert(csv.closed?) assert_equal("Return value.", ret) end - + def test_parse data = File.read(@path) assert_equal( @expected, @@ -61,27 +61,27 @@ class TestCSVInterface < Test::Unit::TestCase assert_equal(@expected.shift, row) end end - + def test_parse_line row = CSV.parse_line("1;2;3", col_sep: ";") assert_not_nil(row) assert_instance_of(Array, row) assert_equal(%w{1 2 3}, row) - + # shortcut interface row = "1;2;3".parse_csv(col_sep: ";") assert_not_nil(row) assert_instance_of(Array, row) assert_equal(%w{1 2 3}, row) end - + def test_read_and_readlines assert_equal( @expected, CSV.read(@path, col_sep: "\t", row_sep: "\r\n") ) assert_equal( @expected, CSV.readlines(@path, col_sep: "\t", row_sep: "\r\n") ) - - + + data = CSV.open(@path, col_sep: "\t", row_sep: "\r\n") do |csv| csv.read end @@ -91,13 +91,13 @@ class TestCSVInterface < Test::Unit::TestCase end assert_equal(@expected, data) end - + def test_table table = CSV.table(@path, col_sep: "\t", row_sep: "\r\n") assert_instance_of(CSV::Table, table) assert_equal([[:"1", :"2", :"3"], [4, 5, nil]], table.to_a) end - + def test_shift # aliased as gets() and readline() CSV.open(@path, "r+", col_sep: "\t", row_sep: "\r\n") do |csv| assert_equal(@expected.shift, csv.shift) @@ -105,7 +105,7 @@ class TestCSVInterface < Test::Unit::TestCase assert_equal(nil, csv.shift) end end - + ### Test Write Interface ### def test_generate @@ -123,13 +123,13 @@ class TestCSVInterface < Test::Unit::TestCase end assert_equal(%Q{1,2,3\n4,,5\nlast,"""row"""\n}, str) end - + def test_generate_line line = CSV.generate_line(%w{1 2 3}, col_sep: ";") assert_not_nil(line) assert_instance_of(String, line) assert_equal("1;2;3\n", line) - + # shortcut interface line = %w{1 2 3}.to_csv(col_sep: ";") assert_not_nil(line) @@ -173,7 +173,7 @@ class TestCSVInterface < Test::Unit::TestCase csv.each { |line| assert_equal(lines.shift, line.to_hash) } end end - + def test_write_hash_with_headers_array File.unlink(@path) @@ -216,7 +216,7 @@ class TestCSVInterface < Test::Unit::TestCase csv.each { |line| assert_equal(lines.shift, line.to_hash) } end end - + def test_write_headers File.unlink(@path) @@ -241,10 +241,10 @@ class TestCSVInterface < Test::Unit::TestCase csv.each { |line| assert_equal(lines.shift, line.to_hash) } end end - + def test_append # aliased add_row() and puts() File.unlink(@path) - + CSV.open(@path, "w", col_sep: "\t", row_sep: "\r\n") do |csv| @expected.each { |row| csv << row } end @@ -253,19 +253,19 @@ class TestCSVInterface < Test::Unit::TestCase # same thing using CSV::Row objects File.unlink(@path) - + CSV.open(@path, "w", col_sep: "\t", row_sep: "\r\n") do |csv| @expected.each { |row| csv << CSV::Row.new(Array.new, row) } end test_shift end - + ### Test Read and Write Interface ### - + def test_filter assert_respond_to(CSV, :filter) - + expected = [[1, 2, 3], [4, 5]] CSV.filter( "1;2;3\n4;5\n", (result = String.new), in_col_sep: ";", out_col_sep: ",", @@ -276,27 +276,27 @@ class TestCSVInterface < Test::Unit::TestCase end assert_equal("2,4,6,\"Added\r\"\n8,10,\"Added\r\"\n", result) end - + def test_instance csv = String.new - + first = nil - assert_nothing_raised(Exception) do + assert_nothing_raised(Exception) do first = CSV.instance(csv, col_sep: ";") first << %w{a b c} end - + assert_equal("a;b;c\n", csv) - + second = nil - assert_nothing_raised(Exception) do + assert_nothing_raised(Exception) do second = CSV.instance(csv, col_sep: ";") second << [1, 2, 3] end - + assert_equal(first.object_id, second.object_id) assert_equal("a;b;c\n1;2;3\n", csv) - + # shortcuts assert_equal(STDOUT, CSV.instance.instance_eval { @io }) assert_equal(STDOUT, CSV { |new_csv| new_csv.instance_eval { @io } }) -- cgit v1.2.3