Skip to content

Commit 6e04307

Browse files
Add tests for clobbered fields (#27)
Just testing for things that already work in advance of doing the work for #6
1 parent 8c9b964 commit 6e04307

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

pkg/server/definition_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,45 @@ func TestDefinition(t *testing.T) {
369369
End: protocol.Position{Line: 7, Character: 9},
370370
},
371371
},
372+
{
373+
name: "goto with overrides: clobber string",
374+
filename: "testdata/goto-overrides.jsonnet",
375+
position: protocol.Position{Line: 38, Character: 30},
376+
targetRange: protocol.Range{
377+
Start: protocol.Position{Line: 24, Character: 4},
378+
End: protocol.Position{Line: 24, Character: 23},
379+
},
380+
targetSelectionRange: protocol.Range{
381+
Start: protocol.Position{Line: 24, Character: 4},
382+
End: protocol.Position{Line: 24, Character: 10},
383+
},
384+
},
385+
{
386+
name: "goto with overrides: clobber nested string",
387+
filename: "testdata/goto-overrides.jsonnet",
388+
position: protocol.Position{Line: 39, Character: 44},
389+
targetRange: protocol.Range{
390+
Start: protocol.Position{Line: 26, Character: 6},
391+
End: protocol.Position{Line: 26, Character: 24},
392+
},
393+
targetSelectionRange: protocol.Range{
394+
Start: protocol.Position{Line: 26, Character: 6},
395+
End: protocol.Position{Line: 26, Character: 11},
396+
},
397+
},
398+
{
399+
name: "goto with overrides: clobber map",
400+
filename: "testdata/goto-overrides.jsonnet",
401+
position: protocol.Position{Line: 40, Character: 28},
402+
targetRange: protocol.Range{
403+
Start: protocol.Position{Line: 28, Character: 4},
404+
End: protocol.Position{Line: 28, Character: 15},
405+
},
406+
targetSelectionRange: protocol.Range{
407+
Start: protocol.Position{Line: 28, Character: 4},
408+
End: protocol.Position{Line: 28, Character: 11},
409+
},
410+
},
372411
}
373412
for _, tc := range testCases {
374413
t.Run(tc.name, func(t *testing.T) {
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
// 1. Initial definition
3+
a: {
4+
hello: 'world',
5+
nested1: {
6+
hello: 'world',
7+
},
8+
nested2: {
9+
hello: 'world',
10+
},
11+
},
12+
}
13+
+ {
14+
// 2. Override maps but keep string keys
15+
a+: {
16+
hello2: 'world2',
17+
nested1+: {
18+
hello2: 'world2',
19+
},
20+
},
21+
}
22+
+ {
23+
// 3. Clobber some attributes
24+
a+: {
25+
hello2: 'clobbered', // Clobber a string
26+
nested1+: {
27+
hello: 'clobbered', // Clobber a nested attribute
28+
},
29+
nested2: {}, // Clobber the whole map
30+
},
31+
}
32+
+ {
33+
map_overrides: self.a, // This should refer to all three definitions (initial + 2 overrides)
34+
nested_map_overrides: self.a.nested1, // This should refer to all three definitions (initial + 2 overrides)
35+
36+
carried_string: self.a.hello, // This should refer to the initial definition (map 1)
37+
carried_nested_string: self.a.nested1.hello2, // This should refer to the initial definition (map 2)
38+
39+
clobbered_string: self.a.hello2, // This should refer to the override only (map 3)
40+
clobbered_nested_string: self.a.nested1.hello, // This should refer to the override only (map 3)
41+
clobbered_map: self.a.nested2, // This should refer to the override only (map 3)
42+
}

0 commit comments

Comments
 (0)