@@ -448,10 +448,17 @@ var marshalingTests = []struct {
448448 {"Any with message and indent" , marshalerAllOptions , anySimple , anySimplePrettyJSON },
449449 {"Any with WKT" , marshaler , anyWellKnown , anyWellKnownJSON },
450450 {"Any with WKT and indent" , marshalerAllOptions , anyWellKnown , anyWellKnownPrettyJSON },
451- {"Duration" , marshaler , & pb2.KnownTypes {Dur : & durpb.Duration {Seconds : 3 }}, `{"dur":"3s"}` },
452- {"Duration" , marshaler , & pb2.KnownTypes {Dur : & durpb.Duration {Seconds : 3 , Nanos : 1e6 }}, `{"dur":"3.001s"}` },
453- {"Duration beyond float64 precision" , marshaler , & pb2.KnownTypes {Dur : & durpb.Duration {Seconds : 100000000 , Nanos : 1 }}, `{"dur":"100000000.000000001s"}` },
454- {"negative Duration" , marshaler , & pb2.KnownTypes {Dur : & durpb.Duration {Seconds : - 123 , Nanos : - 456 }}, `{"dur":"-123.000000456s"}` },
451+ {"Duration empty" , marshaler , & durpb.Duration {}, `"0s"` },
452+ {"Duration with secs" , marshaler , & durpb.Duration {Seconds : 3 }, `"3s"` },
453+ {"Duration with -secs" , marshaler , & durpb.Duration {Seconds : - 3 }, `"-3s"` },
454+ {"Duration with nanos" , marshaler , & durpb.Duration {Nanos : 1e6 }, `"0.001s"` },
455+ {"Duration with -nanos" , marshaler , & durpb.Duration {Nanos : - 1e6 }, `"-0.001s"` },
456+ {"Duration with large secs" , marshaler , & durpb.Duration {Seconds : 1e10 , Nanos : 1 }, `"10000000000.000000001s"` },
457+ {"Duration with 6-digit nanos" , marshaler , & durpb.Duration {Nanos : 1e4 }, `"0.000010s"` },
458+ {"Duration with 3-digit nanos" , marshaler , & durpb.Duration {Nanos : 1e6 }, `"0.001s"` },
459+ {"Duration with -secs -nanos" , marshaler , & durpb.Duration {Seconds : - 123 , Nanos : - 450 }, `"-123.000000450s"` },
460+ {"Duration max value" , marshaler , & durpb.Duration {Seconds : 315576000000 , Nanos : 999999999 }, `"315576000000.999999999s"` },
461+ {"Duration min value" , marshaler , & durpb.Duration {Seconds : - 315576000000 , Nanos : - 999999999 }, `"-315576000000.999999999s"` },
455462 {"Struct" , marshaler , & pb2.KnownTypes {St : & stpb.Struct {
456463 Fields : map [string ]* stpb.Value {
457464 "one" : {Kind : & stpb.Value_StringValue {"loneliest number" }},
@@ -524,15 +531,17 @@ func TestMarshalIllegalTime(t *testing.T) {
524531 pb proto.Message
525532 fail bool
526533 }{
527- {& pb2.KnownTypes {Dur : & durpb.Duration {Seconds : 1 , Nanos : 0 }}, false },
528- {& pb2.KnownTypes {Dur : & durpb.Duration {Seconds : - 1 , Nanos : 0 }}, false },
529- {& pb2.KnownTypes {Dur : & durpb.Duration {Seconds : 1 , Nanos : - 1 }}, true },
530- {& pb2.KnownTypes {Dur : & durpb.Duration {Seconds : - 1 , Nanos : 1 }}, true },
531- {& pb2.KnownTypes {Dur : & durpb.Duration {Seconds : 1 , Nanos : 1000000000 }}, true },
532- {& pb2.KnownTypes {Dur : & durpb.Duration {Seconds : - 1 , Nanos : - 1000000000 }}, true },
533- {& pb2.KnownTypes {Ts : & tspb.Timestamp {Seconds : 1 , Nanos : 1 }}, false },
534- {& pb2.KnownTypes {Ts : & tspb.Timestamp {Seconds : 1 , Nanos : - 1 }}, true },
535- {& pb2.KnownTypes {Ts : & tspb.Timestamp {Seconds : 1 , Nanos : 1000000000 }}, true },
534+ {& durpb.Duration {Seconds : 1 , Nanos : 0 }, false },
535+ {& durpb.Duration {Seconds : - 1 , Nanos : 0 }, false },
536+ {& durpb.Duration {Seconds : 1 , Nanos : - 1 }, true },
537+ {& durpb.Duration {Seconds : - 1 , Nanos : 1 }, true },
538+ {& durpb.Duration {Seconds : 315576000001 }, true },
539+ {& durpb.Duration {Seconds : - 315576000001 }, true },
540+ {& durpb.Duration {Seconds : 1 , Nanos : 1000000000 }, true },
541+ {& durpb.Duration {Seconds : - 1 , Nanos : - 1000000000 }, true },
542+ {& tspb.Timestamp {Seconds : 1 , Nanos : 1 }, false },
543+ {& tspb.Timestamp {Seconds : 1 , Nanos : - 1 }, true },
544+ {& tspb.Timestamp {Seconds : 1 , Nanos : 1000000000 }, true },
536545 }
537546 for _ , tt := range tests {
538547 _ , err := marshaler .MarshalToString (tt .pb )
0 commit comments