From b1459ade6987fb71de39fe24387c15d1fb8fc572 Mon Sep 17 00:00:00 2001 From: sambeckingham <48661226+sambeckingham@users.noreply.github.com> Date: Mon, 20 Apr 2020 20:49:05 +0100 Subject: [PATCH] csv: fix missing last column --- vlib/encoding/csv/csv_test.v | 15 ++++++++++----- vlib/encoding/csv/reader.v | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/vlib/encoding/csv/csv_test.v b/vlib/encoding/csv/csv_test.v index b859d7b4e9..7442bfce8c 100644 --- a/vlib/encoding/csv/csv_test.v +++ b/vlib/encoding/csv/csv_test.v @@ -1,7 +1,7 @@ import encoding.csv fn test_encoding_csv_reader() { - data := 'name,email,phone,other\njoe,joe@blow.com,0400000000,test\nsam,sam@likesham.com,0433000000,"test quoted field"\n#chris,chris@nomail.com,94444444,"commented row"\nmike,mike@mikesbikes.com,98888888,"bike store"\n' + data := 'name,email,phone,other\njoe,joe@blow.com,0400000000,test\nsam,sam@likesham.com,0433000000,"test quoted field"\n#chris,chris@nomail.com,94444444,"commented row"\n' mut csv_reader := csv.new_reader(data) mut row_count := 0 @@ -12,21 +12,26 @@ fn test_encoding_csv_reader() { row_count++ if row_count== 1 { assert row[0] == 'name' + assert row[1] == 'email' + assert row[2] == 'phone' + assert row[3] == 'other' } if row_count == 2 { assert row[0] == 'joe' + assert row[1] == 'joe@blow.com' + assert row[2] == '0400000000' + assert row[3] == 'test' } if row_count == 3 { assert row[0] == 'sam' + assert row[1] == 'sam@likesham.com' + assert row[2] == '0433000000' // quoted field assert row[3] == 'test quoted field' } - if row_count == 4 { - assert row[0] == 'mike' - } } - assert row_count == 4 + assert row_count == 3 } fn test_encoding_csv_writer() { diff --git a/vlib/encoding/csv/reader.v b/vlib/encoding/csv/reader.v index ddf2feed94..bb6a8c33f0 100644 --- a/vlib/encoding/csv/reader.v +++ b/vlib/encoding/csv/reader.v @@ -115,6 +115,7 @@ fn (r mut Reader) read_record() ?[]string { // QTODO i = ... j := line.index(r.delimiter.str()) or { // last + fields << line[..line.len] break } i = j