-
Notifications
You must be signed in to change notification settings - Fork 19
/
error_test.go
94 lines (89 loc) · 1.74 KB
/
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
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
package memefish
import (
"strings"
"testing"
"github.com/MakeNowJust/heredoc/v2"
"github.com/cloudspannerecosystem/memefish/token"
)
func TestMultiError(t *testing.T) {
err1 := &Error{
Message: "error 1",
Position: &token.Position{
FilePath: "foo",
Pos: 0,
End: 1,
Line: 0,
Column: 0,
EndLine: 0,
EndColumn: 1,
Source: " 1| a b\n | ^",
},
}
err2 := &Error{
Message: "error 2",
Position: &token.Position{
FilePath: "foo",
Pos: 2,
End: 3,
Line: 0,
Column: 2,
EndLine: 0,
EndColumn: 3,
Source: " 1| a b\n | ^",
},
}
for _, testCase := range []struct {
list MultiError
error string
fullError string
}{
{
MultiError{},
"(0 errors)",
"",
},
{
MultiError{err1},
"syntax error: foo:1:1: error 1",
heredoc.Doc(`
syntax error: foo:1:1: error 1
1| a b
| ^
`),
},
{
MultiError{err1, err2},
"syntax error: foo:1:1: error 1 (and 1 other error)",
heredoc.Doc(`
syntax error: foo:1:1: error 1
1| a b
| ^
syntax error: foo:1:3: error 2
1| a b
| ^
`),
},
{
MultiError{err1, err2, err2},
"syntax error: foo:1:1: error 1 (and 2 other errors)",
heredoc.Doc(`
syntax error: foo:1:1: error 1
1| a b
| ^
syntax error: foo:1:3: error 2
1| a b
| ^
syntax error: foo:1:3: error 2
1| a b
| ^
`),
},
} {
if testCase.list.Error() != strings.TrimRight(testCase.error, "\n") {
t.Errorf("error on MultiError.Error():\n%s", testCase.list.Error())
}
if testCase.list.FullError() != testCase.fullError {
t.Errorf("error on MultiError.FullError():\n%s", testCase.list.FullError())
}
}
}