diff options
Diffstat (limited to 'test/csv/parse/test_general.rb')
-rw-r--r-- | test/csv/parse/test_general.rb | 88 |
1 files changed, 80 insertions, 8 deletions
diff --git a/test/csv/parse/test_general.rb b/test/csv/parse/test_general.rb index c740462c01..902be2ce4a 100644 --- a/test/csv/parse/test_general.rb +++ b/test/csv/parse/test_general.rb @@ -199,6 +199,32 @@ line,5,jkl field_size_limit: 2048 ) end + def test_field_size_limit_max_allowed + column = "abcde" + assert_equal([[column]], + CSV.parse("\"#{column}\"", + field_size_limit: column.size + 1)) + end + + def test_field_size_limit_quote_simple + column = "abcde" + assert_parse_errors_out("\"#{column}\"", + field_size_limit: column.size) + end + + def test_field_size_limit_no_quote_implicitly + column = "abcde" + assert_parse_errors_out("#{column}", + field_size_limit: column.size) + end + + def test_field_size_limit_no_quote_explicitly + column = "abcde" + assert_parse_errors_out("#{column}", + field_size_limit: column.size, + quote_char: nil) + end + def test_field_size_limit_in_extended_column_not_exceeding data = <<~DATA "a","b" @@ -221,6 +247,59 @@ line,5,jkl assert_parse_errors_out(data, field_size_limit: 5) end + def test_max_field_size_controls_lookahead + assert_parse_errors_out( 'valid,fields,"' + BIG_DATA + '"', + max_field_size: 2048 ) + end + + def test_max_field_size_max_allowed + column = "abcde" + assert_equal([[column]], + CSV.parse("\"#{column}\"", + max_field_size: column.size)) + end + + def test_max_field_size_quote_simple + column = "abcde" + assert_parse_errors_out("\"#{column}\"", + max_field_size: column.size - 1) + end + + def test_max_field_size_no_quote_implicitly + column = "abcde" + assert_parse_errors_out("#{column}", + max_field_size: column.size - 1) + end + + def test_max_field_size_no_quote_explicitly + column = "abcde" + assert_parse_errors_out("#{column}", + max_field_size: column.size - 1, + quote_char: nil) + end + + def test_max_field_size_in_extended_column_not_exceeding + data = <<~DATA + "a","b" + " + 2 + ","" + DATA + assert_nothing_raised(CSV::MalformedCSVError) do + CSV.parse(data, max_field_size: 3) + end + end + + def test_max_field_size_in_extended_column_exceeding + data = <<~DATA + "a","b" + " + 2345 + ","" + DATA + assert_parse_errors_out(data, max_field_size: 4) + end + def test_row_sep_auto_cr assert_equal([["a"]], CSV.parse("a\r")) end @@ -246,14 +325,7 @@ line,5,jkl private def assert_parse_errors_out(data, **options) assert_raise(CSV::MalformedCSVError) do - timeout = 0.2 - if defined?(RubyVM::YJIT.enabled?) and RubyVM::YJIT.enabled? - timeout = 1 # for --yjit-call-threshold=1 - end - if defined?(RubyVM::MJIT.enabled?) and RubyVM::MJIT.enabled? - timeout = 5 # for --jit-wait - end - Timeout.timeout(timeout) do + Timeout.timeout(0.2) do CSV.parse(data, **options) fail("Parse didn't error out") end |