MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestSourceInfoNilSafety

Function TestSourceInfoNilSafety

common/ast/ast_test.go:211–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

209}
210
211func TestSourceInfoNilSafety(t *testing.T) {
212 info, err := ast.ProtoToSourceInfo(nil)
213 if err != nil {
214 t.Fatalf("ast.ProtoToSourceInfo() failed: %v", err)
215 }
216 tests := []*ast.SourceInfo{
217 nil,
218 info,
219 ast.NewSourceInfo(nil),
220 }
221 for i, tst := range tests {
222 tc := tst
223 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
224 testInfo := tc
225 if testInfo.SyntaxVersion() != "" {
226 t.Errorf("SyntaxVersion() got %s, wanted empty string", testInfo.SyntaxVersion())
227 }
228 if testInfo.Description() != "" {
229 t.Errorf("Description() got %s, wanted empty string", testInfo.Description())
230 }
231 if len(testInfo.LineOffsets()) != 0 {
232 t.Errorf("LineOffsets() got %v, wanted empty list", testInfo.LineOffsets())
233 }
234 if len(testInfo.MacroCalls()) != 0 {
235 t.Errorf("MacroCalls() got %v, wanted empty map", testInfo.MacroCalls())
236 }
237 if len(testInfo.Extensions()) != 0 {
238 t.Errorf("Extensions() got %v, wanted empty list", testInfo.Extensions())
239 }
240 if call, found := testInfo.GetMacroCall(0); found {
241 t.Errorf("GetMacroCall(0) got %v, wanted not found", call)
242 }
243 if r, found := testInfo.GetOffsetRange(0); found {
244 t.Errorf("GetOffsetRange(0) got %v, wanted not found", r)
245 }
246 if loc := testInfo.GetStartLocation(0); loc != common.NoLocation {
247 t.Errorf("GetStartLocation(0) got %v, wanted no location", loc)
248 }
249 if loc := testInfo.GetStopLocation(0); loc != common.NoLocation {
250 t.Errorf("GetStopLocation(0) got %v, wanted no location", loc)
251 }
252 if off := testInfo.ComputeOffset(1, 0); off != 0 {
253 t.Errorf("ComputeOffset(1, 0) got %d, wanted 0", off)
254 }
255 if off := testInfo.ComputeOffset(-2, 0); off != -1 {
256 t.Errorf("ComputeOffset(-2, 0) got %d, wanted -1", off)
257 }
258 if off := testInfo.ComputeOffset(2, 0); off != -1 {
259 t.Errorf("ComputeOffset(2, 0) got %d, wanted -1", off)
260 }
261 })
262 }
263}
264
265func TestReferenceInfoEquals(t *testing.T) {
266 tests := []struct {

Callers

nothing calls this directly

Calls 12

ProtoToSourceInfoFunction · 0.92
NewSourceInfoFunction · 0.92
SyntaxVersionMethod · 0.80
ExtensionsMethod · 0.80
GetMacroCallMethod · 0.80
GetOffsetRangeMethod · 0.80
GetStartLocationMethod · 0.80
GetStopLocationMethod · 0.80
ComputeOffsetMethod · 0.80
DescriptionMethod · 0.65
LineOffsetsMethod · 0.65
MacroCallsMethod · 0.45

Tested by

no test coverage detected