Skip to content

Commit 8e3870f

Browse files
authored
Merge pull request #14 from utafrali/fix/issue-5-fix-r-function-name-resolution-all-funct
Add test for R function name resolution
2 parents 9ce3d27 + 351b9a3 commit 8e3870f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

internal/pipeline/astdump_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,40 @@ func TestLuaFuncAssignName(t *testing.T) {
367367
})
368368
}
369369
}
370+
371+
// TestRFuncAssignName verifies that rFuncAssignName correctly extracts
372+
// variable names for R function assignments.
373+
func TestRFuncAssignName(t *testing.T) {
374+
tests := []struct {
375+
name string
376+
code string
377+
wantName string
378+
}{
379+
{"arrow_assign", "add <- function(a, b) {\n\ta + b\n}\n", "add"},
380+
{"equals_assign", "square = function(n) {\n\tn * n\n}\n", "square"},
381+
{"double_arrow", "greet <<- function(x) x\n", "greet"},
382+
}
383+
384+
for _, tt := range tests {
385+
t.Run(tt.name, func(t *testing.T) {
386+
tree, src := parseSource(t, lang.R, tt.code)
387+
defer tree.Close()
388+
389+
var foundName string
390+
parser.Walk(tree.RootNode(), func(node *tree_sitter.Node) bool {
391+
if node.Kind() == "function_definition" {
392+
nameNode := rFuncAssignName(node)
393+
if nameNode != nil {
394+
foundName = parser.NodeText(nameNode, src)
395+
}
396+
return false
397+
}
398+
return true
399+
})
400+
401+
if foundName != tt.wantName {
402+
t.Errorf("rFuncAssignName: got %q, want %q", foundName, tt.wantName)
403+
}
404+
})
405+
}
406+
}

0 commit comments

Comments
 (0)