From 290104da0a2065c203eea958fcd0168807ac5bd7 Mon Sep 17 00:00:00 2001 From: chetz Date: Mon, 9 Aug 2004 08:49:16 +0000 Subject: [PATCH] first commit --- scsh/test/read-delimited-strings.scm | 125 +++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 scsh/test/read-delimited-strings.scm diff --git a/scsh/test/read-delimited-strings.scm b/scsh/test/read-delimited-strings.scm new file mode 100644 index 0000000..bb8d0ae --- /dev/null +++ b/scsh/test/read-delimited-strings.scm @@ -0,0 +1,125 @@ +;;; Test for the function in section 7 of the scsh-manual "Reading Dlimited strings" +;;; Author: Christoph Hetz + +;; for testing: (certainly the path will be an other on other systems...) + +;; ,open define-record-types handle +;; ,config ,load C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-packages.scm +;; ,load C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-base.scm +;; load this file +;; (test-all) + + +(add-test! 'read-line-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-line in-port)) + (equal? "zeile 2" + (read-line in-port)) + (equal? "zeile 3" + (read-line in-port)))) + (make-string-input-port "zeile 1\nzeile 2\nzeile 3")))) + +(add-test! 'read-line-trim-test 'reading-delimited-strings ;; same as without trim + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-line in-port 'trim)) + (equal? "zeile 2" + (read-line in-port 'trim)) + (equal? "zeile 3" + (read-line in-port 'trim)))) + (make-string-input-port "zeile 1\nzeile 2\nzeile 3")))) + +(add-test! 'read-line-peek-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-line in-port 'peek)) + (equal? "" + (read-line in-port 'peek)) + (equal? "" + (read-line in-port 'peek)))) + (make-string-input-port "zeile 1\nzeile 2\nzeile 3")))) + +(add-test! 'read-line-concat-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1\n" + (read-line in-port 'concat)) + (equal? "zeile 2\n" + (read-line in-port 'concat)) + (equal? "zeile 3\n" + (read-line in-port 'concat)))) + (make-string-input-port "zeile 1\nzeile 2\nzeile 3\n")))) ;; XXX klappt mit dem eof irgendwie nicht + +(add-test! 'read-line-split-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (call-with-values (lambda () (read-line in-port 'split)) + (lambda (a b) (and (equal? a "zeile 1") + (equal? b #\newline)))) + (call-with-values (lambda () (read-line in-port 'split)) + (lambda (a b) (and (equal? a "zeile 2") + (equal? b #\newline)))) + (call-with-values (lambda () (read-line in-port 'split)) + (lambda (a b) (and (equal? a "zeile 3") + (equal? b #\newline)))))) + (make-string-input-port "zeile 1\nzeile 2\nzeile 3\n")))) ;; XXX vorhin ging's hier noch - jetzt nicht mehr (\#eof) + +(add-test! 'read-paragraph-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1\nzeile 2\nparagraph 1\n" + (read-paragraph in-port)) + (equal? "zeile 1\nparagraph 2\n" + (read-paragraph in-port)) + (equal? "zeile 1\nparagraph 3\n" + (read-paragraph in-port)))) + (make-string-input-port "zeile 1\nzeile 2\nparagraph 1\n\nzeile 1\nparagraph 2\n \t\nzeile 1\nparagraph 3\n\n")))) + +(add-test! 'read-paragraph-trim-test 'reading-delimited-strings ;; same as without trim + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1\nzeile 2\nparagraph 1\n" + (read-paragraph in-port 'trim)) + (equal? "zeile 1\nparagraph 2\n" + (read-paragraph in-port 'trim)) + (equal? "zeile 1\nparagraph 3\n" + (read-paragraph in-port 'trim)))) + (make-string-input-port "zeile 1\nzeile 2\nparagraph 1\n\nzeile 1\nparagraph 2\n \t\nzeile 1\nparagraph 3\n\n")))) + +(add-test! 'read-paragraph-concat-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1\nzeile 2\nparagraph 1\n\n" + (read-paragraph in-port 'concat)) + (equal? "zeile 1\nparagraph 2\n \t\n" + (read-paragraph in-port 'concat)) + (equal? "zeile 1\nparagraph 3\n\n" + (read-paragraph in-port 'concat)))) + (make-string-input-port "zeile 1\nzeile 2\nparagraph 1\n\nzeile 1\nparagraph 2\n \t\nzeile 1\nparagraph 3\n\n")))) + +(add-test! 'read-paragraph-split-test 'reading-delimited-strings + (lambda () + ((lambda (in-port) + (and (call-with-values (lambda () (read-paragraph in-port 'split)) + (lambda (a b) +; (display "a1: ")(display a) +; (display "b1: ")(display b) + (and (equal? a "zeile 1\nzeile 2\nparagraph 1\n") + (equal? b "\n")))) + (call-with-values (lambda () (read-paragraph in-port 'split)) + (lambda (a b) +; (display "a2: ")(display a) +; (display "b2: ")(display b) + (and (equal? a "zeile 1\nparagraph 2\n") + (equal? b " \t\n")))) + (call-with-values (lambda () (read-paragraph in-port 'split)) + (lambda (a b) +; (display "a3: ")(display a) +; (display "b3: ")(display b) + (and (equal? a "zeile 1\nparagraph 3\n") + (equal? b "\n")))))) + (make-string-input-port "zeile 1\nzeile 2\nparagraph 1\n\nzeile 1\nparagraph 2\n \t\nzeile 1\nparagraph 3\n\n")))) \ No newline at end of file