-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpos_test.go
55 lines (50 loc) · 900 Bytes
/
pos_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
package ybase_test
import (
"fmt"
"testing"
"github.com/berquerant/ybase"
"github.com/stretchr/testify/assert"
)
func TestPos(t *testing.T) {
p := ybase.NewPos(1, 0, 0)
const str = "aあ\nb"
for i, tc := range []struct {
line int
col int
offset int
}{
{
line: 1,
col: 1,
offset: 1,
},
{
line: 1,
col: 2,
offset: 4,
},
{
line: 2,
col: 0,
offset: 5,
},
{
line: 2,
col: 1,
offset: 6,
},
} {
r := []rune(str)[i]
tc := tc
t.Run(fmt.Sprintf("Add %s", string(r)), func(t *testing.T) {
p = p.Add(r)
assert.Equal(t, tc.line, p.Line(), "line")
assert.Equal(t, tc.col, p.Column(), "col")
assert.Equal(t, tc.offset, p.Offset(), "offset")
rsize := len([]byte(string(r)))
start := p.Offset() - rsize
end := p.Offset()
assert.Equal(t, string(r), string(str[start:end]), "rune")
})
}
}