-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(symbol-table): read in template context with variables
- Loading branch information
Showing
7 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package lsp | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetContextForSelectorExpression(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
template string | ||
nodeContent string | ||
expected TemplateContext | ||
}{ | ||
{ | ||
desc: "Selects single selector expression correctly", | ||
template: `{{ .Values.test }}`, | ||
nodeContent: ".Values.test", | ||
expected: TemplateContext{"Values", "test"}, | ||
}, | ||
{ | ||
desc: "Selects selector expression with variable correctly", | ||
template: `{{ $x.test }}`, | ||
nodeContent: "$x.test", | ||
expected: TemplateContext{"$x", "test"}, | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
ast := ParseAst(nil, tC.template) | ||
node := ast.RootNode().Child(1) | ||
|
||
assert.Equal(t, tC.nodeContent, node.Content([]byte(tC.template))) | ||
result := getContextForSelectorExpression(node, []byte(tC.template)) | ||
|
||
assert.Equal(t, tC.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters