summaryrefslogtreecommitdiff
path: root/test/csv
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-01 02:44:48 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-01 02:44:48 +0000
commitf18f940802752fb8997164d4440c488fb1396f35 (patch)
tree4b565a7cf7873e9de8ab876579c951238f47ed87 /test/csv
parent7d9342aecd8dc608f85ea13c400b91f8e361ab9f (diff)
Adding a liberal_parsing option to CSV. Patch by Braden Anderson.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv')
-rwxr-xr-xtest/csv/test_features.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb
index 37fdab8636d..a5588755223 100755
--- a/test/csv/test_features.rb
+++ b/test/csv/test_features.rb
@@ -142,6 +142,29 @@ class TestCSV::Features < TestCSV
assert_equal(3, count)
end
+ def test_liberal_parsing
+ input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
+ assert_raise(CSV::MalformedCSVError) do
+ CSV.parse_line(input)
+ end
+ assert_equal(["Johnson, Dwayne", 'Dwayne "The Rock" Johnson'],
+ CSV.parse_line(input, liberal_parsing: true))
+
+ input = '"quoted" field'
+ assert_raise(CSV::MalformedCSVError) do
+ CSV.parse_line(input)
+ end
+ assert_equal(['"quoted" field'],
+ CSV.parse_line(input, liberal_parsing: true))
+
+ assert_raise(CSV::MalformedCSVError) do
+ CSV.parse_line('is,this "three," or four,fields', liberal_parsing: true)
+ end
+
+ assert_equal(["is", 'this "three', ' or four"', "fields"],
+ CSV.parse_line('is,this "three, or four",fields', liberal_parsing: true))
+ end
+
def test_csv_behavior_readers
%w[ unconverted_fields return_headers write_headers
skip_blanks force_quotes ].each do |behavior|