summaryrefslogtreecommitdiff
path: root/test/csv
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-05 18:28:26 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-05 18:28:26 +0000
commitb614d7823c4d3dcb263577127db5e7e333573a4e (patch)
tree6966beaa54fe028f41099a395f613b4ee3d83159 /test/csv
parent3221e7d29ca5911437f6d2bd733d5022c7050a72 (diff)
* lib/csv.rb: Remove the dangerous serialization feature.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv')
-rwxr-xr-xtest/csv/test_serialization.rb158
-rw-r--r--test/csv/ts_all.rb1
2 files changed, 0 insertions, 159 deletions
diff --git a/test/csv/test_serialization.rb b/test/csv/test_serialization.rb
deleted file mode 100755
index dafe12b..0000000
--- a/test/csv/test_serialization.rb
+++ /dev/null
@@ -1,158 +0,0 @@
-#!/usr/bin/env ruby -w
-# encoding: UTF-8
-
-# tc_serialization.rb
-#
-# Created by James Edward Gray II on 2005-10-31.
-# Copyright 2005 James Edward Gray II. You can redistribute or modify this code
-# under the terms of Ruby's license.
-
-require_relative "base"
-require "tempfile"
-
-# An example of how to provide custom CSV serialization.
-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 TestCSV::Serialization < TestCSV
- extend DifferentOFS
-
- ### 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
- @names = [ %w{James Gray},
- %w{Dana Gray},
- %w{Greg Brown} ].map do |first, last|
- ReadOnlyName.new(first, last)
- end
-
- assert_nothing_raised(Exception) do
- @data = CSV.dump(@names)
- end
- assert_equal(<<-END_CLASS_DUMP.gsub(/^\s*/, ""), @data)
- class,TestCSV::Serialization::ReadOnlyName
- @first,@last
- James,Gray
- Dana,Gray
- 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
- @data = CSV.dump(@names)
- end
- assert_equal(<<-END_STRUCT_DUMP.gsub(/^\s*/, ""), @data)
- class,TestCSV::Serialization::Name
- first=,last=
- James,Gray
- Dana,Gray
- 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
- @data = CSV.dump(@names)
- end
- assert_equal(<<-END_STRUCT_DUMP.gsub(/^\s*/, ""), @data)
- class,TestCSV::Serialization::FullName
- @suffix,first=,last=
- II,James,Gray
- ,Dana,Gray
- ,Greg,Brown
- END_STRUCT_DUMP
- end
-
- def test_load
- %w{ test_class_dump
- test_struct_dump
- test_inherited_struct_dump }.each do |test|
- send(test)
- CSV.load(@data).each do |loaded|
- assert_instance_of(@names.first.class, loaded)
- assert_equal(@names.shift, loaded)
- end
- end
- end
-
- def test_io
- test_class_dump
-
- tempfile = Tempfile.new(%w"serialization .csv")
- tempfile.close
- data_file = tempfile.path
- CSV.dump(@names, File.open(data_file, "wb"))
-
- assert(File.exist?(data_file))
- assert_equal(<<-END_IO_DUMP.gsub(/^\s*/, ""), File.read(data_file))
- class,TestCSV::Serialization::ReadOnlyName
- @first,@last
- James,Gray
- Dana,Gray
- Greg,Brown
- END_IO_DUMP
-
- assert_equal(@names, CSV.load(File.open(data_file)))
-
- tempfile.close(true)
- end
-
- def test_custom_dump_and_load
- obj = {1 => "simple", test: Hash}
- assert_equal(obj, CSV.load(CSV.dump([obj])).first)
- end
-end
diff --git a/test/csv/ts_all.rb b/test/csv/ts_all.rb
index 4fadbb4..3893841 100644
--- a/test/csv/ts_all.rb
+++ b/test/csv/ts_all.rb
@@ -17,5 +17,4 @@ require "test_data_converters"
require "test_row"
require "test_table"
require "test_headers"
-require "test_serialization"
require "test_encodings"