-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
97 lines (84 loc) · 2.71 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
95
96
97
package markers
import (
"errors"
"github.com/stretchr/testify/assert"
"go/token"
"testing"
)
func TestNewError(t *testing.T) {
err := NewError(errors.New("anyError"), "anyFileName", Position{
Line: 2,
Column: 4,
})
assert.Equal(t, Error{
FileName: "anyFileName",
Position: Position{
Line: 2,
Column: 4,
},
error: errors.New("anyError"),
}, err)
}
func TestScannerError_Error(t *testing.T) {
scannerError := &ScannerError{
Message: "anyErrorMessage",
}
assert.Equal(t, "anyErrorMessage", scannerError.Error())
}
func TestImportError_Error(t *testing.T) {
importErr := &ImportError{
Marker: "anyMarker",
}
assert.Equal(t, "the marker 'anyMarker' cannot be resolved", importErr.Error())
}
func TestToParseError(t *testing.T) {
err := errors.New("anyError")
convertedError := toParseError(err, nil, token.Position{
Filename: "anyFileName",
Offset: 0,
Line: 10,
Column: 13,
})
assert.NotNil(t, convertedError)
parserError, isParserError := convertedError.(ParserError)
assert.NotNil(t, convertedError)
assert.True(t, isParserError)
assert.Equal(t, err, parserError.error)
assert.Equal(t, "anyFileName", parserError.FileName)
assert.Equal(t, Position{Line: 10, Column: 13}, parserError.Position)
}
func TestErrorList_ToErrors(t *testing.T) {
errorSlice := []error{errors.New("anyError1"), errors.New("anyError2")}
anyErrorList := NewErrorList(errorSlice)
assert.Equal(t, errorSlice, anyErrorList.(ErrorList).ToErrors())
}
func TestErrorList_Error(t *testing.T) {
anyErrorList := NewErrorList([]error{errors.New("anyError1"), errors.New("anyError2")})
assert.Equal(t, "[anyError1 anyError2]", anyErrorList.Error())
}
func TestToParseErrorWithErrorList(t *testing.T) {
anyErrorList := NewErrorList([]error{errors.New("anyError1"), errors.New("anyError2")})
convertedError := toParseError(anyErrorList, nil, token.Position{
Filename: "anyFileName",
Offset: 0,
Line: 10,
Column: 13,
})
assert.NotNil(t, convertedError)
errorList, isErrorList := convertedError.(ErrorList)
assert.NotNil(t, convertedError)
assert.True(t, isErrorList)
assert.Len(t, errorList, 2)
parserError, isParserError := errorList[0].(ParserError)
assert.NotNil(t, convertedError)
assert.True(t, isParserError)
assert.Equal(t, "anyError1", parserError.error.Error())
assert.Equal(t, "anyFileName", parserError.FileName)
assert.Equal(t, Position{Line: 10, Column: 13}, parserError.Position)
parserError, isParserError = errorList[1].(ParserError)
assert.NotNil(t, convertedError)
assert.True(t, isParserError)
assert.Equal(t, "anyError2", parserError.error.Error())
assert.Equal(t, "anyFileName", parserError.FileName)
assert.Equal(t, Position{Line: 10, Column: 13}, parserError.Position)
}