Permalink
Browse files

fix more newline and empty cell cases to match CSV

  • Loading branch information...
jondistad committed Apr 7, 2011
1 parent 49a8bf1 commit a9e47648a2cdcd711917f8899e0ac5d06ccb1591
Showing with 13 additions and 1 deletion.
  1. +5 −0 ext/bamfcsv/bamfcsv_ext.c
  2. +0 −1 lib/bamfcsv.rb
  3. +7 −0 spec/lib/bamfcsv_spec.rb
  4. +1 −0 spec/spec_helper.rb
@@ -112,6 +112,11 @@ VALUE build_matrix(char *buf, int bufsize) {
VALUE matrix;
char *cur;
+
+ if (bufsize > 0 && *(buf+bufsize-1) == '\n') {
+ *(buf+bufsize-1) = 0;
+ --bufsize;
+ }
for (cur = buf; cur < buf+bufsize; cur++) {
View
@@ -9,7 +9,6 @@ def self.read(thing_to_read, opts={})
def self.parse(csv_str, opts={})
return [] if csv_str.empty?
- csv_str.chomp!
matrix = __parse_string(csv_str)
if opts[:headers]
Table.new(matrix)
View
@@ -127,6 +127,13 @@
expect { BAMFCSV.parse(%Q("a"b"c"\n)) }.should raise_error(BAMFCSV::MalformedCSVError)
expect { BAMFCSV.parse(%Q("a"b"c"\r\n)) }.should raise_error(BAMFCSV::MalformedCSVError)
end
+
+ ['', "\n", "\r\n", ",", "\n\n", "\r\n\r\n"].each do |csv|
+ csv_result = CSV.parse(csv)
+ it "BAMFCSV parses #{csv.inspect} the same way as CSV (#{csv_result.inspect})" do
+ BAMFCSV.parse(csv).should == csv_result
+ end
+ end
end
end
View
@@ -4,6 +4,7 @@
require 'bundler'
require 'bamfcsv'
Bundler.require(:development)
+require 'csv'
RSpec.configure do |config|
config.filter_run :focused => true

0 comments on commit a9e4764

Please sign in to comment.