diff options
Diffstat (limited to 'test/csv/test_serialization.rb')
-rw-r--r-- | test/csv/test_serialization.rb | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/test/csv/test_serialization.rb b/test/csv/test_serialization.rb index 878619f58a..f8e6df1b1d 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) |