(t *testing.T)
| 33 | ) |
| 34 | |
| 35 | func TestRefValueToValueRoundTrip(t *testing.T) { |
| 36 | tests := []struct { |
| 37 | value any |
| 38 | }{ |
| 39 | {value: types.NullValue}, |
| 40 | {value: types.Bool(true)}, |
| 41 | {value: types.String("abc")}, |
| 42 | {value: types.Double(0.0)}, |
| 43 | {value: types.Bytes(make([]byte, 0, 5))}, |
| 44 | {value: types.Int(0)}, |
| 45 | {value: types.Uint(0)}, |
| 46 | {value: types.Duration{Duration: time.Hour}}, |
| 47 | {value: types.Timestamp{Time: time.Unix(0, 0)}}, |
| 48 | {value: types.IntType}, |
| 49 | {value: types.NewOpaqueType("CustomType")}, |
| 50 | {value: map[int64]int64{1: 1}}, |
| 51 | {value: []any{true, "abc"}}, |
| 52 | {value: &proto3pb.TestAllTypes{SingleString: "abc"}}, |
| 53 | } |
| 54 | |
| 55 | env, err := NewEnv(Types(&proto3pb.TestAllTypes{})) |
| 56 | if err != nil { |
| 57 | t.Fatalf("NewEnv() failed: %v", err) |
| 58 | } |
| 59 | |
| 60 | for i, tst := range tests { |
| 61 | tc := tst |
| 62 | t.Run(fmt.Sprintf("[%d]%v", i, tc.value), func(t *testing.T) { |
| 63 | refVal := env.TypeAdapter().NativeToValue(tc.value) |
| 64 | val, err := RefValueToValue(refVal) |
| 65 | if err != nil { |
| 66 | t.Fatalf("RefValueToValue(%v) failed with error: %v", refVal, err) |
| 67 | } |
| 68 | actual, err := ValueToRefValue(env.TypeAdapter(), val) |
| 69 | if err != nil { |
| 70 | t.Fatalf("ValueToRefValue() failed: %v", err) |
| 71 | } |
| 72 | if refVal.Equal(actual) != types.True { |
| 73 | t.Errorf("got val %v, wanted %v", actual, refVal) |
| 74 | } |
| 75 | }) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestAstToProto(t *testing.T) { |
| 80 | stdEnv, _ := NewEnv(Declarations( |
nothing calls this directly
no test coverage detected