csv: fix missing last column

pull/4532/head
sambeckingham 2020-04-20 20:49:05 +01:00 committed by GitHub
parent f725b93019
commit b1459ade69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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() {

View File

@ -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