-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ops_test.go
58 lines (54 loc) · 1.01 KB
/
ops_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
package golisp
import (
"bytes"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestOps(t *testing.T) {
fns, err := filepath.Glob("testdata/*.lisp")
if err != nil {
t.Fatal(err)
}
for _, fn := range fns {
t.Log(fn)
b, err := ioutil.ReadFile(fn)
if err != nil {
t.Fatal(err)
}
input := string(b)
parser := NewParser(strings.NewReader(input))
node, err := parser.Parse()
if err != nil {
b, err2 := ioutil.ReadFile(fn[:len(fn)-4] + "err")
if err2 != nil || err.Error() != strings.TrimSpace(string(b)) {
t.Error(err)
continue
}
continue
}
var buf bytes.Buffer
env := NewEnv(nil)
err = LoadLib(env)
if err != nil {
t.Fatal(err)
}
env.out = &buf
_, err = env.Eval(node)
if err != nil {
t.Error(err)
continue
}
got := buf.String()
b, err = ioutil.ReadFile(fn[:len(fn)-4] + "out")
if err != nil {
t.Fatal(err)
}
want := string(b)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf(diff)
}
}
}