-
Notifications
You must be signed in to change notification settings - Fork 0
/
position_test.go
46 lines (43 loc) · 925 Bytes
/
position_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
package peg
import "testing"
// Test if position calculator works correctly.
func TestPositionCalculator(t *testing.T) {
data := []struct {
text string
inputs []int
outputs []Position
}{
{"", []int{0}, []Position{{0, 0, 0}}},
{"A\n", []int{0, 1, 2}, []Position{
{0, 0, 0},
{1, 0, 1},
{2, 1, 0},
}},
{"\nAA\r\r\nA\n\n", []int{1, 3, 4, 5, 6, 9}, []Position{
{1, 1, 0},
{3, 1, 2},
{4, 2, 0},
{5, 2, 1},
{6, 3, 0},
{9, 5, 0},
}},
{"\nAA\r\r\nA\n\n", []int{1, 5, 3, 4, 6, 9}, []Position{
{1, 1, 0},
{5, 2, 1},
{3, 1, 2},
{4, 2, 0},
{6, 3, 0},
{9, 5, 0},
}},
}
for _, d := range data {
pcalc := &positionCalculator{text: d.text}
for i := range d.inputs {
pos := pcalc.calculate(d.inputs[i])
if d.outputs[i] != pos {
t.Errorf("%q.position(%d) => %v != %v (lnends=%v)",
d.text, d.inputs[i], pos, d.outputs[i], pcalc.lnends)
}
}
}
}