-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
58 lines (56 loc) · 986 Bytes
/
parser_test.go
File metadata and controls
58 lines (56 loc) · 986 Bytes
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 main
import (
"fmt"
"reflect"
"testing"
)
func TestParser(t *testing.T) {
testCases := []struct {
in []Token
want ASTNode
}{
{
in: []Token{
{"paren", "("},
{"name", "add"},
{"number", "1"},
{"number", "2"},
{"paren", ")"},
},
want: ASTNode{
nodeType: "Program",
value: nil,
params: nil,
body: []ASTNode{
{
nodeType: "CallExpression",
value: "add",
params: []ASTNode{
{
nodeType: "NumberLiteral",
value: "1",
params: nil,
body: nil,
},
{
nodeType: "NumberLiteral",
value: "2",
params: nil,
body: nil,
},
},
},
},
},
},
}
for _, tC := range testCases {
testName := fmt.Sprintf("%s", tC.in)
t.Run(testName, func(t *testing.T) {
out := Parser(tC.in)
if !reflect.DeepEqual(out, tC.want) {
t.Errorf("got %s, want %s", out, tC.want)
}
})
}
}