koans, looks like exception handling with signals
This commit is contained in:
@@ -37,25 +37,26 @@
|
||||
(define-test type-hierarchy
|
||||
;; Inheritance for condition types works the same way as for classes.
|
||||
(let ((condition (make-condition 'my-condition)))
|
||||
(true-or-false? ____ (typep condition 'my-condition))
|
||||
(true-or-false? ____ (typep condition 'condition))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error)))
|
||||
(true-or-false? t (typep condition 'my-condition))
|
||||
(true-or-false? t (typep condition 'condition))
|
||||
(true-or-false? nil (typep condition 'warning)) ; nope
|
||||
(true-or-false? nil (typep condition 'error))) ; nope
|
||||
(let ((condition (make-condition 'my-warning)))
|
||||
(true-or-false? ____ (typep condition 'my-warning))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error)))
|
||||
(true-or-false? t (typep condition 'my-warning))
|
||||
(true-or-false? t (typep condition 'warning))
|
||||
(true-or-false? nil (typep condition 'error)))
|
||||
(let ((condition (make-condition 'my-serious-condition)))
|
||||
(true-or-false? ____ (typep condition 'my-serious-condition))
|
||||
(true-or-false? ____ (typep condition 'serious-condition))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error)))
|
||||
(true-or-false? t (typep condition 'my-serious-condition))
|
||||
(true-or-false? t (typep condition 'serious-condition))
|
||||
(true-or-false? nil (typep condition 'warning))
|
||||
(true-or-false? nil (typep condition 'error)))
|
||||
(let ((condition (make-condition 'my-error)))
|
||||
(true-or-false? ____ (typep condition 'my-error))
|
||||
(true-or-false? ____ (typep condition 'my-serious-condition))
|
||||
(true-or-false? ____ (typep condition 'serious-condition))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error))))
|
||||
(true-or-false? t (typep condition 'my-error))
|
||||
(true-or-false? nil (typep condition 'my-serious-condition))
|
||||
(true-or-false? t (typep condition 'serious-condition)) ; not on first try
|
||||
(true-or-false? nil (typep condition 'warning))
|
||||
(true-or-false? t (typep condition 'error))))
|
||||
;; heh
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -90,16 +91,17 @@
|
||||
(silly-condition #'handle-silly-condition)
|
||||
(most-silly-condition #'handle-most-silly-condition))
|
||||
(signal (make-condition 'most-silly-condition)))
|
||||
(assert-equal ____ *list*)))
|
||||
(assert-equal '(:most-silly-condition :silly-condition :very-silly-condition) *list*)))
|
||||
;; list is reverse order of functions in #'handler-bind
|
||||
|
||||
(define-test handler-order
|
||||
;; The order of binding handlers matters.
|
||||
(let ((*list* '()))
|
||||
(handler-bind ((silly-condition #'handle-silly-condition)
|
||||
(very-silly-condition #'handle-very-silly-condition)
|
||||
(most-silly-condition #'handle-most-silly-condition))
|
||||
(signal (make-condition 'most-silly-condition)))
|
||||
(assert-equal ____ *list*)))
|
||||
;; The order of binding handlers matters.
|
||||
(let ((*list* '()))
|
||||
(handler-bind ((silly-condition #'handle-silly-condition)
|
||||
(very-silly-condition #'handle-very-silly-condition)
|
||||
(most-silly-condition #'handle-most-silly-condition))
|
||||
(signal (make-condition 'most-silly-condition)))
|
||||
(assert-equal ____ *list*)))
|
||||
|
||||
(define-test multiple-handler-binds
|
||||
;; It is possible to bind handlers in steps.
|
||||
|
||||
Reference in New Issue
Block a user