summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-20 20:52:36 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-20 20:52:36 +0000
commit3c3e659196b7511f02b03e2904c40a29993a184c (patch)
tree7ed24f6ae43d6ecac69602d97e15039768f75059 /test
parent6ac1d39acec4ccb01cca219e30d2ba4b3547a9e3 (diff)
* lib/csv.rb: Fixes #161 on github
* lib/csv.rb: You can now specify a pattern for :skip_lines. Matching lines will not be passed to the CSV parser. * lib/csv.rb: Patch by Christian Schwartz. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rwxr-xr-xtest/csv/test_features.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb
index 7176cca0e0..ded876abbe 100755
--- a/test/csv/test_features.rb
+++ b/test/csv/test_features.rb
@@ -274,4 +274,37 @@ class TestCSV::Features < TestCSV
assert(CSV::VERSION.frozen?)
assert_match(/\A\d\.\d\.\d\Z/, CSV::VERSION)
end
+
+ def test_accepts_comment_skip_lines_option
+ assert_nothing_raised(ArgumentError) do
+ CSV.new nil, :skip_lines => /\A\s*#/
+ end
+ end
+
+ def test_accepts_comment_defaults_to_nil
+ c = CSV.new nil
+ assert_equal c.skip_lines, nil
+ end
+
+ class RegexStub
+ end
+
+ def test_requires_skip_lines_to_call_match
+ regex_stub = RegexStub.new
+ assert_raise(ArgumentError) do
+ CSV.new nil, :skip_lines => regex_stub
+ end
+ end
+
+ def test_comment_rows_are_ignored
+ sample_data = "line,1,a\n#not,a,line\nline,2,b\n #also,no,line"
+ c = CSV.new sample_data, :skip_lines => /\A\s*#/
+ assert_equal c.each.to_a, [["line", "1", "a"], ["line", "2", "b"]]
+ end
+
+ def test_quoted_skip_line_markers_are_ignored
+ sample_data = "line,1,a\n\"#not\",a,line\nline,2,b"
+ c = CSV.new sample_data, :skip_lines => /\A\s*#/
+ assert_equal c.each.to_a, [["line", "1", "a"], ["#not", "a", "line"], ["line", "2", "b"]]
+ end
end