-
Notifications
You must be signed in to change notification settings - Fork 4
/
contract-test.ss
37 lines (30 loc) · 2.08 KB
/
contract-test.ss
1
2
3
4
5
6
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
#lang scheme/base
(require "contract.ss"
"test-base.ss")
; Tests ------------------------------------------
; test-suite
(define/provide-test-suite contract-tests
(test-case "arity/c : fixed arity procedures"
(check-false (contract-first-order-passes? (arity/c 1) (lambda () #t)))
(check-true (contract-first-order-passes? (arity/c 1) (lambda (a) #t)))
(check-false (contract-first-order-passes? (arity/c 1) (lambda (a b) #t))))
(test-case "arity/c : rest arguments"
(check-false (contract-first-order-passes? (arity/c 2) (lambda (a b c . d) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda (a b . c) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda (a . b) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda a #t))))
(test-case "arity/c : optional arguments"
(check-false (contract-first-order-passes? (arity/c 2) (lambda (a b c) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda (a b [c #f]) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda (a [b #f] [c #f]) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda ([a #f] [b #f] [c #f]) #t))))
(test-case "arity/c : keyword arguments"
; Basically, arity/c doesn't work with keyword procedures
(check-false (contract-first-order-passes? (arity/c 2) (lambda (#:a a #:b b #:c c) #t)))
(check-false (contract-first-order-passes? (arity/c 2) (lambda (#:a a #:b b #:c [c #f]) #t)))
(check-false (contract-first-order-passes? (arity/c 2) (lambda (#:a a #:b [b #f] #:c [c #f]) #t)))
(check-false (contract-first-order-passes? (arity/c 2) (lambda (#:a [a #f] #:b [b #f] #:c [c #f]) #t)))
(check-false (contract-first-order-passes? (arity/c 2) (lambda (x #:a a #:b b #:c c) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda (x y #:a a #:b b #:c c) #t)))
(check-false (contract-first-order-passes? (arity/c 2) (lambda (x y z #:a a #:b b #:c c) #t)))
(check-true (contract-first-order-passes? (arity/c 2) (lambda (x y [z #f] #:a a #:b b #:c c) #t)))))