forked from jackc/tern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_line_extract_test.go
104 lines (99 loc) · 1.67 KB
/
error_line_extract_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
98
99
100
101
102
103
104
package main
import (
"testing"
)
func TestErrorLineExtract(t *testing.T) {
tests := []struct {
source string
position int
ele ErrorLineExtract
errMsg string
}{
{
source: "single line",
position: 3,
ele: ErrorLineExtract{
LineNum: 1,
ColumnNum: 3,
Text: "single line",
},
errMsg: "",
},
{
source: "bad position",
position: 32,
ele: ErrorLineExtract{},
errMsg: "position (32) is greater than source length (12)",
},
{
source: `multi
line
text`,
position: 8,
ele: ErrorLineExtract{
LineNum: 2,
ColumnNum: 2,
Text: "line",
},
errMsg: "",
},
{
source: `last
line
error`,
position: 13,
ele: ErrorLineExtract{
LineNum: 3,
ColumnNum: 3,
Text: "error",
},
errMsg: "",
},
{
source: `first
character
first
line
error`,
position: 1,
ele: ErrorLineExtract{
LineNum: 1,
ColumnNum: 1,
Text: "first",
},
errMsg: "",
},
{
source: `last
character
last
line
error`,
position: 30,
ele: ErrorLineExtract{
LineNum: 5,
ColumnNum: 5,
Text: "error",
},
errMsg: "",
},
}
for i, tt := range tests {
ele, err := ExtractErrorLine(tt.source, tt.position)
if err != nil {
if tt.errMsg == "" {
t.Errorf("%d. Expected success but received err %v", i, err)
} else if err.Error() != tt.errMsg {
t.Errorf("%d. Expected err %v, but received %v", i, tt.errMsg, err)
}
continue
}
if tt.errMsg != "" {
t.Errorf("%d. Expected err %v, but it succeeded", i, tt.errMsg)
continue
}
if ele != tt.ele {
t.Errorf("%d. Expected %v, but received %v", i, tt.ele, ele)
}
}
}