| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package tree |
| 16 |
|
| 17 |
import ( |
| 18 |
"reflect" |
| 19 |
"testing" |
| 20 |
) |
| 21 |
|
| 22 |
func TestFixLineColumn(t *testing.T) { |
| 23 |
tests := []struct { |
| 24 |
in []int64 |
| 25 |
src string |
| 26 |
out [][]int64 |
| 27 |
}{ |
| 28 |
{ |
| 29 |
in: []int64{0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9}, |
| 30 |
src: "01\n3\n567\n9", |
| 31 |
out: [][]int64{ |
| 32 |
{0, 1, 1}, |
| 33 |
{1, 1, 2}, |
| 34 |
{1, 1, 2}, |
| 35 |
{2, 1, 3}, |
| 36 |
{3, 2, 1}, |
| 37 |
{4, 2, 2}, |
| 38 |
{5, 3, 1}, |
| 39 |
{6, 3, 2}, |
| 40 |
{7, 3, 3}, |
| 41 |
{8, 3, 4}, |
| 42 |
{9, 4, 1}, |
| 43 |
}, |
| 44 |
}, |
| 45 |
} |
| 46 |
|
| 47 |
for i, test := range tests { |
| 48 |
p := make([]*Pos, len(test.in)) |
| 49 |
expected := make(map[int64]Pos, len(test.in)) |
| 50 |
for j, index := range test.in { |
| 51 |
p[j] = &Pos{Index: index} |
| 52 |
expected[test.out[j][0]] = Pos{ |
| 53 |
Index: test.out[j][0], |
| 54 |
Line: test.out[j][1], |
| 55 |
Column: test.out[j][2], |
| 56 |
} |
| 57 |
} |
| 58 |
fixLineColumn(p, []byte(test.src)) |
| 59 |
for _, pos := range p { |
| 60 |
exp := expected[pos.Index] |
| 61 |
if !reflect.DeepEqual(*pos, exp) { |
| 62 |
t.Errorf("#%d: expected %+v, got %+v:", i, exp, *pos) |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |