On Oct 30, 2005, at 8:55 AM, Stefan Lang wrote: > On Sunday 30 October 2005 14:52, gabriele renzi wrote: > >> William James ha scritto: >> > [...] > >>> For my test file of 1,964,211 bytes, it's about 6.4 times as >>> fast. >>> >> >> what things is this missing wrt standard csv.rb? >> >> Also, why you did choose to make all of the stuff (methods, >> variables) at class level instead of instance ? >> > > A more OO (and equally fast) version: Ara.T.Howard posted a test framework for a bunch of edge cases on Ruby Core, based on the CSV RFC (http://www.ietf.org/rfc/ rfc4180.txt). Here's that framework modified to work with your library: Neo:~/Desktop$ cat fast_csv_tests.rb require 'pp' require 'csv' require 'fast_csv' tests = [ [ %( a,b ), ["a", "b"] ], [ %( a,"""b""" ), ["a", "\"b\""] ], [ %( a,"""b" ), ["a", "\"b"] ], [ %( a,"b""" ), ["a", "b\""] ], [ %( a," b""" ), ["a", "\nb\""] ], [ %( a,""" b" ), ["a", "\"\nb"] ], [ %( a,""" b """ ), ["a", "\"\nb\n\""] ], [ %( a,""" b """, c ), ["a", "\"\nb\n\"", nil] ], [ %( a,,, ), ["a", nil, nil, nil] ], [ %( , ), [nil, nil] ], [ %( "","" ), ["", ""] ], [ %( """" ), ["\""] ], [ %( """","" ), ["\"",""] ], [ %( ,"" ), [nil,""] ], [ %( \r,"\r" ), [nil,"\r"] ], [ %( "\r\n," ), ["\r\n,"] ], [ %( "\r\n,", ), ["\r\n,", nil] ], ] impls = CSV, FastCsv.new tests.each_with_index do |test, idx| input, expected = test csv = [] impls.each do |impl| begin if impl == CSV csv = impl::parse_line input.strip else csv = impl.parse input.strip end raise "FAILED" unless csv == expected rescue => e puts "=" * 42 puts "#{ impl }[#{ idx }] => #{ e.message } (#{ e.class })" puts "=" * 42 puts "input:\n#{ PP::pp input.strip, '' }" puts "csv:\n#{ PP::pp csv, '' }" puts "expected:\n#{ PP::pp expected, '' }" puts "=" * 42 puts end end end __END__ Neo:~/Desktop$ ruby fast_csv_tests.rb ========================================== #<FastCsv:0x33d130>[7] => Bad csv record: a,""" b """, c (RuntimeError) ========================================== input: "a,\"\"\"\nb\n\"\"\",\nc" csv: ["a", "\"\nb\n\"", nil] expected: ["a", "\"\nb\n\"", nil] ========================================== ========================================== #<FastCsv:0x33d130>[8] => FAILED (RuntimeError) ========================================== input: "a,,," csv: ["a", "", "", ""] expected: ["a", nil, nil, nil] ========================================== ========================================== #<FastCsv:0x33d130>[9] => FAILED (RuntimeError) ========================================== input: "," csv: ["", ""] expected: [nil, nil] ========================================== ========================================== #<FastCsv:0x33d130>[13] => FAILED (RuntimeError) ========================================== input: ",\"\"" csv: ["", ""] expected: [nil, ""] ========================================== ========================================== #<FastCsv:0x33d130>[14] => FAILED (RuntimeError) ========================================== input: ",\"\r\"" csv: ["", "\r"] expected: [nil, "\r"] ========================================== ========================================== #<FastCsv:0x33d130>[16] => FAILED (RuntimeError) ========================================== input: "\"\r\n,\"," csv: ["\r\n,", ""] expected: ["\r\n,", nil] ========================================== James Edward Gray II