forked from hashicorp/hcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigation_test.go
61 lines (55 loc) · 1.02 KB
/
navigation_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package json
import (
"fmt"
"strconv"
"testing"
)
func TestNavigationContextString(t *testing.T) {
src := `
{
"version": 1,
"resource": {
"null_resource": {
"baz": {
"id": "foo"
},
"boz": [
{
"ov": { }
}
]
}
}
}
`
file, diags := Parse([]byte(src), "test.json")
if len(diags) != 0 {
fmt.Printf("offset %d\n", diags[0].Subject.Start.Byte)
t.Errorf("Unexpected diagnostics: %s", diags)
}
if file == nil {
t.Fatalf("Got nil file")
}
nav := file.Nav.(navigation)
tests := []struct {
Offset int
Want string
}{
{0, ``},
{8, ``},
{36, `resource`},
{60, `resource.null_resource`},
{89, `resource.null_resource.baz`},
{141, `resource.null_resource.boz`},
}
for _, test := range tests {
t.Run(strconv.Itoa(test.Offset), func(t *testing.T) {
got := nav.ContextString(test.Offset)
if got != test.Want {
t.Errorf("wrong result\ngot: %s\nwant: %s", got, test.Want)
}
})
}
}