-
Notifications
You must be signed in to change notification settings - Fork 4
/
enum-test.ss
48 lines (39 loc) · 1.51 KB
/
enum-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
38
39
40
41
42
43
44
45
46
47
48
#lang scheme/base
(require "enum.ss"
"test-base.ss")
; Helpers ----------------------------------------
(define-enum vehicle
(train boat plane))
(define-enum prefixed
([a "item a"]
[b 'B "item b"])
#:prefix prefix:)
; Tests ------------------------------------------
(define/provide-test-suite enum-tests
(test-case "vehicle"
(check-pred enum? vehicle)
(check-equal? (enum-values vehicle) '(train boat plane))
(check-equal? (enum-pretty-values vehicle) '("train" "boat" "plane"))
(check-equal? (enum->string vehicle) "train, boat, plane")
(check-equal? (enum->pretty-string vehicle) "train, boat, plane")
(check-equal? train 'train)
(check-equal? boat 'boat)
(check-equal? plane 'plane)
(check-true (vehicle? 'train))
(check-true (vehicle? 'boat))
(check-true (vehicle? 'plane))
(check-false (vehicle? 'lemon)))
(test-case "prefixed"
(check-pred enum? prefixed)
(check-equal? (enum-values prefixed) '(a B))
(check-equal? (enum-pretty-values prefixed) '("item a" "item b"))
(check-equal? (enum->string prefixed) "a, B")
(check-equal? (enum->pretty-string prefixed) "item a, item b")
(check-equal? prefix:a 'a)
(check-equal? prefix:b 'B)
(check-true (prefixed? 'a))
(check-true (prefixed? 'B))
(check-false (prefixed? 'b)))
(test-case "enum->[pretty-]string with separator specified"
(check-equal? (enum->string vehicle ":") "train:boat:plane")
(check-equal? (enum->pretty-string vehicle ":") "train:boat:plane")))