Tests for aand and and-let
This commit is contained in:
parent
691e7e0771
commit
4ded042225
|
@ -90,7 +90,8 @@ using @racket[it].
|
||||||
at most once (evaluation stops at the first successful
|
at most once (evaluation stops at the first successful
|
||||||
@racket[conditionᵢ]).}
|
@racket[conditionᵢ]).}
|
||||||
|
|
||||||
@defform[(aand conditionᵢ ... body)]{
|
@defform*[[(aand)
|
||||||
|
(aand conditionᵢ ... body)]]{
|
||||||
Variant of @racket[and] which binds @racket[it]
|
Variant of @racket[and] which binds @racket[it]
|
||||||
to the value of each @racket[conditionᵢ], in scope within the
|
to the value of each @racket[conditionᵢ], in scope within the
|
||||||
next @racket[conditionᵢ] or @racket[body]. More precisely, the value
|
next @racket[conditionᵢ] or @racket[body]. More precisely, the value
|
||||||
|
@ -142,7 +143,8 @@ using @racket[it].
|
||||||
(evaluation stops at the first successful
|
(evaluation stops at the first successful
|
||||||
@racket[conditionᵢ]).}
|
@racket[conditionᵢ]).}
|
||||||
|
|
||||||
@defform[(and-let [identifier conditionᵢ] ... body)]{
|
@defform*[[(and-let)
|
||||||
|
(and-let [identifier conditionᵢ] ... body)]]{
|
||||||
Variant of @racket[and] which binds each @racket[identifier]
|
Variant of @racket[and] which binds each @racket[identifier]
|
||||||
to the value of its @racket[conditionᵢ], in scope within every
|
to the value of its @racket[conditionᵢ], in scope within every
|
||||||
@racket[conditionᵢ] afterwards as well as in @racket[body].
|
@racket[conditionᵢ] afterwards as well as in @racket[body].
|
||||||
|
|
34
test/aand-test.rkt
Normal file
34
test/aand-test.rkt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require anaphoric/aand
|
||||||
|
rackunit)
|
||||||
|
|
||||||
|
(define lst '(x b 2 y z a b c 1 2 3))
|
||||||
|
|
||||||
|
(check-equal? (aand)
|
||||||
|
#t)
|
||||||
|
|
||||||
|
(check-equal? (aand #f)
|
||||||
|
#f)
|
||||||
|
|
||||||
|
(check-equal? (aand (member 'y lst))
|
||||||
|
'(y z a b c 1 2 3))
|
||||||
|
|
||||||
|
(check-equal? (aand (member 'y lst)
|
||||||
|
(member 'b lst)
|
||||||
|
(member '2 lst))
|
||||||
|
'(2 y z a b c 1 2 3))
|
||||||
|
|
||||||
|
(check-equal? (aand (member 'y lst)
|
||||||
|
(member 'b lst)
|
||||||
|
(member '2 it))
|
||||||
|
'(2 y z a b c 1 2 3))
|
||||||
|
|
||||||
|
(check-equal? (aand (member 'y lst)
|
||||||
|
(member 'b it)
|
||||||
|
(member '2 it))
|
||||||
|
'(2 3))
|
||||||
|
|
||||||
|
(check-equal? (aand (member 'absent lst)
|
||||||
|
(fail "aand selected wrong branch"))
|
||||||
|
#f)
|
50
test/and-let-test.rkt
Normal file
50
test/and-let-test.rkt
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require anaphoric/and-let
|
||||||
|
rackunit)
|
||||||
|
|
||||||
|
(define lst '(x b 2 y z a b c 1 2 3))
|
||||||
|
|
||||||
|
(check-equal? (and-let)
|
||||||
|
#t)
|
||||||
|
|
||||||
|
(check-equal? (and-let 42)
|
||||||
|
42)
|
||||||
|
|
||||||
|
(check-equal? (and-let #f)
|
||||||
|
#f)
|
||||||
|
|
||||||
|
(check-equal? (and-let [v1 (member 'y lst)]
|
||||||
|
v1)
|
||||||
|
'(y z a b c 1 2 3))
|
||||||
|
|
||||||
|
(check-equal? (and-let [v1 (member 'y lst)]
|
||||||
|
[v2 (member 'b v1)]
|
||||||
|
[v3 (member '2 v2)]
|
||||||
|
(list v1 v2 v3))
|
||||||
|
'((y z a b c 1 2 3)
|
||||||
|
(b c 1 2 3)
|
||||||
|
(2 3)))
|
||||||
|
|
||||||
|
(check-equal? (let ([v1 'outer]
|
||||||
|
[v2 'outer]
|
||||||
|
[v3 'outer])
|
||||||
|
(and-let [v1 (member 'y lst)]
|
||||||
|
[v2 (member 'b v1)]
|
||||||
|
[v3 (member '2 v2)]
|
||||||
|
(list v1 v2 v3)))
|
||||||
|
'((y z a b c 1 2 3)
|
||||||
|
(b c 1 2 3)
|
||||||
|
(2 3)))
|
||||||
|
|
||||||
|
(check-equal? (let ([v1 'outer])
|
||||||
|
(and-let [v1 (member 'absent lst)]
|
||||||
|
(fail "aand selected wrong branch")))
|
||||||
|
#f)
|
||||||
|
|
||||||
|
(check-equal? (let ([v1 'outer]
|
||||||
|
[v2 'outer])
|
||||||
|
(and-let [v1 (member 'y lst)]
|
||||||
|
[v2 (member 'x v1)]
|
||||||
|
(fail "aand selected wrong branch")))
|
||||||
|
#f)
|
Loading…
Reference in New Issue
Block a user