listen.lsp 1.5 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jan 27 21:16:39 2004
;;;; Contains: Tests of LISTEN

(in-package :cl-test)

(deftest listen.1
  (with-input-from-string (s "") (listen s))
  nil)

(deftest listen.2
  (with-input-from-string (s "x") (notnot-mv (listen s)))
  t)

(deftest listen.3
  (with-input-from-string (*standard-input* "") (listen))
  nil)

(deftest listen.4
  (with-input-from-string (*standard-input* "A") (notnot-mv (listen)))
  t)

pfdietz's avatar
pfdietz committed
24 25 26 27
;;; (deftest listen.5
;;;  (when (interactive-stream-p *standard-input*)
;;;    (clear-input) (listen))
;;;  nil)
pfdietz's avatar
pfdietz committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

(deftest listen.6
  (with-input-from-string
   (s "x")
   (values
    (read-char s)
    (listen s)
    (unread-char #\x s)
    (notnot (listen s))
    (read-char s)))
  #\x nil nil t #\x)

(deftest listen.7
  (with-open-file
   (s "listen.lsp")
   (values
    (notnot (listen s))
    (handler-case
     (locally (declare (optimize safety))
sds's avatar
sds committed
47
              (loop (read-char s)))
pfdietz's avatar
pfdietz committed
48 49 50
     (end-of-file () (listen s)))))
  t nil)

51 52 53
(deftest listen.8
  (with-input-from-string
   (is "abc")
pfdietz's avatar
pfdietz committed
54
   (let ((*terminal-io* (make-two-way-stream is (make-broadcast-stream))))
55 56 57 58 59 60 61 62 63
     (notnot-mv (listen t))))
  t)

(deftest listen.9
  (with-input-from-string
   (*standard-input* "345")
   (notnot-mv (listen nil)))
  t)

pfdietz's avatar
pfdietz committed
64 65 66
;;; Error tests

(deftest listen.error.1
67
  :notes (:assume-no-simple-streams)
pfdietz's avatar
pfdietz committed
68 69 70
  (signals-error (listen *standard-input* nil) program-error)
  t)

71 72 73
(deftest listen.error.2
  (signals-error (listen *standard-input* nil nil) program-error)
  t)