MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestAstGrepPython

Function TestAstGrepPython

scanner/astgrep_test.go:83–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestAstGrepPython(t *testing.T) {
84 analyzer := NewAstGrepAnalyzer()
85 if !analyzer.Available() {
86 t.Skip("ast-grep (sg) not installed")
87 }
88
89 tmpDir := t.TempDir()
90 pyFile := filepath.Join(tmpDir, "test.py")
91 os.WriteFile(pyFile, []byte(`import os
92from pathlib import Path
93
94def hello(name):
95 print(f"Hello {name}")
96
97def greet():
98 pass
99`), 0644)
100
101 analysis, err := analyzer.AnalyzeFile(pyFile)
102 if err != nil {
103 t.Fatalf("AnalyzeFile failed: %v", err)
104 }
105
106 funcs := make(map[string]bool)
107 for _, f := range analysis.Functions {
108 funcs[f] = true
109 }
110 if !funcs["hello"] {
111 t.Errorf("Expected hello function, got: %v", analysis.Functions)
112 }
113 if !funcs["greet"] {
114 t.Errorf("Expected greet function, got: %v", analysis.Functions)
115 }
116
117 imports := make(map[string]bool)
118 for _, i := range analysis.Imports {
119 imports[i] = true
120 }
121 if !imports["os"] {
122 t.Errorf("Expected os import, got: %v", analysis.Imports)
123 }
124}
125
126func TestAstGrepCSharp(t *testing.T) {
127 analyzer := NewAstGrepAnalyzer()

Callers

nothing calls this directly

Calls 3

NewAstGrepAnalyzerFunction · 0.85
AvailableMethod · 0.80
AnalyzeFileMethod · 0.80

Tested by

no test coverage detected