-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypeName_test.go
More file actions
135 lines (123 loc) · 2.46 KB
/
Copy pathtypeName_test.go
File metadata and controls
135 lines (123 loc) · 2.46 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package solparser_test
import (
"errors"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/uji/solparser"
"github.com/uji/solparser/ast"
"github.com/uji/solparser/token"
)
func TestParser_ParseTypeName(t *testing.T) {
tests := []struct {
name string
input string
want ast.TypeName
err *token.PosError
}{
{
name: "ElementaryTypeName",
input: "string)",
want: ast.ElementaryTypeName{
{
Type: token.String,
Value: "string",
Position: token.Pos{Column: 1, Line: 1},
},
},
},
{
name: "Not TypeName",
input: "pragma",
err: &token.PosError{
Pos: token.Pos{Column: 1, Line: 1},
Msg: "not found type-name.",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(*testing.T) {
r := strings.NewReader(tt.input)
p := solparser.New(r)
got, err := p.ParseTypeName()
var sErr *token.PosError
if errors.As(err, &sErr) {
if diff := cmp.Diff(tt.err, sErr); diff != "" {
t.Errorf("%s", diff)
}
}
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("%s", diff)
}
})
}
}
func TestParser_ParseElementaryTypeName(t *testing.T) {
tests := []struct {
input string
want ast.TypeName
err *token.PosError
}{
{
input: "address",
want: ast.ElementaryTypeName{
{
Type: token.Address,
Value: "address",
Position: token.Pos{Column: 1, Line: 1},
},
},
},
{
input: "bool",
want: ast.ElementaryTypeName{
{
Type: token.Bool,
Value: "bool",
Position: token.Pos{Column: 1, Line: 1},
},
},
},
{
input: "string",
want: ast.ElementaryTypeName{
{
Type: token.String,
Value: "string",
Position: token.Pos{Column: 1, Line: 1},
},
},
},
{
input: "address payable",
want: ast.ElementaryTypeName{
{
Type: token.Address,
Value: "address",
Position: token.Pos{Column: 1, Line: 1},
},
{
Type: token.Payable,
Value: "payable",
Position: token.Pos{Column: 9, Line: 1},
},
},
},
}
for _, tt := range tests {
t.Run(tt.input, func(*testing.T) {
r := strings.NewReader(tt.input)
p := solparser.New(r)
got, err := p.ParseElementaryTypeName()
var sErr *token.PosError
if errors.As(err, &sErr) {
if diff := cmp.Diff(tt.err, sErr); diff != "" {
t.Errorf("%s", diff)
}
}
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Errorf("%s", diff)
}
})
}
}