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

Function TestAstGrepAnalyzer

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

Source from the content-addressed store, hash-verified

22}
23
24func TestAstGrepAnalyzer(t *testing.T) {
25 analyzer := NewAstGrepAnalyzer()
26 if !analyzer.Available() {
27 t.Skip("ast-grep (sg) not installed")
28 }
29
30 // Test Go file
31 tmpDir := t.TempDir()
32 goFile := filepath.Join(tmpDir, "test.go")
33 os.WriteFile(goFile, []byte(`package main
34
35import (
36 "fmt"
37 "os"
38)
39
40func main() {
41 fmt.Println("hello")
42}
43
44func helper(x int) int {
45 return x * 2
46}
47`), 0644)
48
49 analysis, err := analyzer.AnalyzeFile(goFile)
50 if err != nil {
51 t.Fatalf("AnalyzeFile failed: %v", err)
52 }
53
54 if analysis == nil {
55 t.Fatal("Expected analysis, got nil")
56 }
57
58 // Check functions
59 funcs := make(map[string]bool)
60 for _, f := range analysis.Functions {
61 funcs[f] = true
62 }
63 if !funcs["main"] {
64 t.Error("Expected main function")
65 }
66 if !funcs["helper"] {
67 t.Error("Expected helper function")
68 }
69
70 // Check imports
71 imports := make(map[string]bool)
72 for _, i := range analysis.Imports {
73 imports[i] = true
74 }
75 if !imports["fmt"] {
76 t.Errorf("Expected fmt import, got: %v", analysis.Imports)
77 }
78 if !imports["os"] {
79 t.Errorf("Expected os import, got: %v", analysis.Imports)
80 }
81}

Callers

nothing calls this directly

Calls 4

NewAstGrepAnalyzerFunction · 0.85
AvailableMethod · 0.80
AnalyzeFileMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected