-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_test.go
45 lines (41 loc) · 861 Bytes
/
error_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
package cf
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestError(t *testing.T) {
dir := "testdata/error"
testFiles, err := os.ReadDir(dir)
if err != nil {
t.Fatalf("could not read %s: %q", dir, err)
}
for _, f := range testFiles {
if f.IsDir() {
continue
}
if filepath.Ext(f.Name()) != ".cf" {
continue
}
buf, err := os.ReadFile(dir + "/" + f.Name())
if err != nil {
t.Fatal(err)
}
errortext, _ := os.ReadFile(dir + "/" + f.Name() + ".error")
t.Run(f.Name(), func(t *testing.T) {
tokens, err := Lex(string(buf))
if err != nil {
t.Fatal(err)
}
_, _, err = ParseTokens(tokens)
if err == nil {
t.Fatal("expected error, got none")
}
err1 := strings.TrimSpace(err.Error()) + "\n"
if err1 != string(errortext) {
t.Fatalf("expected %q, got %q", errortext, err1)
}
})
}
}