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

Function TestProtoMessageComprehensions

cel/cel_test.go:6800–6946  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6798}
6799
6800func TestProtoMessageComprehensions(t *testing.T) {
6801 allTwoVar := ReceiverMacro("all", 3,
6802 func(mef MacroExprFactory, target celast.Expr, args []celast.Expr) (celast.Expr, *Error) {
6803 return mef.NewComprehensionTwoVar(
6804 target,
6805 args[0].AsIdent(),
6806 args[1].AsIdent(),
6807 mef.AccuIdentName(),
6808 mef.NewLiteral(types.True),
6809 mef.NewCall(operators.NotStrictlyFalse, mef.NewAccuIdent()),
6810 mef.NewCall(operators.LogicalAnd, mef.NewAccuIdent(), args[2]),
6811 mef.NewAccuIdent(),
6812 ), nil
6813 })
6814 existsTwoVar := ReceiverMacro("exists", 3,
6815 func(mef MacroExprFactory, target celast.Expr, args []celast.Expr) (celast.Expr, *Error) {
6816 return mef.NewComprehensionTwoVar(
6817 target,
6818 args[0].AsIdent(),
6819 args[1].AsIdent(),
6820 mef.AccuIdentName(),
6821 mef.NewLiteral(types.False),
6822 mef.NewCall(operators.NotStrictlyFalse, mef.NewCall(operators.LogicalNot, mef.NewAccuIdent())),
6823 mef.NewCall(operators.LogicalOr, mef.NewAccuIdent(), args[2]),
6824 mef.NewAccuIdent(),
6825 ), nil
6826 })
6827
6828 env, err := NewEnv(
6829 OptionalTypes(),
6830 Macros(allTwoVar, existsTwoVar),
6831 Types(&proto3pb.TestAllTypes{}),
6832 Variable("msg", ObjectType("google.expr.proto3.test.TestAllTypes")),
6833 )
6834 if err != nil {
6835 t.Fatalf("NewEnv() failed: %v", err)
6836 }
6837
6838 anyNested1, err := anypb.New(&proto3pb.TestAllTypes_NestedMessage{Bb: 100})
6839 if err != nil {
6840 t.Fatalf("anypb.New() failed: %v", err)
6841 }
6842 anyNested2, err := anypb.New(&proto3pb.TestAllTypes_NestedMessage{Bb: 200})
6843 if err != nil {
6844 t.Fatalf("anypb.New() failed: %v", err)
6845 }
6846
6847 msg := &proto3pb.TestAllTypes{
6848 RepeatedNestedMessage: []*proto3pb.TestAllTypes_NestedMessage{
6849 {Bb: 1},
6850 {Bb: 2},
6851 {Bb: 3},
6852 },
6853 MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{
6854 1: {
6855 Payload: &proto3pb.TestAllTypes{
6856 SingleInt32: 10,
6857 SingleInt64Wrapper: wrapperspb.Int64(100),

Callers

nothing calls this directly

Calls 15

CompileMethod · 0.95
ProgramMethod · 0.95
ReceiverMacroFunction · 0.85
OptionalTypesFunction · 0.85
NewMethod · 0.80
ErrMethod · 0.80
NewEnvFunction · 0.70
MacrosFunction · 0.70
TypesFunction · 0.70
VariableFunction · 0.70
AsIdentMethod · 0.65

Tested by

no test coverage detected