File tree Expand file tree Collapse file tree 2 files changed +51
-3
lines changed Expand file tree Collapse file tree 2 files changed +51
-3
lines changed Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ pub fn (mut cr RandomAccessReader) map_csv() ! {
252
252
// println("${i:-12d} of ${cr.f_len:-12d} readed: ${read_bytes_count}")
253
253
mut p1 := p
254
254
mut i1 := i64 (0 )
255
- for i1 < = read_bytes_count {
255
+ for i1 < read_bytes_count {
256
256
// println("loop char: ${*&u8(p1):c}")
257
257
// manage quote char
258
258
if * p1 == cr.quote {
@@ -529,7 +529,7 @@ pub fn (mut cr RandomAccessReader) rows_count() !i64 {
529
529
// println("${i:-12d} of ${cr.f_len:-12d} readed: ${read_bytes_count}")
530
530
mut p1 := p
531
531
mut i1 := 0
532
- for i1 < = read_bytes_count {
532
+ for i1 < read_bytes_count {
533
533
if * p1 == cr.end_line {
534
534
count++
535
535
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ This file contains tests
10
10
Known limitations:
11
11
*/
12
12
import encoding.csv
13
+ import strings
13
14
import os
14
15
15
16
/* *****************************************************************************
@@ -267,7 +268,7 @@ fn test_csv_string() {
267
268
// parse the temp file
268
269
csvr = csv.csv_reader (
269
270
file_path: file_path_str
270
- mem_buf_size: 64
271
+ mem_buf_size: 32
271
272
end_line_len: csv.endline_crlf_len
272
273
)!
273
274
perform_test (mut csvr)!
@@ -295,6 +296,53 @@ fn test_csv_string() {
295
296
csvr.dispose_csv_reader ()
296
297
}
297
298
299
+ fn test_coherence () {
300
+ file_path_str := os.join_path (os.temp_dir (), 'test_csv.csv' )
301
+ mut f := os.open_file (file_path_str, 'w' )!
302
+ mut b := strings.new_builder (64536 )
303
+ mut i := u64 (0 )
304
+ mut sum := u64 (0 )
305
+ for rows in 0 .. 1000 {
306
+ for col in 0 .. 1000 {
307
+ if col > 0 {
308
+ b.write_u8 (`,` )
309
+ }
310
+ b.write_string (i.str ())
311
+ i++
312
+ sum + = i
313
+ }
314
+ b.write_string ('\n ' )
315
+ }
316
+ f.write_string (b.str ())!
317
+ f.close ()
318
+
319
+ sum - = i
320
+ // println('sum: ${sum}')
321
+
322
+ // parse the temp file
323
+ mut csvr := csv.csv_reader (
324
+ file_path: file_path_str
325
+ mem_buf_size: 32
326
+ end_line_len: csv.endline_cr_len
327
+ )!
328
+
329
+ mut sum1 := u64 (0 )
330
+ for row_index in 0 .. csvr.csv_map.len {
331
+ row := csvr.get_row (row_index)!
332
+ for x in row {
333
+ sum1 + = u64 (x.int ())
334
+ }
335
+ }
336
+ // println('sum: ${sum1}')
337
+
338
+ csvr.dispose_csv_reader ()
339
+
340
+ // remove the temp file
341
+ os.rm (file_path_str)!
342
+
343
+ assert sum == sum1 , 'csv coherence test failed'
344
+ }
345
+
298
346
// Debug code
299
347
fn main () {
300
348
test_csv_string ()
You can’t perform that action at this time.
0 commit comments