(t *testing.T)
| 2399 | } |
| 2400 | |
| 2401 | func TestContextProto(t *testing.T) { |
| 2402 | descriptor := new(proto3pb.TestAllTypes).ProtoReflect().Descriptor() |
| 2403 | option := DeclareContextProto(descriptor) |
| 2404 | env := testEnv(t, option) |
| 2405 | expression := ` |
| 2406 | single_int64 == 1 |
| 2407 | && single_double == 1.0 |
| 2408 | && single_bool == true |
| 2409 | && single_string == '' |
| 2410 | && single_nested_message == google.expr.proto3.test.TestAllTypes.NestedMessage{} |
| 2411 | && standalone_enum == google.expr.proto3.test.TestAllTypes.NestedEnum.FOO |
| 2412 | && single_duration == duration('5s') |
| 2413 | && single_timestamp == timestamp(63154820) |
| 2414 | && single_any == null |
| 2415 | && single_uint32_wrapper == null |
| 2416 | && single_uint64_wrapper == 0u |
| 2417 | && repeated_int32 == [1,2] |
| 2418 | && map_string_string == {'': ''} |
| 2419 | && map_int64_nested_type == {0 : google.expr.proto3.test.NestedTestAllTypes{}}` |
| 2420 | ast, iss := env.Compile(expression) |
| 2421 | if iss.Err() != nil { |
| 2422 | t.Fatalf("env.Compile(%s) failed: %s", expression, iss.Err()) |
| 2423 | } |
| 2424 | prg, err := env.Program(ast) |
| 2425 | if err != nil { |
| 2426 | t.Fatalf("env.Program() failed: %v", err) |
| 2427 | } |
| 2428 | in := &proto3pb.TestAllTypes{ |
| 2429 | SingleInt64: 1, |
| 2430 | SingleDouble: 1.0, |
| 2431 | SingleBool: true, |
| 2432 | NestedType: &proto3pb.TestAllTypes_SingleNestedMessage{ |
| 2433 | SingleNestedMessage: &proto3pb.TestAllTypes_NestedMessage{}, |
| 2434 | }, |
| 2435 | StandaloneEnum: proto3pb.TestAllTypes_FOO, |
| 2436 | SingleDuration: &durationpb.Duration{Seconds: 5}, |
| 2437 | SingleTimestamp: ×tamppb.Timestamp{ |
| 2438 | Seconds: 63154820, |
| 2439 | }, |
| 2440 | SingleUint64Wrapper: wrapperspb.UInt64(0), |
| 2441 | RepeatedInt32: []int32{1, 2}, |
| 2442 | MapStringString: map[string]string{"": ""}, |
| 2443 | MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{0: {}}, |
| 2444 | } |
| 2445 | vars, err := ContextProtoVars(in) |
| 2446 | if err != nil { |
| 2447 | t.Fatalf("ContextProtoVars(%v) failed: %v", in, err) |
| 2448 | } |
| 2449 | out, _, err := prg.Eval(vars) |
| 2450 | if err != nil { |
| 2451 | t.Fatalf("prg.Eval() failed: %v", err) |
| 2452 | } |
| 2453 | if out.Equal(types.True) != types.True { |
| 2454 | t.Errorf("prg.Eval() got %v, wanted true", out) |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | func TestContextProtoJSONFieldNames(t *testing.T) { |
nothing calls this directly
no test coverage detected