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

Function TestAstGrepCSharp

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

Source from the content-addressed store, hash-verified

124}
125
126func TestAstGrepCSharp(t *testing.T) {
127 analyzer := NewAstGrepAnalyzer()
128 if !analyzer.Available() {
129 t.Skip("ast-grep (sg) not installed")
130 }
131
132 tmpDir := t.TempDir()
133 csFile := filepath.Join(tmpDir, "Program.cs")
134 os.WriteFile(csFile, []byte(`using System;
135using System.Collections.Generic;
136using System.Linq;
137
138namespace TestApp
139{
140 public class Program
141 {
142 public static void Main(string[] args)
143 {
144 Console.WriteLine("Hello");
145 }
146
147 public int Calculate(int x)
148 {
149 return x * 2;
150 }
151 }
152}
153`), 0644)
154
155 analysis, err := analyzer.AnalyzeFile(csFile)
156 if err != nil {
157 t.Fatalf("AnalyzeFile failed: %v", err)
158 }
159
160 if analysis == nil {
161 t.Fatal("Expected analysis, got nil")
162 }
163
164 funcs := make(map[string]bool)
165 for _, f := range analysis.Functions {
166 funcs[f] = true
167 }
168 if !funcs["Main"] {
169 t.Errorf("Expected Main function, got: %v", analysis.Functions)
170 }
171 if !funcs["Calculate"] {
172 t.Errorf("Expected Calculate function, got: %v", analysis.Functions)
173 }
174
175 imports := make(map[string]bool)
176 for _, i := range analysis.Imports {
177 imports[i] = true
178 }
179 if !imports["System"] {
180 t.Errorf("Expected System import, got: %v", analysis.Imports)
181 }
182 if !imports["System.Collections.Generic"] {
183 t.Errorf("Expected System.Collections.Generic import, got: %v", analysis.Imports)

Callers

nothing calls this directly

Calls 3

NewAstGrepAnalyzerFunction · 0.85
AvailableMethod · 0.80
AnalyzeFileMethod · 0.80

Tested by

no test coverage detected