From 3c4a6c7c468b1829816f1444112acf89af45d3f1 Mon Sep 17 00:00:00 2001 From: chetz Date: Tue, 10 Aug 2004 11:50:22 +0000 Subject: [PATCH] some more test cases --- scsh/test/read-delimited-strings.scm | 206 ++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 2 deletions(-) diff --git a/scsh/test/read-delimited-strings.scm b/scsh/test/read-delimited-strings.scm index bb8d0ae..3def5fc 100644 --- a/scsh/test/read-delimited-strings.scm +++ b/scsh/test/read-delimited-strings.scm @@ -1,4 +1,4 @@ -;;; Test for the function in section 7 of the scsh-manual "Reading Dlimited strings" +;;; Test for the function in section 7 of the scsh-manual "Reading Delimited strings" ;;; Author: Christoph Hetz ;; for testing: (certainly the path will be an other on other systems...) @@ -122,4 +122,206 @@ ; (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 + (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-delimited-with-char-set-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited (list->char-set (list #\a #\b #\:)) in-port)) + (equal? " nix\nzeile 2: x" + (read-delimited (list->char-set (list #\a #\b #\y)) in-port)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-trim-with-char-set-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited (list->char-set (list #\a #\b #\:)) in-port 'trim)) + (equal? " nix\nzeile 2: x" + (read-delimited (list->char-set (list #\a #\b #\y)) in-port 'trim)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-peek-with-char-set-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited (list->char-set (list #\a #\b #\:)) in-port 'peek)) + (equal? ": nix\nzeile 2: x" + (read-delimited (list->char-set (list #\a #\b #\y)) in-port 'peek)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-concat-with-char-set-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1:" + (read-delimited (list->char-set (list #\a #\b #\:)) in-port 'concat)) + (equal? " nix\nzeile 2: xy" + (read-delimited (list->char-set (list #\a #\b #\y)) in-port 'concat)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-split-with-char-set-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (call-with-values + (lambda () (read-delimited (list->char-set (list #\a #\b #\:)) in-port 'split)) + (lambda (a b) (and (equal? "zeile 1" a) + (equal? #\: b)))) + (call-with-values + (lambda () (read-delimited (list->char-set (list #\a #\b #\y)) in-port 'split)) + (lambda (a b) (and (equal? " nix\nzeile 2: x" a) + (equal? #\y b)))))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +;;------------------------------------------------------------------------------------------------------------------------ + +(add-test! 'read-delimited-with-string-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited "ab:" in-port)) + (equal? " nix\nzeile 2: x" + (read-delimited "aby" in-port)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-trim-with-string-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited "ab:" in-port 'trim)) + (equal? " nix\nzeile 2: x" + (read-delimited "aby" in-port 'trim)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-peek-with-string-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited "ab:" in-port 'peek)) + (equal? ": nix\nzeile 2: x" + (read-delimited "aby" in-port 'peek)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-concat-with-string-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1:" + (read-delimited "ab:" in-port 'concat)) + (equal? " nix\nzeile 2: xy" + (read-delimited "aby" in-port 'concat)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-split-with-string-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (call-with-values + (lambda () (read-delimited "ab:" in-port 'split)) + (lambda (a b) (and (equal? "zeile 1" a) + (equal? #\: b)))) + (call-with-values + (lambda () (read-delimited "aby" in-port 'split)) + (lambda (a b) (and (equal? " nix\nzeile 2: x" a) + (equal? #\y b)))))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +;; --------------------------------------------------------------------------------------------------- + +(add-test! 'read-delimited-with-character-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited #\: in-port)) + (equal? " nix\nzeile 2: x" + (read-delimited #\y in-port)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-trim-with-character-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited #\: in-port 'trim)) + (equal? " nix\nzeile 2: x" + (read-delimited #\y in-port 'trim)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-peek-with-character-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1" + (read-delimited #\: in-port 'peek)) + (equal? ": nix\nzeile 2: x" + (read-delimited #\y in-port 'peek)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-concat-with-character-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile 1:" + (read-delimited #\: in-port 'concat)) + (equal? " nix\nzeile 2: xy" + (read-delimited #\y in-port 'concat)))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +(add-test! 'read-delimited-split-with-character-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (call-with-values + (lambda () (read-delimited #\: in-port 'split)) + (lambda (a b) (and (equal? "zeile 1" a) + (equal? #\: b)))) + (call-with-values + (lambda () (read-delimited #\y in-port 'split)) + (lambda (a b) (and (equal? " nix\nzeile 2: x" a) + (equal? #\y b)))))) + (make-string-input-port "zeile 1: nix\nzeile 2: xy\nzeile 3: wieder nix\n")))) + +;; --------------------------------------------------------------------------------------------------- + +(add-test! 'read-delimited-with-character-predicate-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile a" + (read-delimited char-digit? in-port)) + (equal? " nix\nzeile b1 x" + (read-delimited char-digit? in-port)))) + (make-string-input-port "zeile a1 nix\nzeile b1 x2\nzeile c1 wieder nix\n")))) + +(add-test! 'read-delimited-trim-with-character-predicate-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile a" + (read-delimited char-digit? in-port 'trim)) + (equal? " nix\nzeile b1 x" + (read-delimited char-digit? in-port 'trim)))) + (make-string-input-port "zeile a1 nix\nzeile b1 x2\nzeile c1 wieder nix\n")))) + +(add-test! 'read-delimited-peek-with-character-predicate-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile a" + (read-delimited char-digit? in-port 'peek)) + (equal? "1 nix\nzeile b1 x" + (read-delimited char-digit? in-port 'peek)))) + (make-string-input-port "zeile a1 nix\nzeile b1 x2\nzeile c1 wieder nix\n")))) + +(add-test! 'read-delimited-concat-with-character-predicate-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (equal? "zeile a1" + (read-delimited char-digit? in-port 'concat)) + (equal? " nix\nzeile b1 x2" + (read-delimited char-digit? in-port 'concat)))) + (make-string-input-port "zeile a1 nix\nzeile b1 x2\nzeile c1 wieder nix\n")))) + +(add-test! 'read-delimited-split-with-character-predicate-test 'read-delimited-strings + (lambda () + ((lambda (in-port) + (and (call-with-values + (lambda () (read-delimited char-digit? in-port 'split)) + (lambda (a b) (and (equal? "zeile a" a) + (equal? #\1 b)))) + (call-with-values + (lambda () (read-delimited char-digit? in-port 'split)) + (lambda (a b) (and (equal? " nix\nzeile b1 x" a) + (equal? #\2 b)))))) + (make-string-input-port "zeile a1 nix\nzeile b1 x2\nzeile c1 wieder nix\n")))) \ No newline at end of file