-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypecheck_test.go
117 lines (112 loc) · 1.64 KB
/
typecheck_test.go
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
//
// Copyright (c) 2022-2023 Markku Rossi
//
// All rights reserved.
//
package scheme
import (
"fmt"
"strings"
"testing"
)
var typecheckTests = []struct {
name string
data string
}{
{
name: "non-lambda function",
data: `("foo" 1 2)`,
},
{
name: "native argument count",
data: `(string-length 1 2)`,
},
{
name: "back-reference argument count",
data: `
(define (bar a)
(+ a 1))
(define (foo)
(bar 1 2))
`,
},
{
name: "forward-reference argument count",
data: `
(define (foo)
(bar 1 2))
(define (bar a)
(+ a 1))
`,
},
{
name: "redefine symbol",
data: `
(define (foo)
(+ 1 2))
(define (foo a)
(+ a 1))
`,
},
{
name: "set invalid value",
data: `
(define num #e10)
(set! num #t)
`,
},
{
name: "invalid fixed argument type",
data: `
(string-length 1)
`,
},
{
name: "let init argument count",
data: `
(let ((a (string-length 1 2))
(b 1))
(+ a b))
`,
},
{
name: "let body argument count",
data: `
(let ((f (lambda (a) (+ a 1)))
(b 1))
(f 1 2))
`,
},
{
name: "let* back-reference argument count",
data: `
(let* ((f (lambda (a) (+ a 1)))
(b (f 1 2)))
(display b)
(newline))
`,
},
{
name: "letrec forward-reference argument count",
data: `
(letrec ((b (lambda (a) (f 1 2)))
(f (lambda (a) (+ a 1))))
(display (b 1))
(newline))
`,
},
}
func TestTypecheck(t *testing.T) {
for idx, test := range typecheckTests {
scm, err := New()
if err != nil {
t.Fatal(err)
}
scm.Params.Quiet = true
_, err = scm.Eval(fmt.Sprintf("test-%d", idx),
strings.NewReader(test.data))
if err == nil {
t.Errorf("test-%d: error %s not detected", idx, test.name)
}
}
}