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

Function TestMap

common/ast/expr_test.go:327–355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

325}
326
327func TestMap(t *testing.T) {
328 fac := ast.NewExprFactory()
329 expr := fac.NewMap(1,
330 []ast.EntryExpr{
331 fac.NewMapEntry(2, fac.NewIdent(3, "a"), fac.NewLiteral(4, types.True), true),
332 fac.NewMapEntry(5, fac.NewIdent(6, "b"), fac.NewLiteral(7, types.False), false),
333 })
334 m := expr.AsMap()
335 if m.Size() != 2 {
336 t.Errorf("map.Size() got %d, wanted 2", m.Size())
337 }
338 expr.RenumberIDs(testIDGen(50))
339 if expr.ID() != 51 {
340 t.Errorf("expr.ID() got %d, wanted 51", expr.ID())
341 }
342 if m.Entries()[0].ID() != 52 {
343 t.Errorf("m.Entries()[0].ID() got %d, wanted 52", m.Entries()[0].ID())
344 }
345 entry := m.Entries()[0].AsMapEntry()
346 if key := entry.Key(); key.ID() != 53 {
347 t.Errorf("key.ID() got %d, wanted 53", key.ID())
348 }
349 if val := entry.Value(); val.ID() != 54 {
350 t.Errorf("val.ID() got %d, wanted 54", val.ID())
351 }
352 if !entry.IsOptional() {
353 t.Error("entry.IsOptional() got false, wanted true")
354 }
355}
356
357func TestMapNil(t *testing.T) {
358 expr := nilTestExpr(t)

Callers

nothing calls this directly

Calls 15

NewMapMethod · 0.95
NewMapEntryMethod · 0.95
NewIdentMethod · 0.95
NewLiteralMethod · 0.95
NewExprFactoryFunction · 0.92
testIDGenFunction · 0.85
AsMapMethod · 0.65
SizeMethod · 0.65
RenumberIDsMethod · 0.65
IDMethod · 0.65
EntriesMethod · 0.65
AsMapEntryMethod · 0.65

Tested by

no test coverage detected