@@ -264,6 +264,15 @@ TEST(Value, BasicSemantics) {
264264 v.resize (10 );
265265 TestBasicSemantics (v);
266266
267+ for (auto x : {Interval (), MakeInterval (" P1Y1M1D" ).value ()}) {
268+ SCOPED_TRACE (" Testing: google::cloud::spanner::Interval " + std::string{x});
269+ TestBasicSemantics (x);
270+ TestBasicSemantics (std::vector<Interval>(5 , x));
271+ std::vector<absl::optional<Interval>> v (5 , x);
272+ v.resize (10 );
273+ TestBasicSemantics (v);
274+ }
275+
267276 for (auto x : {testing::Genre::POP, testing::Genre::JAZZ,
268277 testing::Genre::FOLK, testing::Genre::ROCK}) {
269278 SCOPED_TRACE (" Testing: ProtoEnum<testing::Genre> " +
@@ -922,6 +931,24 @@ TEST(Value, ProtoConversionDate) {
922931 }
923932}
924933
934+ TEST (Value, ProtoConversionInterval) {
935+ for (auto const & x : std::vector<Interval>{
936+ MakeInterval (" -P178000Y" ).value (),
937+ MakeInterval (" -P1Y2M3DT4H5M6.789S" ).value (),
938+ MakeInterval (" -PT0.000001S" ).value (),
939+ Interval (),
940+ MakeInterval (" PT0.000001S" ).value (),
941+ MakeInterval (" P1Y2M3DT4H5M6.789S" ).value (),
942+ MakeInterval (" P178000Y" ).value (),
943+ }) {
944+ Value const v (x);
945+ auto const p = spanner_internal::ToProto (v);
946+ EXPECT_EQ (v, spanner_internal::FromProto (p.first , p.second ));
947+ EXPECT_EQ (google::spanner::v1::TypeCode::INTERVAL, p.first .code ());
948+ EXPECT_EQ (std::string{x}, p.second .string_value ());
949+ }
950+ }
951+
925952TEST (Value, ProtoConversionProtoEnum) {
926953 for (auto e : {testing::Genre::POP, testing::Genre::JAZZ,
927954 testing::Genre::FOLK, testing::Genre::ROCK}) {
@@ -1251,6 +1278,24 @@ TEST(Value, GetBadDate) {
12511278 EXPECT_THAT (v.get <absl::CivilDay>(), Not (IsOk ()));
12521279}
12531280
1281+ TEST (Value, GetBadInterval) {
1282+ Value v (Interval{});
1283+ ClearProtoKind (v);
1284+ EXPECT_THAT (v.get <Interval>(), Not (IsOk ()));
1285+
1286+ SetProtoKind (v, google::protobuf::NULL_VALUE);
1287+ EXPECT_THAT (v.get <Interval>(), Not (IsOk ()));
1288+
1289+ SetProtoKind (v, true );
1290+ EXPECT_THAT (v.get <Interval>(), Not (IsOk ()));
1291+
1292+ SetProtoKind (v, 0.0 );
1293+ EXPECT_THAT (v.get <Interval>(), Not (IsOk ()));
1294+
1295+ SetProtoKind (v, " blah" );
1296+ EXPECT_THAT (v.get <Interval>(), Not (IsOk ()));
1297+ }
1298+
12541299TEST (Value, GetBadProtoEnum) {
12551300 Value v (ProtoEnum<testing::Genre>{});
12561301 ClearProtoKind (v);
@@ -1429,6 +1474,7 @@ TEST(Value, OutputStream) {
14291474 {Value (PgOid (1234567890 )), " 1234567890" , normal},
14301475 {Value (absl::CivilDay ()), " 1970-01-01" , normal},
14311476 {Value (Timestamp ()), " 1970-01-01T00:00:00Z" , normal},
1477+ {Value (Interval ()), " P0D" , normal},
14321478 {Value (ProtoEnum<testing::Genre>(testing::Genre::POP)),
14331479 " google.cloud.spanner.testing.POP" , normal},
14341480 {Value (ProtoMessage<testing::SingerInfo>(singer)),
@@ -1462,6 +1508,7 @@ TEST(Value, OutputStream) {
14621508 {MakeNullValue<PgOid>(), " NULL" , normal},
14631509 {MakeNullValue<absl::CivilDay>(), " NULL" , normal},
14641510 {MakeNullValue<Timestamp>(), " NULL" , normal},
1511+ {MakeNullValue<Interval>(), " NULL" , normal},
14651512 {MakeNullValue<ProtoEnum<testing::Genre>>(), " NULL" , normal},
14661513 {MakeNullValue<ProtoMessage<testing::SingerInfo>>(), " NULL" , normal},
14671514
@@ -1482,6 +1529,7 @@ TEST(Value, OutputStream) {
14821529 {Value (std::vector<absl::CivilDay>{2 }), " [1970-01-01, 1970-01-01]" ,
14831530 normal},
14841531 {Value (std::vector<Timestamp>{1 }), " [1970-01-01T00:00:00Z]" , normal},
1532+ {Value (std::vector<Interval>{1 }), " [P0D]" , normal},
14851533 {Value (std::vector<ProtoEnum<testing::Genre>>{testing::JAZZ,
14861534 testing::FOLK}),
14871535 " [google.cloud.spanner.testing.JAZZ, google.cloud.spanner.testing.FOLK]" ,
@@ -1507,6 +1555,7 @@ TEST(Value, OutputStream) {
15071555 {MakeNullValue<std::vector<Numeric>>(), " NULL" , normal},
15081556 {MakeNullValue<std::vector<absl::CivilDay>>(), " NULL" , normal},
15091557 {MakeNullValue<std::vector<Timestamp>>(), " NULL" , normal},
1558+ {MakeNullValue<std::vector<Interval>>(), " NULL" , normal},
15101559 {MakeNullValue<std::vector<ProtoEnum<testing::Genre>>>(), " NULL" , normal},
15111560 {MakeNullValue<std::vector<ProtoMessage<testing::SingerInfo>>>(), " NULL" ,
15121561 normal},
@@ -1657,6 +1706,10 @@ TEST(Value, OutputStreamMatchesT) {
16571706 StreamMatchesValueStream (Timestamp ());
16581707 StreamMatchesValueStream (MakeTimestamp (MakeTime (1 , 1 )).value ());
16591708
1709+ // Interval
1710+ StreamMatchesValueStream (Interval ());
1711+ StreamMatchesValueStream (MakeInterval (" P1Y2M3DT4H5M6.789S" ).value ());
1712+
16601713 // ProtoEnum
16611714 StreamMatchesValueStream (ProtoEnum<testing::Genre>());
16621715 StreamMatchesValueStream (ProtoEnum<testing::Genre>(testing::ROCK));
0 commit comments