diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/csv.rb | 14 | ||||
-rw-r--r-- | test/csv/test_csv.rb | 26 |
3 files changed, 46 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Fri Dec 12 22:36:44 2003 NAKAMURA, Hiroshi <[email protected]> + + * lib/csv.rb: add Cell#to_str and Cell#to_s for /.../ =~ aCell, + "#{aCell}" and so on. + + * test/csv/test_csv.rb: add tests. + Fri Dec 12 19:33:06 2003 Minero Aoki <[email protected]> * lib/fileutils.rb (mkdir): remove trailing `/' from pathes. diff --git a/lib/csv.rb b/lib/csv.rb index 10c86f6417..cfc5489ea0 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -85,6 +85,20 @@ public @data == rhs.data end end + + def to_str + content.to_str + end + + def to_s + content.to_s + end + + private + + def content + @is_null ? nil : data + end end diff --git a/test/csv/test_csv.rb b/test/csv/test_csv.rb index 782f5af8d4..6cc4c5cac7 100644 --- a/test/csv/test_csv.rb +++ b/test/csv/test_csv.rb @@ -1,4 +1,5 @@ -require 'test/unit' +require 'test/unit/testsuite' +require 'test/unit/testcase' require 'tempfile' require 'fileutils' @@ -92,6 +93,29 @@ class TestCSVCell < Test::Unit::TestCase d3 = CSV::Cell.new(nil, false) assert_equal(d3.is_null, false, "Data: false.") end + + def test_to_str + d = CSV::Cell.new("foo", false) + assert_equal("foo", d.to_str) + assert(/foo/ =~ d) + d = CSV::Cell.new("foo", true) + begin + d.to_str + assert(false) + rescue + # NoMethodError or NameError + assert(true) + end + end + + def test_to_s + d = CSV::Cell.new("foo", false) + assert_equal("foo", d.to_s) + assert_equal("foo", "#{d}") + d = CSV::Cell.new("foo", true) + assert_equal("", d.to_s) + assert_equal("", "#{d}") + end end |