|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (test-suite test-rnrs-conditions) |
|
:use-module ((rnrs base) :version (6)) |
|
:use-module ((rnrs conditions) :version (6)) |
|
:use-module (test-suite lib)) |
|
|
|
(define-condition-type &a &condition make-a-condition a-condition? (foo a-foo)) |
|
(define-condition-type &b &condition make-b-condition b-condition? (bar b-bar)) |
|
(define-condition-type &c &condition make-c-condition c-condition? |
|
(baz c-baz) |
|
(qux c-qux) |
|
(frobotz c-frobotz)) |
|
|
|
(with-test-prefix "condition?" |
|
(pass-if "condition? is #t for simple conditions" |
|
(condition? (make-error))) |
|
|
|
(pass-if "condition? is #t for compound conditions" |
|
(condition? (condition (make-error) (make-assertion-violation)))) |
|
|
|
(pass-if "condition? is #f for non-conditions" |
|
(not (condition? 'foo)))) |
|
|
|
(with-test-prefix "simple-conditions" |
|
(pass-if "simple-conditions returns condition components" |
|
(let* ((error (make-error)) |
|
(assertion (make-assertion-violation)) |
|
(c (condition error assertion)) |
|
(scs (simple-conditions c))) |
|
(equal? scs (list error assertion)))) |
|
|
|
(pass-if "simple-conditions flattens compound conditions" |
|
(let* ((implementation-restriction |
|
(make-implementation-restriction-violation)) |
|
(error1 (make-error)) |
|
(c1 (condition implementation-restriction error1)) |
|
(error2 (make-error)) |
|
(assertion (make-assertion-violation)) |
|
(c2 (condition error2 assertion c1)) |
|
(scs (simple-conditions c2))) |
|
(equal? scs (list error2 assertion implementation-restriction error1))))) |
|
|
|
(with-test-prefix "condition-predicate" |
|
(pass-if "returned procedure identifies matching simple conditions" |
|
(let ((mp (condition-predicate &message)) |
|
(mc (make-message-condition "test"))) |
|
(mp mc))) |
|
|
|
(pass-if "returned procedure identifies matching compound conditions" |
|
(let* ((sp (condition-predicate &serious)) |
|
(vp (condition-predicate &violation)) |
|
(sc (make-serious-condition)) |
|
(vc (make-violation)) |
|
(c (condition sc vc))) |
|
(and (sp c) (vp c)))) |
|
|
|
(pass-if "returned procedure is #f for non-matching simple" |
|
(let ((sp (condition-predicate &serious))) |
|
(not (sp 'foo)))) |
|
|
|
(pass-if "returned procedure is #f for compound without match" |
|
(let* ((ip (condition-predicate &irritants)) |
|
(sc (make-serious-condition)) |
|
(vc (make-violation)) |
|
(c (condition sc vc))) |
|
(not (ip c))))) |
|
|
|
(with-test-prefix "condition-accessor" |
|
(pass-if "accessor applies proc to field from simple condition" |
|
(let* ((proc (lambda (c) (condition-message c))) |
|
(ma (condition-accessor &message proc)) |
|
(mc (make-message-condition "foo"))) |
|
(equal? (ma mc) "foo"))) |
|
|
|
(pass-if "accessor applies proc to field from compound condition" |
|
(let* ((proc (lambda (c) (condition-message c))) |
|
(ma (condition-accessor &message proc)) |
|
(mc (make-message-condition "foo")) |
|
(vc (make-violation)) |
|
(c (condition vc mc))) |
|
(equal? (ma c) "foo")))) |
|
|
|
(with-test-prefix "define-condition-type" |
|
(pass-if "define-condition-type produces proper accessors" |
|
(let ((c (condition (make-a-condition 'foo) (make-b-condition 'bar)))) |
|
(and (eq? (a-foo c) 'foo) (eq? (b-bar c) 'bar)))) |
|
(pass-if "define-condition-type works for multiple fields" |
|
(let ((c (condition (make-a-condition 'foo) |
|
(make-c-condition 1 2 3)))) |
|
(and (eq? (a-foo c) 'foo) |
|
(= (c-baz c) 1) |
|
(= (c-qux c) 2) |
|
(= (c-frobotz c) 3))))) |
|
|