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

Function TestInterpreter_ProtoAttributeOpt

interpreter/interpreter_test.go:1999–2044  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1997}
1998
1999func TestInterpreter_ProtoAttributeOpt(t *testing.T) {
2000 inst, _, err := program(t, &testCase{
2001 name: "nested_proto_field_with_index",
2002 expr: `pb3.map_int64_nested_type[0].child.payload.single_int32`,
2003 typeOpts: []types.RegistryOption{types.ProtoTypeDefs(&proto3pb.TestAllTypes{})},
2004 vars: []*decls.VariableDecl{
2005 decls.NewVariable("pb3",
2006 types.NewObjectType("google.expr.proto3.test.TestAllTypes")),
2007 },
2008 in: map[string]any{
2009 "pb3": &proto3pb.TestAllTypes{
2010 MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{
2011 0: {
2012 Child: &proto3pb.NestedTestAllTypes{
2013 Payload: &proto3pb.TestAllTypes{
2014 SingleInt32: 1,
2015 },
2016 },
2017 },
2018 },
2019 },
2020 },
2021 }, Optimize())
2022 if err != nil {
2023 t.Fatal(err)
2024 }
2025 attr, ok := inst.(InterpretableAttribute)
2026 if !ok {
2027 t.Fatalf("got %v, expected attribute value", inst)
2028 }
2029 absAttr, ok := attr.Attr().(NamespacedAttribute)
2030 if !ok {
2031 t.Fatalf("got %v, expected global attribute", attr.Attr())
2032 }
2033 quals := absAttr.Qualifiers()
2034 if len(quals) != 5 {
2035 t.Errorf("got %d qualifiers, wanted 5", len(quals))
2036 }
2037 if !isFieldQual(quals[0], "map_int64_nested_type") ||
2038 !isConstQual(quals[1], types.IntZero) ||
2039 !isFieldQual(quals[2], "child") ||
2040 !isFieldQual(quals[3], "payload") ||
2041 !isFieldQual(quals[4], "single_int32") {
2042 t.Error("unoptimized qualifier types present in optimized attribute")
2043 }
2044}
2045
2046func TestInterpreter_LogicalAndMissingType(t *testing.T) {
2047 parsed := testMustParse(t, `a && TestProto{c: true}.c`)

Callers

nothing calls this directly

Calls 10

ProtoTypeDefsFunction · 0.92
NewVariableFunction · 0.92
NewObjectTypeFunction · 0.92
programFunction · 0.85
OptimizeFunction · 0.85
isFieldQualFunction · 0.85
isConstQualFunction · 0.85
AttrMethod · 0.65
QualifiersMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected