(use test) (use magic-pipes-runtime) (test-group "alists" (test "alist-modify" '((a . 1) (b . 3) (c . 3)) (alist-modify (list (cons 'b (lambda (x) (+ x 1))) (cons 'd (lambda (x) (* x 2)))) '((a . 1) (b . 2) (c . 3)))) (test "alist-modifier" '((a . 1) (b . 3) (c . 3)) ((alist-modifier (list (cons 'b (lambda (x) (+ x 1))) (cons 'd (lambda (x) (* x 2))))) '((a . 1) (b . 2) (c . 3)))) (test "alist-project" '((a . 1) (c . 3) (d . 4)) (alist-project '(a c (d . 4)) '((a . 1) (b . 2) (c . 3)))) (test "alist-projector" '((a . 1) (c . 3) (d . 4)) ((alist-projector '(a c (d . 4))) '((a . 1) (b . 2) (c . 3)))) ) (test-group "mpcsv-read" (for-each (lambda (file) (when (string-suffix? ".csv" file) (test-group file (let* ((base-filename (make-pathname "csv" (string-drop-right file 4))) (csv-filename (string-append base-filename ".csv")) (expected-result-filename (string-append base-filename ".out")) (flags-filename (string-append base-filename ".flags")) (flags (if (file-exists? flags-filename) (string-trim-right (with-input-from-file flags-filename read-string)) ""))) (call-with-input-file expected-result-filename (lambda (expected-results) (with-input-from-pipe (string-append "mpcsv-read " flags " < " csv-filename) (lambda () (let loop () (let ((expected-record (read expected-results)) (actual-record (read))) (if (eof-object? expected-record) (test "eof" expected-record actual-record) (test "record" expected-record actual-record)) (unless (and (eof-object? expected-record) (eof-object? actual-record)) (loop)))))))))))) (directory "csv"))) (test-group "mpcsv-write" (for-each (lambda (file) (when (string-suffix? ".sexpr" file) (test-group file (let* ((base-filename (make-pathname "csv" (string-drop-right file 6))) (sexpr-filename (string-append base-filename ".sexpr")) (expected-result-filename (string-append base-filename ".out")) (flags-filename (string-append base-filename ".flags")) (flags (if (file-exists? flags-filename) (string-trim-right (with-input-from-file flags-filename read-string)) ""))) (call-with-input-file expected-result-filename (lambda (expected-results) (with-input-from-pipe (string-append "mpcsv-write " flags " < " sexpr-filename) (lambda () (let ((expected-content (read-string #f expected-results)) (actual-content (read-string))) (test "result" expected-content actual-content)))))))))) (directory "csv"))) (printf "Final count of failures: ~a\n" (test-failure-count)) (test-exit)