Debian Codegraph @

tree/tree_test.go

raw symbols SCIP
1 // Copyright 2019 Red Hat, Inc
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.)
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 //list of index, line, col
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 }