-
Notifications
You must be signed in to change notification settings - Fork 1
/
prql_test.go
58 lines (53 loc) · 1002 Bytes
/
prql_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 prql
import (
"context"
"os"
"testing"
)
func TestWasi(t *testing.T) {
ctx := context.Background()
w, err := New(ctx)
if err != nil {
t.Fatal(err)
}
defer w.Close(ctx)
testCases := map[string]struct {
input string
shouldErr bool
}{
"empty string": {
input: "",
shouldErr: true,
},
"invalid prql": {
input: "foo",
shouldErr: true,
},
"valid prql": {
input: `from employees`,
shouldErr: false,
},
"example query": {
input: MustFromFile("testdata/input.prql"),
shouldErr: false,
},
}
for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
_, err := w.Compile(ctx, tc.input)
if tc.shouldErr && err == nil {
t.Fatalf("expected err, got nil")
} else if !tc.shouldErr && err != nil {
t.Fatalf("expected nil, got err: %v", err)
}
})
}
}
func MustFromFile(name string) string {
content, err := os.ReadFile(name)
if err != nil {
panic(err)
}
return string(content)
}