aboutsummaryrefslogtreecommitdiffstats
path: root/match-test.csc
blob: bbecce456ada372c90580f531ffb3dc1343b03f3 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(import (scheme base)
        (only (csc testing) assert-equal test)
        (csc match))


(test match-cond
  (assert-equal
    3
    (match 3
      ((! 0) 0)
      ((! 1) 1)
      ((! 2) 2)
      ((! 3) 3)
      (_ 4))))


(test match-list
  (assert-equal
    2
    (match '(1 2 3)
      ('() 0)
      (((! 1) (! 2)) 1)
      (((! 1) (! 2) (! 3)) 2)
      (((! 1) (! 2) (! 3) (! 4)) 3)
      (_ 4))))


(test match-binding
  (assert-equal
    2
    (match '(1 2 3)
      (((! 1) x (! 3)) x))))


(test match-destructuring
  (assert-equal
    1
    (match '(1 2 3)
      ('() 0)
      ((head . _) head))))


(test match-ignore
  (assert-equal
    2
    (match '(1 2 3)
      ((_ _ _ _) 0)
      (((! 2) _ _) 1)
      (((! 1) _ _) 2)
      (_ 3))))


(test match-improper-list
  (assert-equal
    2
    (match '(1 2 3)
      (((! 2) . _) 1)
      (((! 1) . x) (car x))
      (_ 3))))


(test match-symbol
  (assert-equal
    2
    (match 'b
      ((! 'a) 1)
      ((! 'b) 2)
      (_ 3))))


(test match-when
  (assert-equal
    3
    (match 'b
      ((! 'a) 1)
      ((! 'b) (when #f) 2)
      ((! 'b) 3)
      (_ 4))))