Skip to content

Commit

Permalink
[FIX] repair tests after grammar update
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Nov 1, 2023
1 parent 4932bd3 commit 8496d3a
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions internal/lsp/ast_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestGetVariableDefinitionDirectDecleration(t *testing.T) {
t.Errorf("Parsing did not work")
}

usageNode := node.NamedChild(3)
usageNode := node.NamedChild(1)
definitionNode := GetVariableDefinitionOfNode(usageNode, template)

if definitionNode == nil {
Expand All @@ -44,7 +44,7 @@ func TestGetVariableDefinitionOtherDecleration(t *testing.T) {
t.Errorf("Parsing did not work")
}

usageNode := node.NamedChild(5)
usageNode := node.NamedChild(2)
definitionNode := GetVariableDefinitionOfNode(usageNode, template)

if definitionNode == nil {
Expand All @@ -56,18 +56,35 @@ func TestGetVariableDefinitionOtherDecleration(t *testing.T) {
}

func TestGetVariableDefinitionRange(t *testing.T) {
var template = `
{{ range $index, $element := pipeline }}{{ $index }}{{ $element }}{{ end }}
`
var template = `{{ range $index, $element := pipeline }}{{ $index }}{{ $element }}{{ end }}`
// (template [0, 0] - [1, 0]
// (range_action [0, 0] - [0, 75]
// (range_variable_definition [0, 9] - [0, 37]
// index: (variable [0, 9] - [0, 15]
// name: (identifier [0, 10] - [0, 15]))
// element: (variable [0, 17] - [0, 25]
// name: (identifier [0, 18] - [0, 25]))
// range: (function_call [0, 29] - [0, 37]
// function: (identifier [0, 29] - [0, 37])))
// body: (variable [0, 43] - [0, 49]
// name: (identifier [0, 44] - [0, 49]))
// body: (variable [0, 55] - [0, 63]
// name: (identifier [0, 56] - [0, 63]))))

node, err := sitter.ParseCtx(context.Background(), []byte(template), gotemplate.GetLanguage())

if err != nil {
t.Errorf("Parsing did not work")
}

elementUsageNode := node.NamedChild(1).NamedChild(2)
logger.Println(elementUsageNode.Content([]byte(template))) // $element
elementUsageNode_start := sitter.Point{Row: 0, Column: 55}
elementUsageNode := node.NamedDescendantForPointRange(elementUsageNode_start, elementUsageNode_start)
if elementUsageNode == nil {
t.Errorf("Could not get elementUsageNode")
}
if elementUsageNode.Content([]byte(template)) != "$element" {
t.Errorf("Definition did not match but was %s", elementUsageNode.Content([]byte(template)))
}
definitionNode := GetVariableDefinitionOfNode(elementUsageNode, template)

if definitionNode == nil {
Expand All @@ -76,8 +93,14 @@ func TestGetVariableDefinitionRange(t *testing.T) {
t.Errorf("Definition did not match but was %s", definitionNode.Content([]byte(template)))
}

indexUsageNode := node.NamedChild(1).NamedChild(1)
logger.Println(elementUsageNode.Content([]byte(template))) // $index
indexUsageNode_start := sitter.Point{Row: 0, Column: 43}
indexUsageNode := node.NamedDescendantForPointRange(indexUsageNode_start, indexUsageNode_start)
if indexUsageNode == nil {
t.Errorf("Could not get indexUsageNode")
}
if indexUsageNode.Content([]byte(template)) != "$index" {
t.Errorf("Definition did not match but was %s", indexUsageNode.Content([]byte(template)))
}
definitionNode = GetVariableDefinitionOfNode(indexUsageNode, template)

if definitionNode == nil {
Expand Down

0 comments on commit 8496d3a

Please sign in to comment.