-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprocess_test.go
73 lines (67 loc) · 1.13 KB
/
process_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
package mold
import (
"strconv"
"testing"
)
func TestPos(t *testing.T) {
source := `<html>
<head>
<title>Test</title>
</head>
<body>
<p>Hello world</p>
</body>
</html>
`
tests := []struct {
body string
pos int
expectedLine int
expectedCol int
}{
{
body: "",
pos: 0,
expectedLine: 1,
expectedCol: 1,
},
{
body: source,
pos: 0,
expectedLine: 1,
expectedCol: 1,
},
{
body: source,
pos: 5,
expectedLine: 1,
expectedCol: 6,
},
{
body: source,
pos: 20,
expectedLine: 4,
expectedCol: 6,
},
{
body: source,
pos: 30,
expectedLine: 4,
expectedCol: 16,
},
{
body: source,
pos: 50,
expectedLine: 7,
expectedCol: 3,
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
line, col := pos(tt.body, tt.pos)
if line != tt.expectedLine || col != tt.expectedCol {
t.Errorf("pos(%q, %d) = (%d, %d), expected (%d, %d)", tt.body, tt.pos, line, col, tt.expectedLine, tt.expectedCol)
}
})
}
}