1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Import CSV 3.0.8

This includes performance improvements and backward incompatibility
fixes.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2019-04-14 21:01:51 +00:00
parent fb96811d15
commit e3b6c7c7eb
23 changed files with 1534 additions and 650 deletions

View file

@ -22,8 +22,7 @@ class TestCSVParseLiberalParsing < Test::Unit::TestCase
error = assert_raise(CSV::MalformedCSVError) do
CSV.parse_line(input)
end
assert_equal("Do not allow except col_sep_split_separator " +
"after quoted fields in line 1.",
assert_equal("Any value after quoted field isn't allowed in line 1.",
error.message)
assert_equal(['"quoted" field'],
CSV.parse_line(input, liberal_parsing: true))
@ -75,8 +74,7 @@ class TestCSVParseLiberalParsing < Test::Unit::TestCase
error = assert_raise(CSV::MalformedCSVError) do
CSV.parse(data)
end
assert_equal("Do not allow except col_sep_split_separator " +
"after quoted fields in line 1.",
assert_equal("Any value after quoted field isn't allowed in line 1.",
error.message)
assert_equal([
[["a", %Q{""b""}]],
@ -90,4 +88,73 @@ class TestCSVParseLiberalParsing < Test::Unit::TestCase
}),
])
end
class TestBackslashQuote < Test::Unit::TestCase
extend ::DifferentOFS
def test_double_quote_outside_quote
data = %Q{a,""b""}
assert_equal([
[["a", %Q{""b""}]],
[["a", %Q{"b"}]],
],
[
CSV.parse(data,
liberal_parsing: {
backslash_quote: true
}),
CSV.parse(data,
liberal_parsing: {
backslash_quote: true,
double_quote_outside_quote: true
}),
])
end
def test_unquoted_value
data = %q{\"\"a\"\"}
assert_equal([
[[%q{\"\"a\"\"}]],
[[%q{""a""}]],
],
[
CSV.parse(data, liberal_parsing: true),
CSV.parse(data,
liberal_parsing: {
backslash_quote: true
}),
])
end
def test_unquoted_value_multiple_characters_col_sep
data = %q{a<\\"b<=>x}
assert_equal([[%Q{a<"b}, "x"]],
CSV.parse(data,
col_sep: "<=>",
liberal_parsing: {
backslash_quote: true
}))
end
def test_quoted_value
data = %q{"\"\"a\"\""}
assert_equal([
[[%q{"\"\"a\"\""}]],
[[%q{""a""}]],
[[%q{""a""}]],
],
[
CSV.parse(data, liberal_parsing: true),
CSV.parse(data,
liberal_parsing: {
backslash_quote: true
}),
CSV.parse(data,
liberal_parsing: {
backslash_quote: true,
double_quote_outside_quote: true
}),
])
end
end
end