mirror of
https://github.com/vlang/v.git
synced 2025-09-11 16:36:20 -04:00
encoding.csv: fix bug in RandomAccessReader, spotted on windows with mingw32 (#20571)
This commit is contained in:
parent
4c47bb5288
commit
ef3b0ec775
@ -252,7 +252,7 @@ pub fn (mut cr RandomAccessReader) map_csv() ! {
|
||||
// println("${i:-12d} of ${cr.f_len:-12d} readed: ${read_bytes_count}")
|
||||
mut p1 := p
|
||||
mut i1 := i64(0)
|
||||
for i1 <= read_bytes_count {
|
||||
for i1 < read_bytes_count {
|
||||
// println("loop char: ${*&u8(p1):c}")
|
||||
// manage quote char
|
||||
if *p1 == cr.quote {
|
||||
@ -529,7 +529,7 @@ pub fn (mut cr RandomAccessReader) rows_count() !i64 {
|
||||
// println("${i:-12d} of ${cr.f_len:-12d} readed: ${read_bytes_count}")
|
||||
mut p1 := p
|
||||
mut i1 := 0
|
||||
for i1 <= read_bytes_count {
|
||||
for i1 < read_bytes_count {
|
||||
if *p1 == cr.end_line {
|
||||
count++
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ This file contains tests
|
||||
Known limitations:
|
||||
*/
|
||||
import encoding.csv
|
||||
import strings
|
||||
import os
|
||||
|
||||
/******************************************************************************
|
||||
@ -267,7 +268,7 @@ fn test_csv_string() {
|
||||
// parse the temp file
|
||||
csvr = csv.csv_reader(
|
||||
file_path: file_path_str
|
||||
mem_buf_size: 64
|
||||
mem_buf_size: 32
|
||||
end_line_len: csv.endline_crlf_len
|
||||
)!
|
||||
perform_test(mut csvr)!
|
||||
@ -295,6 +296,53 @@ fn test_csv_string() {
|
||||
csvr.dispose_csv_reader()
|
||||
}
|
||||
|
||||
fn test_coherence() {
|
||||
file_path_str := os.join_path(os.temp_dir(), 'test_csv.csv')
|
||||
mut f := os.open_file(file_path_str, 'w')!
|
||||
mut b := strings.new_builder(64536)
|
||||
mut i := u64(0)
|
||||
mut sum := u64(0)
|
||||
for rows in 0 .. 1000 {
|
||||
for col in 0 .. 1000 {
|
||||
if col > 0 {
|
||||
b.write_u8(`,`)
|
||||
}
|
||||
b.write_string(i.str())
|
||||
i++
|
||||
sum += i
|
||||
}
|
||||
b.write_string('\n')
|
||||
}
|
||||
f.write_string(b.str())!
|
||||
f.close()
|
||||
|
||||
sum -= i
|
||||
// println('sum: ${sum}')
|
||||
|
||||
// parse the temp file
|
||||
mut csvr := csv.csv_reader(
|
||||
file_path: file_path_str
|
||||
mem_buf_size: 32
|
||||
end_line_len: csv.endline_cr_len
|
||||
)!
|
||||
|
||||
mut sum1 := u64(0)
|
||||
for row_index in 0 .. csvr.csv_map.len {
|
||||
row := csvr.get_row(row_index)!
|
||||
for x in row {
|
||||
sum1 += u64(x.int())
|
||||
}
|
||||
}
|
||||
// println('sum: ${sum1}')
|
||||
|
||||
csvr.dispose_csv_reader()
|
||||
|
||||
// remove the temp file
|
||||
os.rm(file_path_str)!
|
||||
|
||||
assert sum == sum1, 'csv coherence test failed'
|
||||
}
|
||||
|
||||
// Debug code
|
||||
fn main() {
|
||||
test_csv_string()
|
||||
|
Loading…
x
Reference in New Issue
Block a user