1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-30 08:50:23 +02:00

* tests/ports.test: Group the string port tests under a new

test name prefix.
* tests/ports.test ("line counter"): Check the final column, too.
This commit is contained in:
Jim Blandy 1999-06-15 08:39:11 +00:00
parent cbe50a7301
commit 73cb0a9704

View file

@ -104,26 +104,28 @@
;;;; String ports. ;;;; String ports.
;;; Write text to a string port. (with-test-prefix "string ports"
(catch-test-errors
(let* ((string "Howdy there, partner!") ;; Write text to a string port.
(in-string (call-with-output-string (catch-test-errors
(lambda (port) (let* ((string "Howdy there, partner!")
(display string port) (in-string (call-with-output-string
(newline port))))) (lambda (port)
(pass-if "output string: display text" (display string port)
(equal? in-string (string-append string "\n"))))) (newline port)))))
(pass-if "display text"
(equal? in-string (string-append string "\n")))))
;;; Write an s-expression to a string port. ;; Write an s-expression to a string port.
(catch-test-errors (catch-test-errors
(let* ((sexpr '("more utterly random text" 1729 #(a vector) 3.1415926)) (let* ((sexpr '("more utterly random text" 1729 #(a vector) 3.1415926))
(in-sexpr (in-sexpr
(call-with-input-string (call-with-output-string (call-with-input-string (call-with-output-string
(lambda (port) (lambda (port)
(write sexpr port))) (write sexpr port)))
read))) read)))
(pass-if "input and output string: write/read sexpr" (pass-if "write/read sexpr"
(equal? in-sexpr sexpr)))) (equal? in-sexpr sexpr)))))
;;;; Soft ports. No tests implemented yet. ;;;; Soft ports. No tests implemented yet.
@ -151,7 +153,7 @@
(define port-list-names '("file" "pipe" "string")) (define port-list-names '("file" "pipe" "string"))
;; Test the line counter. ;; Test the line counter.
(define (test-line-counter text second-line) (define (test-line-counter text second-line final-column)
(with-test-prefix "line counter" (with-test-prefix "line counter"
(let ((ports (input-port-list text))) (let ((ports (input-port-list text)))
(for-each (for-each
@ -178,7 +180,9 @@
((> i 20) #f) ((> i 20) #f)
(else (loop (+ i 1)))))) (else (loop (+ i 1))))))
(pass-if "line count is 5 at EOF" (pass-if "line count is 5 at EOF"
(= (port-line port) 5)))) (= (port-line port) 5))
(pass-if "column is correct at EOF"
(= (port-column port) final-column))))
ports port-list-names) ports port-list-names)
(for-each close-port ports) (for-each close-port ports)
(delete-file port-loop-temp)))) (delete-file port-loop-temp))))
@ -191,7 +195,8 @@
"himself without lessening mine; as he who lights his\n" "himself without lessening mine; as he who lights his\n"
"taper at mine, receives light without darkening me.\n" "taper at mine, receives light without darkening me.\n"
" --- Thomas Jefferson\n") " --- Thomas Jefferson\n")
"He who receives an idea from me, receives instruction"))) "He who receives an idea from me, receives instruction"
0)))
(catch-test-errors (catch-test-errors
(with-test-prefix "no newline" (with-test-prefix "no newline"
@ -202,4 +207,5 @@
"taper at mine, receives light without darkening me.\n" "taper at mine, receives light without darkening me.\n"
" --- Thomas Jefferson\n" " --- Thomas Jefferson\n"
"no newline here") "no newline here")
"He who receives an idea from me, receives instruction")))) "He who receives an idea from me, receives instruction"
15))))