Added tests, included newer Racket versions in .travis.yml

This commit is contained in:
Georges Dupéron 2016-08-08 13:14:50 +02:00
parent ff1ad651f3
commit 502e8f7e86
5 changed files with 176 additions and 2 deletions

View File

@ -26,6 +26,8 @@ env:
- RACKET_VERSION=6.2
- RACKET_VERSION=6.3
- RACKET_VERSION=6.4
- RACKET_VERSION=6.5
- RACKET_VERSION=6.6
- RACKET_VERSION=HEAD
matrix:

View File

@ -12,8 +12,8 @@
(void))
(check-equal? (awhen (member 'a lst)
'seen)
'seen)
it)
'(a b c))
(check-equal? (awhen (member 'a lst)

118
test/cond-let-test.rkt Normal file
View File

@ -0,0 +1,118 @@
#lang racket
(require anaphoric/cond-let
rackunit)
(define lst '(x y z a b c))
(define seen 0)
;; With else branch
(check-equal? (cond-let
[[x (member 'a lst)] (set! seen (add1 seen))
(check-equal? x '(a b c))
'seen-01]
[[x (member 'b lst)] (fail "cond-let chose wrong branch")]
[else (fail "cond-let chose wrong branch")])
'seen-01)
(check-equal? seen 1) ;; multiple body statements
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[x (member 'b lst)] (begin (check-equal? x '(b c))
'seen-02)]
[else (fail "cond-let chose wrong branch")])
'seen-02)
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[x (member 'absent2 lst)] (fail "cond-let chose wrong branch")]
[else 'seen-03])
'seen-03)
;; Different variable names
(check-equal? (cond-let
[[x (member 'a lst)] (begin (check-equal? x '(a b c))
'seen-02)]
[[y (member 'b lst)] (fail "cond-let chose wrong branch")]
[else (fail "cond-let chose wrong branch")])
'seen-02)
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[y (member 'b lst)] (begin (check-equal? y '(b c))
'seen-02)]
[else (fail "cond-let chose wrong branch")])
'seen-02)
;; Shadowing
(check-equal? (let ([x 'outerx] [y 'outery])
(cond-let
[[x (member 'a lst)] (begin (check-equal? x '(a b c))
'seen-02)]
[[y (member 'b lst)] (fail "cond-let chose wrong branch")]
[else (fail "cond-let chose wrong branch")]))
'seen-02)
(check-equal? (let ([x 'outerx] [y 'outery])
(cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[y (member 'b lst)] (begin (check-equal? y '(b c))
'seen-02)]
[else (fail "cond-let chose wrong branch")]))
'seen-02)
(check-equal? (let ([x 'outerx] [y 'outery])
(cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[y (member 'absent lst)] (fail "cond-let chose wrong branch")]
[else (list x y)]))
'(outerx outery))
;; Just else branch
(check-equal? (cond-let
[else 'seen-04])
'seen-04)
;; Multiple body statements
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[x (member 'absent2 lst)] (fail "cond-let chose wrong branch")]
[else (set! seen (add1 seen))
'seen-05])
'seen-05)
(check-equal? seen 2)
;; Without else branch
(check-equal? (cond-let
[[x (member 'a lst)] (set! seen (add1 seen))
(check-equal? x '(a b c))
'seen-06]
[[x (member 'b lst)] (fail "cond-let chose wrong branch")])
'seen-06)
(check-equal? seen 3)
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[x (member 'b lst)] (begin (check-equal? x '(b c))
'seen-07)])
'seen-07)
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")]
[[x (member 'absent2 lst)] (fail "cond-let chose wrong branch")])
(void))
;; No branch
(check-equal? (cond-let)
(void))
;; Single branch
(check-equal? (cond-let
[[x (member 'a lst)] (begin (check-equal? x '(a b c))
'seen-09)])
'seen-09)
(check-equal? (cond-let
[[x (member 'absent lst)] (fail "cond-let chose wrong branch")])
(void))

25
test/if-let-test.rkt Normal file
View File

@ -0,0 +1,25 @@
#lang racket
(require anaphoric/if-let
rackunit)
(define lst '(x y z a b c))
(check-equal? (if-let [x (member 'a lst)]
(begin (check-equal? x '(a b c))
'seen)
(fail "aif selected wrong branch"))
'seen)
(check-equal? (let ([x 'outer])
(if-let [x (member 'a lst)]
(begin (check-equal? x '(a b c))
'seen)
(fail "aif selected wrong branch")))
'seen)
(check-equal? (let ([x 'outer])
(if-let [x (member 'absent lst)]
(fail "aif selected wrong branch")
'outer))
'outer)

29
test/when-let-test.rkt Normal file
View File

@ -0,0 +1,29 @@
#lang racket
(require anaphoric/when-let
rackunit)
(define lst '(x y z a b c))
(define seen 0)
(check-equal? (when-let [x (member 'absent lst)]
(fail "awhen should not have executed body")
'seen)
(void))
(check-equal? (when-let [x (member 'a lst)]
x)
'(a b c))
(check-equal? (let ([x 'outer])
(list (when-let [x (member 'a lst)]
x)
x))
'((a b c) outer))
(check-equal? (when-let [x (member 'a lst)]
(set! seen (add1 seen))
(check-equal? x '(a b c))
'seen)
'seen)
(check-equal? seen 1) ;; Multiple body statements