-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconditional_test.go
More file actions
137 lines (131 loc) · 2.11 KB
/
conditional_test.go
File metadata and controls
137 lines (131 loc) · 2.11 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
package lib
import "testing"
func TestIf(t *testing.T) {
execTests(t, If, []test{
{
exp: `(if (> 3 2) 'yes 'no)`,
want: `'yes`,
wantErr: false,
},
{
exp: `(if (> 2 3) 'yes 'no)`,
want: `'no`,
wantErr: false,
},
{
exp: `(if (> 2 3) 'yes)`,
want: `nil`,
wantErr: false,
},
{
exp: `(if (> 3 2) (- 3 2) (+ 3 2))`,
want: `1`,
wantErr: false,
},
{
exp: `
(let ((x 7))
(if (< x 0) x (- x)))
`,
want: `-7`,
wantErr: false,
},
})
}
func TestCond(t *testing.T) {
execTests(t, Cond, []test{
{
exp: `
(cond ((> 3 2) 'greater)
((< 3 2) 'less))
`,
want: `'greater`,
wantErr: false,
},
{
exp: `
(cond ((> 3 3) 'greater)
((< 3 3) 'less))
`,
want: `nil`,
wantErr: false,
},
{
exp: `
(cond ((> 3 3) 'greater)
((< 3 3) 'less)
(t 'equal))
`,
want: `'equal`,
wantErr: false,
},
})
}
func TestCase(t *testing.T) {
execTests(t, Case, []test{
{
exp: `
(case (* 2 3)
((2 3 5 7) 'prime)
((4 6 8 9) 'composite))
`,
want: `'composite`,
wantErr: false,
},
{
exp: `
(case (car '(c d))
((a) 'a)
((b) 'b))
`,
want: `nil`,
wantErr: false,
},
{
exp: `
(case (car '(c d))
((a e i o u) 'vowel)
((y) 'semivowel)
(t 'consonant))
`,
want: `'consonant`,
wantErr: false,
},
{
exp: `
(let ((char #\u))
(case char
((#\a #\e #\o #\u #\i) 'vowels)
(t 'consonants)))
`,
want: `'vowels`,
wantErr: false,
},
})
}
func TestCaseUsing(t *testing.T) {
execTests(t, CaseUsing, []test{
{
exp: `
(case-using #'= (+ 1.0 1.0)
((1) 'one)
((2) 'two)
(t 'more))
`,
want: `'two`,
wantErr: false,
},
{
exp: `
(case-using #'string= "bar"
(("foo") 1)
(("bar") 2))
`,
want: `'2`,
wantErr: false,
},
})
}