bug eliminated from _words_ reading
This commit is contained in:
parent
17c5ed073c
commit
6d1d3da1fe
|
@ -61,13 +61,19 @@
|
|||
(read-chunks f read-line reverse))
|
||||
|
||||
(def-reader (read-as-words f)
|
||||
(define lines (read-chunks f read-line reverse))
|
||||
(foldr (lambda (f r) (append (split f) r)) '() lines))
|
||||
(read-as-words/line/internal f append))
|
||||
|
||||
(def-reader (read-as-words/line f)
|
||||
;; String -> [Listof [Listof String]]
|
||||
;; read the specified file as a list of lines, each line as a list of words
|
||||
(map split (read-chunks f read-line reverse)))
|
||||
(read-as-words/line/internal f cons))
|
||||
|
||||
(define (read-as-words/line/internal f combine)
|
||||
(define lines (read-chunks f read-line (lambda (x) x)))
|
||||
(foldl (lambda (f r)
|
||||
(define fst (filter (compose not (curry string=? "")) (split f)))
|
||||
(if (empty? fst) r (combine fst r)))
|
||||
'() lines))
|
||||
|
||||
(def-reader (read-as-csv f)
|
||||
(read-as-csv/func f))
|
||||
|
|
|
@ -45,6 +45,19 @@ eos
|
|||
(write-file file test2)
|
||||
(check-equal? (read-as-1strings file) as-1strings2 "as-lines 2")
|
||||
|
||||
(define test2-a-as-list '("test1" "" "test2"))
|
||||
|
||||
(define test2-a
|
||||
(apply string-append
|
||||
(list (first test2-as-list)
|
||||
(string #\newline)
|
||||
(string #\newline)
|
||||
(second test2-as-list))))
|
||||
|
||||
(write-file file test2-a)
|
||||
(check-equal? (read-as-lines file) test2-a-as-list "as-lines 2-a")
|
||||
(check-equal? (read-as-words file) '("test1" "test2") "as-words 2-a")
|
||||
|
||||
(define test3 #<< eos
|
||||
word1, word2
|
||||
word3, word4
|
||||
|
@ -59,7 +72,7 @@ eos
|
|||
(check-equal? (read-as-csv file) '(("word1" "word2") ("word3" "word4"))
|
||||
"as-cvs 1")
|
||||
(check-equal? (read-as-csv/rows file length) '(2 2)
|
||||
"as-words/rows")
|
||||
"as-csv/rows")
|
||||
|
||||
|
||||
(check-exn exn:fail:contract? (lambda () (write-file 0 1)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user