-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathliteral_test.go
87 lines (80 loc) · 1.61 KB
/
literal_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
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
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_ParseLiteral(t *testing.T) {
tests := []struct {
name string
input string
want ast.Literal
err *token.PosError
}{
{
name: "normal",
input: `"Hello World!!";`,
want: &ast.StringLiteral{
Type: token.NonEmptyStringLiteral,
Value: `"Hello World!!"`,
Position: pos(1, 1),
},
},
{
name: `Including \n`,
input: "\"Hello \nWorld!!\";",
want: &ast.StringLiteral{
Type: token.NonEmptyStringLiteral,
Value: "\"Hello \nWorld!!\"",
Position: pos(1, 1),
},
},
// {
// name: `Next token is \n`,
// input: "\"Hello World!!\"\n",
// want: &ast.StringLiteral{
// Value: `"Hello World!!"`,
// From: token.Pos{
// Column: 1,
// Line: 1,
// },
// To: token.Pos{
// Column: 15,
// Line: 1,
// },
// },
// err: nil,
// },
{
name: "Not Literal",
input: "pragma",
err: &token.PosError{
Pos: token.Pos{
Column: 1,
Line: 1,
},
Msg: "not found string literal quote",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(*testing.T) {
r := strings.NewReader(tt.input)
p := solparser.New(r)
got, err := p.ParseLiteral()
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)
}
})
}
}