Skip to content

Commit

Permalink
* lib/csv.rb: add Cell#to_str and Cell#to_s for /.../ =~ aCell,
Browse files Browse the repository at this point in the history
          "#{aCell}" and so on.

        * test/csv/test_csv.rb: add tests.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nahi committed Dec 12, 2003
1 parent 232b4c2 commit 30e1429
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 14 additions & 0 deletions lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ def ==(rhs)
@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


Expand Down
26 changes: 25 additions & 1 deletion test/csv/test_csv.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'test/unit'
require 'test/unit/testsuite'
require 'test/unit/testcase'
require 'tempfile'
require 'fileutils'

Expand Down Expand Up @@ -92,6 +93,29 @@ def test_Cell_s_new
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


Expand Down

0 comments on commit 30e1429

Please sign in to comment.