Add testing of CSV lines parsing.
This commit is contained in:
parent
0d7a7f765c
commit
e1b673a519
2 changed files with 11 additions and 4 deletions
|
@ -80,11 +80,10 @@
|
||||||
(cons (string-append (car res) token) (cdr res))
|
(cons (string-append (car res) token) (cdr res))
|
||||||
2)))))))) ; Continue inside quoted data
|
2)))))))) ; Continue inside quoted data
|
||||||
|
|
||||||
;; Loads given CSV file and parses its lines into lists
|
;; Parses given CSV lines list
|
||||||
(define (csv-parse fn . args)
|
(define (csv-parse-lines lines . args)
|
||||||
(let* ((separator (get-keyword #:separator args (lambda () ";")))
|
(let* ((separator (get-keyword #:separator args (lambda () ";")))
|
||||||
(string-delimiter (get-keyword #:string-delimiter args (lambda () "\"")))
|
(string-delimiter (get-keyword #:string-delimiter args (lambda () "\"")))
|
||||||
(lines (read-lines (open-input-file fn)))
|
|
||||||
(csv-parse-line (make-csv-line-parser separator string-delimiter))
|
(csv-parse-line (make-csv-line-parser separator string-delimiter))
|
||||||
(total (max (sub1 (length lines)) 1)))
|
(total (max (sub1 (length lines)) 1)))
|
||||||
(let loop ((lines lines)
|
(let loop ((lines lines)
|
||||||
|
@ -98,6 +97,11 @@
|
||||||
(add1 idx)
|
(add1 idx)
|
||||||
(cons (csv-parse-line line)
|
(cons (csv-parse-line line)
|
||||||
res)))))))
|
res)))))))
|
||||||
|
|
||||||
|
;; Loads given CSV file and parses its lines into lists
|
||||||
|
(define (csv-parse fn . args)
|
||||||
|
(let ((lines (read-lines (open-input-file fn))))
|
||||||
|
(apply csv-parse-lines lines args)))
|
||||||
|
|
||||||
;; Splits CSV into header and body based on the first empty row.
|
;; Splits CSV into header and body based on the first empty row.
|
||||||
(define (csv-split-header csv)
|
(define (csv-split-header csv)
|
||||||
|
@ -128,6 +132,9 @@
|
||||||
(test-equal? csv-split-header
|
(test-equal? csv-split-header
|
||||||
(csv-split-header '((1 2) (5 6) (3 4)))
|
(csv-split-header '((1 2) (5 6) (3 4)))
|
||||||
'(((1 2) (5 6) (3 4)) ()))
|
'(((1 2) (5 6) (3 4)) ()))
|
||||||
|
(test-equal? csv-parse-lines
|
||||||
|
(csv-parse-lines '("a;b;c" "1;2"))
|
||||||
|
'(("a" "b" "c") ("1" "2")))
|
||||||
))
|
))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -122,7 +122,7 @@
|
||||||
(* value (*progress%-width*)))))
|
(* value (*progress%-width*)))))
|
||||||
(swidth (- (*progress%-width*) bwidth)))
|
(swidth (- (*progress%-width*) bwidth)))
|
||||||
(display
|
(display
|
||||||
(sprintf "\r[~A~A]~A% ~A"
|
(sprintf "\r[~A~A] ~A% ~A"
|
||||||
(make-string bwidth #\=)
|
(make-string bwidth #\=)
|
||||||
(make-string swidth #\space)
|
(make-string swidth #\space)
|
||||||
ivalue%
|
ivalue%
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue