(t *testing.T)
| 2590 | } |
| 2591 | |
| 2592 | func TestContextProto(t *testing.T) { |
| 2593 | descriptor := new(proto3pb.TestAllTypes).ProtoReflect().Descriptor() |
| 2594 | option := DeclareContextProto(descriptor) |
| 2595 | env := testEnv(t, option) |
| 2596 | expression := ` |
| 2597 | single_int64 == 1 |
| 2598 | && single_double == 1.0 |
| 2599 | && single_bool == true |
| 2600 | && single_string == '' |
| 2601 | && single_nested_message == google.expr.proto3.test.TestAllTypes.NestedMessage{} |
| 2602 | && standalone_enum == google.expr.proto3.test.TestAllTypes.NestedEnum.FOO |
| 2603 | && single_duration == duration('5s') |
| 2604 | && single_timestamp == timestamp(63154820) |
| 2605 | && single_any == null |
| 2606 | && single_uint32_wrapper == null |
| 2607 | && single_uint64_wrapper == 0u |
| 2608 | && repeated_int32 == [1,2] |
| 2609 | && map_string_string == {'': ''} |
| 2610 | && map_int64_nested_type == {0 : google.expr.proto3.test.NestedTestAllTypes{}}` |
| 2611 | ast, iss := env.Compile(expression) |
| 2612 | if iss.Err() != nil { |
| 2613 | t.Fatalf("env.Compile(%s) failed: %s", expression, iss.Err()) |
| 2614 | } |
| 2615 | prg, err := env.Program(ast) |
| 2616 | if err != nil { |
| 2617 | t.Fatalf("env.Program() failed: %v", err) |
| 2618 | } |
| 2619 | in := &proto3pb.TestAllTypes{ |
| 2620 | SingleInt64: 1, |
| 2621 | SingleDouble: 1.0, |
| 2622 | SingleBool: true, |
| 2623 | NestedType: &proto3pb.TestAllTypes_SingleNestedMessage{ |
| 2624 | SingleNestedMessage: &proto3pb.TestAllTypes_NestedMessage{}, |
| 2625 | }, |
| 2626 | StandaloneEnum: proto3pb.TestAllTypes_FOO, |
| 2627 | SingleDuration: &durationpb.Duration{Seconds: 5}, |
| 2628 | SingleTimestamp: ×tamppb.Timestamp{ |
| 2629 | Seconds: 63154820, |
| 2630 | }, |
| 2631 | SingleUint64Wrapper: wrapperspb.UInt64(0), |
| 2632 | RepeatedInt32: []int32{1, 2}, |
| 2633 | MapStringString: map[string]string{"": ""}, |
| 2634 | MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{0: {}}, |
| 2635 | } |
| 2636 | vars, err := ContextProtoVars(in) |
| 2637 | if err != nil { |
| 2638 | t.Fatalf("ContextProtoVars(%v) failed: %v", in, err) |
| 2639 | } |
| 2640 | out, _, err := prg.Eval(vars) |
| 2641 | if err != nil { |
| 2642 | t.Fatalf("prg.Eval() failed: %v", err) |
| 2643 | } |
| 2644 | if out.Equal(types.True) != types.True { |
| 2645 | t.Errorf("prg.Eval() got %v, wanted true", out) |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | func TestContextProtoJSONFieldNames(t *testing.T) { |
nothing calls this directly
no test coverage detected