From 3c3e659196b7511f02b03e2904c40a29993a184c Mon Sep 17 00:00:00 2001 From: jeg2 Date: Mon, 20 Aug 2012 20:52:36 +0000 Subject: * 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 --- test/csv/test_features.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test') 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 -- cgit v1.2.3