block.lsp 1.44 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Oct 12 12:30:46 2002
;;;; Contains: Tests of BLOCK

Daniel Kochmański's avatar
Daniel Kochmański committed
6

pfdietz's avatar
pfdietz committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

(deftest block.1
  (block foo
    (return-from foo 1))
  1)

(deftest block.2
  (block nil
    (block foo
      (return 'good))
    'bad)
  good)

(deftest block.3
  (block done
    (flet ((%f (x) (return-from done x)))
      (%f 'good))
    'bad)
  good)

(deftest block.4
  (block foo
    (block foo
      (return-from foo 'bad))
    'good)
  good)

(deftest block.5
  (block done
    (flet ((%f (x) (return-from done x)))
      (mapcar #'%f '(good bad bad)))
    'bad)
  good)

41 42 43 44
(deftest block.6
  (block b1
    (return-from b1 (values))
    1))
pfdietz's avatar
pfdietz committed
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
(deftest block.7
  (block b1
    (return-from b1 (values 1 2 3 4))
    1)
  1 2 3 4)

(deftest block.8
  (block foo)
  nil)

(deftest block.9
  (block foo (values 'a 'b) (values 'c 'd))
  c d)

(deftest block.10
  (block done
    (flet ((%f (x) (return-from done x)))
      (block done (mapcar #'%f '(good bad bad))))
    'bad)
  good)
66

67 68 69 70 71 72 73 74 75 76 77 78
;;; Block has no tagbody
(deftest block.11
  (block done
    (tagbody
     (block nil
       (go 10)
       10
       (return-from done 'bad))
     10
     (return-from done 'good)))
  good)

79 80 81 82
;;; Macros are expanded in the appropriate environment

(deftest block.12
  (macrolet ((%m (z) z))
sds's avatar
sds committed
83
            (block foo (expand-in-current-env (%m :good))))
84 85
  :good)

86 87
#|
(deftest return.error.1
88
  (signals-error
89
   (block nil
90 91 92
     (return 'a 'b))
   program-error)
  t)
93
|#