-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
931 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
(define-library (chibi csv-test) | ||
(import (scheme base) | ||
(srfi 227) | ||
(chibi csv) | ||
(chibi test)) | ||
(export run-tests) | ||
(begin | ||
(define string->csv | ||
(opt-lambda (str (reader (csv-read->list))) | ||
(reader (open-input-string str)))) | ||
(define (run-tests) | ||
(test-begin "(chibi csv)") | ||
(test-assert (eof-object? (string->csv ""))) | ||
(test '("1997" "Ford" "E350") | ||
(string->csv "1997,Ford,E350")) | ||
(test '("1997" "Ford" "E350") | ||
(string->csv "\n1997,Ford,E350")) | ||
(test '(" ") | ||
(string->csv " \n1997,Ford,E350")) | ||
(test '("" "") | ||
(string->csv ",\n1997,Ford,E350")) | ||
(test '("1997" "Ford" "E350") | ||
(string->csv "\"1997\",\"Ford\",\"E350\"")) | ||
(test '("1997" "Ford" "E350" "Super, luxurious truck") | ||
(string->csv "1997,Ford,E350,\"Super, luxurious truck\"")) | ||
(test '("1997" "Ford" "E350" "Super, \"luxurious\" truck") | ||
(string->csv "1997,Ford,E350,\"Super, \"\"luxurious\"\" truck\"")) | ||
(test '("1997" "Ford" "E350" "Go get one now\nthey are going fast") | ||
(string->csv "1997,Ford,E350,\"Go get one now | ||
they are going fast\"")) | ||
(test '("1997" "Ford" "E350") | ||
(string->csv | ||
"# this is a comment\n1997,Ford,E350" | ||
(csv-read->list | ||
(csv-parser (csv-grammar '((comment-chars #\#))))))) | ||
(test '("1997" "Fo\"rd" "E3\"50") | ||
(string->csv "1997\tFo\"rd\tE3\"50" | ||
(csv-read->list (csv-parser default-tsv-grammar)))) | ||
(test '#("1997" "Ford" "E350") | ||
(string->csv "1997,Ford,E350" (csv-read->vector))) | ||
(test '#("1997" "Ford" "E350") | ||
(string->csv "1997,Ford,E350" (csv-read->fixed-vector 3))) | ||
(test-error | ||
(string->csv "1997,Ford,E350" (csv-read->fixed-vector 2))) | ||
(let ((city-csv "Los Angeles,34°03′N,118°15′W | ||
New York City,40°42′46″N,74°00′21″W | ||
Paris,48°51′24″N,2°21′03″E")) | ||
(test '(*TOP* | ||
(row (col-0 "Los Angeles") | ||
(col-1 "34°03′N") | ||
(col-2 "118°15′W")) | ||
(row (col-0 "New York City") | ||
(col-1 "40°42′46″N") | ||
(col-2 "74°00′21″W")) | ||
(row (col-0 "Paris") | ||
(col-1 "48°51′24″N") | ||
(col-2 "2°21′03″E"))) | ||
((csv->sxml) (open-input-string city-csv))) | ||
(test '(*TOP* | ||
(city (name "Los Angeles") | ||
(latitude "34°03′N") | ||
(longitude "118°15′W")) | ||
(city (name "New York City") | ||
(latitude "40°42′46″N") | ||
(longitude "74°00′21″W")) | ||
(city (name "Paris") | ||
(latitude "48°51′24″N") | ||
(longitude "2°21′03″E"))) | ||
((csv->sxml 'city '(name latitude longitude)) | ||
(open-input-string city-csv)))) | ||
(test-end)))) |
Oops, something went wrong.