works with string-ports instead

of temp-files now
This commit is contained in:
chetz 2004-08-09 15:24:43 +00:00
parent 290104da0a
commit c7d103da99
1 changed files with 232 additions and 356 deletions

View File

@ -4,8 +4,8 @@
;; for testing: (certainly the path will be an other on other systems...) ;; for testing: (certainly the path will be an other on other systems...)
;; ,open define-record-types handle ;; ,open define-record-types handle
;; ,config ,load C:/cygwin/home/mephisto/cvs_scsh/scsh/scsh/test/test-packages.scm ;; ,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 C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-base.scm
;; load this file ;; load this file
;; (test-all) ;; (test-all)
@ -43,37 +43,30 @@
(add-test! 'counter-inc-test 'awk (add-test! 'counter-inc-test 'awk
(lambda () (lambda ()
(let ((read '()) (let ((read '())
(tmp-file (create-temp-file))) (string (let loop ((i 0))
(call-with-output-file tmp-file (if (not (= 9 i))
(lambda (out-port) (begin
(let loop ((i 0)) (string-append "test-zeile\n"
(if (not (= 9 i)) (loop (+ i 1))))
(begin ""))))
(write "test-zeile\n" out-port) ((lambda (in-port)
(loop (+ i 1))))))) (awk (read-line in-port) (line) counter ()
(#t (set! read (cons counter read)))))
(call-with-input-file tmp-file (make-string-input-port string))
(lambda (in-port) (equal? read '(9 8 7 6 5 4 3 2 1)))))
(awk (read-line in-port) (line) counter ()
(#t (set! read (cons counter read))))))
(delete-file tmp-file)
(equal? read '(10 9 8 7 6 5 4 3 2 1)))))
;; --- does the "int-test" work properly --- ;; --- does the "int-test" work properly ---
(add-test! 'int-test-test 'awk (add-test! 'int-test-test 'awk
(lambda () (lambda ()
(let ((read '()) (let ((read '())
(tmp-file (create-temp-file))) (string (let loop ((i 0))
(call-with-output-file tmp-file (if (not (= 9 i))
(lambda (out-port) (begin
(let loop ((i 0)) (string-append "test-zeile\n"
(if (not (= 20 i)) (loop (+ i 1))))
(begin ""))))
(write "test-zeile\n" out-port) ((lambda (in-port)
(loop (+ i 1)))))))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) counter () (awk (read-line in-port) (line) counter ()
(1 (set! read (cons 1 read))) (1 (set! read (cons 1 read)))
(2 (set! read (cons 2 read))) (2 (set! read (cons 2 read)))
@ -84,38 +77,27 @@
(7 (set! read (cons 7 read))) (7 (set! read (cons 7 read)))
(8 (set! read (cons 8 read))) (8 (set! read (cons 8 read)))
(9 (set! read (cons 9 read))) (9 (set! read (cons 9 read)))
(0 (set! read (cons 0 read)))))) (0 (set! read (cons 0 read)))))
(delete-file tmp-file) (make-string-input-port string))
(equal? read '(9 8 7 6 5 4 3 2 1))))) (equal? read '(9 8 7 6 5 4 3 2 1)))))
;; --- big line --- ;; --- big line ---
(add-test! 'read-one-mb-line-from-file 'awk ;(add-test! 'read-one-mb-line-from-file 'awk
(lambda () ; (lambda ()
(let ((one-kb-line (let loop ((i 0)) ; (let ((one-mb-line (let loop ((i 0))
(if (= 1024 i) ; (if (= 1048576 i)
"" ; ""
(string-append "a" (loop (+ i 1)))))) ; (string-append "a" (loop (+ i 1))))))
(tmp-file (create-temp-file)) ; (read '()))
(read '())) ; ((lambda (in-port)
; (awk (read-line in-port) (line) c ()
(call-with-output-file tmp-file ; (#t (begin
(lambda (out-port) ; (set! read line)))))
(let loop ((i 0)) ; (make-string-input-port one-mb-line))
(if (= 1024 i) ; (and (string? read)
(write-string "" out-port) ; (= (string-length read)
(begin ; 1048576)))))
(write-string one-kb-line out-port)
(loop (+ i 1)))))))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) c ()
(#t (begin
(set! read line))))))
(delete-file tmp-file)
(and (string? read)
(= (string-length read)
(* 1024 1024))))))
;; --- special signs --- ;; --- special signs ---
@ -124,48 +106,38 @@
(let (( strange-sign-line (let (( strange-sign-line
(let loop ((i 0)) (let loop ((i 0))
(if (= i 256) (if (= i 256)
"" "\n"
(if (= i 10) ;; comes along with everything but line-feed (if (= i 10) ;; works with everything but line-feed
(loop (+ i 1)) (loop (+ i 1))
(string-append (ascii->string i) (string-append (ascii->string i)
(loop (+ i 1))))))) (loop (+ i 1)))))))
(tmp-file (create-temp-file))
(read '())) (read '()))
(call-with-output-file tmp-file ((lambda (in-port)
(lambda (out-port)
(write-string strange-sign-line out-port)
(write-string "\n" out-port)))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) () (awk (read-line in-port) (line) ()
(#t (set! read line))))) (#t (set! read line))))
(delete-file tmp-file) (make-string-input-port strange-sign-line))
(equal? read strange-sign-line)))) (equal? (string-append read "\n") strange-sign-line))))
;; --- sre-expr-test --- ;; --- sre-expr-test ---
(add-test! 'sre-expr-test-test 'awk (add-test! 'sre-expr-test-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "sre-expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "sre-expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port)
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port)))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) () (awk (read-line in-port) (line) ()
(("sre" "zu") (set! read (cons 'sre-zu read))) (("sre" "zu") (set! read (cons 'sre-zu read)))
("eine" (set! read (cons 'eine read))) ("eine" (set! read (cons 'eine read)))
("EINE" (set! read (cons 'EINE read))) ("EINE" (set! read (cons 'EINE read)))
((* "3") (set! read (cons '*3 read))) ((* "3") (set! read (cons '*3 read)))
((? "s") (set! read (cons '?s read))) ((? "s") (set! read (cons '?s read)))
((+ "+") (set! read (cons '++ read)))))) ((+ "+") (set! read (cons '++ read)))))
(delete-file tmp-file) (make-string-input-port str))
;; |z6 |z5 |z4 |z3 |z2 |z1 | ;; |z6 |z5 |z4 |z3 |z2 |z1 |
(equal? (list '++ '?s '*3 '?s '*3 'eine 'sre-zu '?s '*3 'eine 'sre-zu '?s '*3 'EINE '?s '*3 'sre-zu '?s '*3 'sre-zu) (equal? (list '++ '?s '*3 '?s '*3 'eine 'sre-zu '?s '*3 'eine 'sre-zu '?s '*3 'EINE '?s '*3 'sre-zu '?s '*3 'sre-zu)
read)))) read))))
@ -174,27 +146,23 @@
(add-test! 'when-bool-exp-test-test 'awk (add-test! 'when-bool-exp-test-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "when-bool-expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "when-bool-expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) ((when (= counter 1))
(call-with-input-file tmp-file (set! read (cons 'first-clause read)))
(lambda (in-port) ((when (equal? line
(awk (read-line in-port) (line) counter () "when-bool-expr-test zu prüfen:"))
((when (= counter 1)) (set! read (cons 'second-clause read)))
(set! read (cons 'first-clause read))) ((when (> counter 2))
((when (equal? line (set! read (cons 'third-clause read)))))
"when-bool-expr-test zu prüfen:")) (make-string-input-port str))
(set! read (cons 'second-clause read)))
((when (> counter 2))
(set! read (cons 'third-clause read))))))
(delete-file tmp-file)
(equal? read (equal? read
(list 'third-clause 'third-clause 'third-clause 'third-clause 'second-clause 'first-clause))))) (list 'third-clause 'third-clause 'third-clause 'third-clause 'second-clause 'first-clause)))))
@ -202,28 +170,24 @@
(add-test! 'expr-test-test 'awk (add-test! 'expr-test-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) ("paar" (set! read (cons 'first-clause read)))
(call-with-input-file tmp-file ((equal? line
(lambda (in-port) "expr-test zu prüfen:")
(awk (read-line in-port) (line) counter () (set! line (cons 'second-clause read)))
("paar" (set! read (cons 'first-clause read))) ((> counter 5)
((equal? line (set! read (cons 'third-clause read)))
"expr-test zu prüfen:") ((+ "3") ;; makes problems here, but was ok in sre-xpr-test ;;FIXXX it
(set! line (cons 'second-clause read))) (set! read (cons 'fourth-clause read)))))
((> counter 5) (make-string-input-port str))
(set! read (cons 'third-clause read)))
((+ "3") ;; makes problems here, but was ok in sre-xpr-test ;;FIXXX it
(set! read (cons 'fourth-clause read))))))
(delete-file tmp-file)
(equal? read (equal? read
(list 'third-clause 'fourth-clause 'second-clause 'first-clause))))) (list 'third-clause 'fourth-clause 'second-clause 'first-clause)))))
@ -232,28 +196,24 @@
(add-test! 'several-bodys-in-clause-test 'awk (add-test! 'several-bodys-in-clause-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) (1 (set! read (cons 'clause-one-body-one read))
(call-with-input-file tmp-file (set! read (cons 'clause-one-body-two read))
(lambda (in-port) (set! read (cons 'clause-one-body-three read)))
(awk (read-line in-port) (line) counter () ((when (equal? line
(1 (set! read (cons 'clause-one-body-one read)) "eine zeile klein..."))
(set! read (cons 'clause-one-body-two read)) (set! read (cons 'clause-two-body-one read))
(set! read (cons 'clause-one-body-three read))) (set! read (cons 'clause-two-body-two read))
((when (equal? line (set! read (cons 'clause-two-body-three read)))))
"eine zeile klein...")) (make-string-input-port str))
(set! read (cons 'clause-two-body-one read))
(set! read (cons 'clause-two-body-two read))
(set! read (cons 'clause-two-body-three read))))))
(delete-file tmp-file)
(equal? read (equal? read
(list 'clause-two-body-three 'clause-two-body-two 'clause-two-body-one (list 'clause-two-body-three 'clause-two-body-two 'clause-two-body-one
'clause-one-body-three 'clause-one-body-two 'clause-one-body-one))))) 'clause-one-body-three 'clause-one-body-two 'clause-one-body-one)))))
@ -263,30 +223,26 @@
(add-test! 'range-wo-begin-wo-end-test 'awk (add-test! 'range-wo-begin-wo-end-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) (range 1 3 (set! read (cons 'first-clause read)))
(call-with-input-file tmp-file (range (when (equal? line
(lambda (in-port) "EINE ZEILE GRO/3..."))
(awk (read-line in-port) (line) counter () (when (equal? line
(range 1 3 (set! read (cons 'first-clause read))) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}"))
(range (when (equal? line (set! read (cons 'second-clause read)))
"EINE ZEILE GRO/3...")) (range (when (equal? line
(when (equal? line "expr-test zu prüfen:"))
"*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}")) 4
(set! read (cons 'second-clause read))) (set! read (cons 'third-clause read)))))
(range (when (equal? line (make-string-input-port str))
"expr-test zu prüfen:"))
4
(set! read (cons 'third-clause read))))))
(delete-file tmp-file)
(equal? read (equal? read
(list 'second-clause 'second-clause 'third-clause 'first-clause))))) (list 'second-clause 'second-clause 'third-clause 'first-clause)))))
@ -295,30 +251,26 @@
(add-test! 'range-w-begin-wo-end-test 'awk (add-test! 'range-w-begin-wo-end-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) (:range 1 3 (set! read (cons 'first-clause read)))
(call-with-input-file tmp-file (:range (when (equal? line
(lambda (in-port) "EINE ZEILE GRO/3..."))
(awk (read-line in-port) (line) counter () (when (equal? line
(:range 1 3 (set! read (cons 'first-clause read))) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}"))
(:range (when (equal? line (set! read (cons 'second-clause read)))
"EINE ZEILE GRO/3...")) (:range (when (equal? line
(when (equal? line
"*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}"))
(set! read (cons 'second-clause read)))
(:range (when (equal? line
"expr-test zu prüfen:")) "expr-test zu prüfen:"))
4 4
(set! read (cons 'third-clause read)))))) (set! read (cons 'third-clause read)))))
(delete-file tmp-file) (make-string-input-port str))
(equal? read (equal? read
(list 'second-clause 'second-clause 'third-clause 'second-clause 'third-clause 'first-clause 'first-clause))))) (list 'second-clause 'second-clause 'third-clause 'second-clause 'third-clause 'first-clause 'first-clause)))))
@ -327,30 +279,26 @@
(add-test! 'range-wo-begin-w-end-test 'awk (add-test! 'range-wo-begin-w-end-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) (range: 1 3 (set! read (cons 'first-clause read)))
(call-with-input-file tmp-file (range: (when (equal? line
(lambda (in-port) "EINE ZEILE GRO/3..."))
(awk (read-line in-port) (line) counter () (when (equal? line
(range: 1 3 (set! read (cons 'first-clause read))) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}"))
(range: (when (equal? line (set! read (cons 'second-clause read)))
"EINE ZEILE GRO/3...")) (range: (when (equal? line
(when (equal? line "expr-test zu prüfen:"))
"*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}"))
(set! read (cons 'second-clause read)))
(range: (when (equal? line
"expr-test zu prüfen:"))
4 4
(set! read (cons 'third-clause read)))))) (set! read (cons 'third-clause read)))))
(delete-file tmp-file) (make-string-input-port str))
(equal? read (equal? read
(list 'second-clause 'second-clause 'third-clause 'second-clause 'third-clause 'first-clause 'first-clause))))) (list 'second-clause 'second-clause 'third-clause 'second-clause 'third-clause 'first-clause 'first-clause)))))
@ -359,18 +307,14 @@
(add-test! 'range-w-begin-w-end-test 'awk (add-test! 'range-w-begin-w-end-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port)
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port)))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) counter () (awk (read-line in-port) (line) counter ()
(:range: 1 3 (set! read (cons 'first-clause read))) (:range: 1 3 (set! read (cons 'first-clause read)))
(:range: (when (equal? line (:range: (when (equal? line
@ -381,8 +325,8 @@
(:range: (when (equal? line (:range: (when (equal? line
"expr-test zu prüfen:")) "expr-test zu prüfen:"))
4 4
(set! read (cons 'third-clause read)))))) (set! read (cons 'third-clause read)))))
(delete-file tmp-file) (make-string-input-port str))
(equal? read (equal? read
(list 'second-clause 'second-clause 'third-clause 'second-clause 'third-clause (list 'second-clause 'second-clause 'third-clause 'second-clause 'third-clause
'second-clause 'first-clause 'third-clause 'first-clause 'first-clause))))) 'second-clause 'first-clause 'third-clause 'first-clause 'first-clause)))))
@ -391,25 +335,21 @@
(add-test! 'else-test 'awk (add-test! 'else-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port)
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port)))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) () (awk (read-line in-port) (line) ()
(1 (set! read (cons 'first-clause read))) (1 (set! read (cons 'first-clause read)))
(else (set! read (cons 'second-clause read))) (else (set! read (cons 'second-clause read)))
(4 (set! read (cons 'third-clause read))) (4 (set! read (cons 'third-clause read)))
(5 (set! read (cons 'fourth-clause read))) (5 (set! read (cons 'fourth-clause read)))
(else (set! read (cons 'fifth-clause read)))))) (else (set! read (cons 'fifth-clause read)))))
(delete-file tmp-file) (make-string-input-port str))
(equal? read (equal? read
(list 'fifth-clause 'second-clause 'fourth-clause 'second-clause 'third-clause (list 'fifth-clause 'second-clause 'fourth-clause 'second-clause 'third-clause
'second-clause 'fifth-clause 'second-clause 'fifth-clause 'second-clause 'second-clause 'fifth-clause 'second-clause 'fifth-clause 'second-clause
@ -420,24 +360,20 @@
(add-test! 'test=>expr-test 'awk (add-test! 'test=>expr-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port) (awk (read-line in-port) (line) counter ()
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port))) (counter => (lambda (c)
(call-with-input-file tmp-file (set! read (cons c read))))
(lambda (in-port) (#f => (lambda (c)
(awk (read-line in-port) (line) counter () (set! read (cons c read))))))
(counter => (lambda (c) (make-string-input-port str))
(set! read (cons c read))))
(#f => (lambda (c)
(set! read (cons c read)))))))
(delete-file tmp-file)
(equal? read (list 6 5 4 3 2 1))))) (equal? read (list 6 5 4 3 2 1)))))
@ -445,24 +381,20 @@
(add-test! 'after-test 'awk (add-test! 'after-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port)
(write-string "eine zeile mit zeichen...\n" out-port)
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port)))
(set! read (set! read
(call-with-input-file tmp-file ((lambda (in-port)
(lambda (in-port) (awk (read-line in-port) (line) ()
(awk (read-line in-port) (line) () (1 (set! read 1))
(1 (set! read 1)) (2 (set! read 2))
(2 (set! read 2)) (after 'return)))
(after 'return))))) (make-string-input-port str)))
(delete-file tmp-file)
(equal? read 'return)))) (equal? read 'return))))
@ -470,18 +402,14 @@
(add-test! 'var-decl-test 'awk (add-test! 'var-decl-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port)
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port)))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) counter ((i 0) (awk (read-line in-port) (line) counter ((i 0)
(x 2) (x 2)
(y 3)) (y 3))
@ -490,8 +418,8 @@
(3 (set! i (* i 2))) (3 (set! i (* i 2)))
(4 (set! i (- i y))) (4 (set! i (- i y)))
(5 (set! i (* i x))) (5 (set! i (* i x)))
(6 (set! read i))))) (6 (set! read i))))
(delete-file tmp-file) (make-string-input-port str))
(= read 56)))) (= read 56))))
@ -499,72 +427,20 @@
(add-test! 'multiple-return-values-of-next-record-test 'awk (add-test! 'multiple-return-values-of-next-record-test 'awk
(lambda () (lambda ()
(let ((tmp-file (create-temp-file)) (let ((read '())
(read '())) (str (string-append "ein paar testzeilen, um\n"
(call-with-output-file tmp-file "expr-test zu prüfen:\n"
(lambda (out-port) "EINE ZEILE GRO/3...\n"
(write-string "ein paar testzeilen, um\n" out-port) "eine zeile klein...\n"
(write-string "expr-test zu prüfen:\n" out-port) "eine zeile mit zeichen...\n"
(write-string "EINE ZEILE GRO/3...\n" out-port) "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n")))
(write-string "eine zeile klein...\n" out-port) ((lambda (in-port)
(write-string "eine zeile mit zeichen...\n" out-port)
(write-string "*+#'~,;:.-_<>|!§$%&/()=?\"\\[]{}\n" out-port)))
(call-with-input-file tmp-file
(lambda (in-port)
(awk ((lambda () (awk ((lambda ()
(values (read-line in-port)1 2 'a 'b))) (line x y a b) counter () (values (read-line in-port)1 2 'a 'b))) (line x y a b) counter ()
(1 (set! read (cons x read))) (1 (set! read (cons x read)))
(2 (set! read (cons y read))) (2 (set! read (cons y read)))
(3 (set! read (cons a read))) (3 (set! read (cons a read)))
(4 (set! read (cons b read)))))) (4 (set! read (cons b read)))))
(delete-file tmp-file) (make-string-input-port str))
(equal? read (equal? read
(list 'b 'a 2 1))))) (list 'b 'a 2 1)))))
;; --- awk-in-awk-test ---
(add-test! 'awk-in-awk-test 'awk
(lambda ()
(let ((tmp-file (create-temp-file))
(read '()))
(call-with-output-file tmp-file
(lambda (out-port)
(let loop ((i 1))
(if (= 10000 i)
(write-string (number->string i) out-port)
(begin
(write-string (number->string i) out-port)
(if (zero? (modulo i 100))
(write-string "\n" out-port)
(write-string " " out-port))
(loop (+ i 1)))))))
(call-with-input-file tmp-file
(lambda (in-port)
(awk (read-line in-port) (line) ()
(#t (let ((tmp-file-1 (create-temp-file))
(l (string-length line)))
(call-with-output-file tmp-file-1
(lambda (out-port)
(let loop ((i 0))
(if (= i l)
(write-string "" out-port)
(let ((ch (string-ref line i)))
(if (= 32 (char->ascii ch))
(write-string "\n" out-port)
(write-string (char->string ch) out-port))
(loop (+ i 1)))))))
(call-with-input-file tmp-file-1
(lambda (in-port)
(awk (read-line in-port) (number-str) ()
((str-palindrom? number-str) (set! read (cons number-str read))))))
(delete-file tmp-file-1))))))
(delete-file tmp-file)
(equal? read
(let loop ((i 10000))
(if (zero? i)
'()
(if (int-palindrom? i)
(cons (number->string i) (loop (- i 1)))
(loop (- i 1)))))))))