summaryrefslogtreecommitdiffstats
path: root/test/csv/test_serialization.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-06 03:56:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-06 03:56:38 +0000
commitd17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad (patch)
tree5e35d5b41aae961b37cf6632f60c42f51c7aa775 /test/csv/test_serialization.rb
parent101e79d7b434c01c0e6f4bcc480003858ab8e1a4 (diff)
downloadruby-d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad.tar.gz
ruby-d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad.tar.xz
ruby-d17d1b111341f2c8979cf8fbd63ec7ec9db7c3ad.zip
* {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/test_serialization.rb')
-rw-r--r--test/csv/test_serialization.rb50
1 files changed, 25 insertions, 25 deletions
diff --git a/test/csv/test_serialization.rb b/test/csv/test_serialization.rb
index 878619f58..f8e6df1b1 100644
--- a/test/csv/test_serialization.rb
+++ b/test/csv/test_serialization.rb
@@ -16,48 +16,48 @@ class Hash
def self.csv_load( meta, headers, fields )
self[*headers.zip(fields).to_a.flatten.map { |e| eval(e) }]
end
-
+
def csv_headers
keys.map { |key| key.inspect }
end
-
+
def csv_dump( headers )
headers.map { |header| fetch(eval(header)).inspect }
end
end
class TestSerialization < Test::Unit::TestCase
-
+
### Classes Used to Test Serialization ###
-
+
class ReadOnlyName
def initialize( first, last )
@first, @last = first, last
end
attr_reader :first, :last
-
+
def ==( other )
%w{first last}.all? { |att| send(att) == other.send(att) }
end
end
Name = Struct.new(:first, :last)
-
+
class FullName < Name
def initialize( first, last, suffix = nil )
super(first, last)
-
+
@suffix = suffix
end
-
+
attr_accessor :suffix
-
+
def ==( other )
%w{first last suffix}.all? { |att| send(att) == other.send(att) }
end
end
-
+
### Tests ###
def test_class_dump
@@ -66,8 +66,8 @@ class TestSerialization < Test::Unit::TestCase
%w{Greg Brown} ].map do |first, last|
ReadOnlyName.new(first, last)
end
-
- assert_nothing_raised(Exception) do
+
+ assert_nothing_raised(Exception) do
@data = CSV.dump(@names)
end
assert_equal(<<-END_CLASS_DUMP.gsub(/^\s*/, ""), @data)
@@ -78,15 +78,15 @@ class TestSerialization < Test::Unit::TestCase
Greg,Brown
END_CLASS_DUMP
end
-
+
def test_struct_dump
@names = [ %w{James Gray},
%w{Dana Gray},
%w{Greg Brown} ].map do |first, last|
Name.new(first, last)
end
-
- assert_nothing_raised(Exception) do
+
+ assert_nothing_raised(Exception) do
@data = CSV.dump(@names)
end
assert_equal(<<-END_STRUCT_DUMP.gsub(/^\s*/, ""), @data)
@@ -97,15 +97,15 @@ class TestSerialization < Test::Unit::TestCase
Greg,Brown
END_STRUCT_DUMP
end
-
+
def test_inherited_struct_dump
@names = [ %w{James Gray II},
%w{Dana Gray},
%w{Greg Brown} ].map do |first, last, suffix|
FullName.new(first, last, suffix)
end
-
- assert_nothing_raised(Exception) do
+
+ assert_nothing_raised(Exception) do
@data = CSV.dump(@names)
end
assert_equal(<<-END_STRUCT_DUMP.gsub(/^\s*/, ""), @data)
@@ -116,7 +116,7 @@ class TestSerialization < Test::Unit::TestCase
,Greg,Brown
END_STRUCT_DUMP
end
-
+
def test_load
%w{ test_class_dump
test_struct_dump
@@ -128,13 +128,13 @@ class TestSerialization < Test::Unit::TestCase
end
end
end
-
+
def test_io
test_class_dump
-
+
data_file = File.join(File.dirname(__FILE__), "temp_test_data.csv")
CSV.dump(@names, File.open(data_file, "w"))
-
+
assert(File.exist?(data_file))
assert_equal(<<-END_IO_DUMP.gsub(/^\s*/, ""), File.read(data_file))
class,TestSerialization::ReadOnlyName
@@ -143,12 +143,12 @@ class TestSerialization < Test::Unit::TestCase
Dana,Gray
Greg,Brown
END_IO_DUMP
-
+
assert_equal(@names, CSV.load(File.open(data_file)))
-
+
File.unlink(data_file)
end
-
+
def test_custom_dump_and_load
obj = {1 => "simple", test: Hash}
assert_equal(obj, CSV.load(CSV.dump([obj])).first)