]> Cypherpunks repositories - gostls13.git/commitdiff
time: update TestSub to avoid future regressions
authorJoe Tsai <joetsai@digital-static.net>
Fri, 16 Aug 2019 17:36:01 +0000 (10:36 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Fri, 16 Aug 2019 19:54:57 +0000 (19:54 +0000)
CL 131196 optimized Time.Sub, but was reverted because
it incorrectly computed the nanoseconds in some edge cases.
This CL adds a test case to enforce the correct behavior
so that a future optimization does not break this again.

Updates #17858
Updates #33677

Change-Id: I596d8302ca6bf721cf7ca11cc6f939639fcbdd43
Reviewed-on: https://go-review.googlesource.com/c/go/+/190524
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/time/time_test.go

index 0ac3c3a27fae338c61476ee7cd7c043efc039b70..95998c362f09f97ef0c34e0c3808cebedefb53a9 100644 (file)
@@ -690,7 +690,7 @@ var gobTests = []Time{
        Date(0, 1, 2, 3, 4, 5, 6, UTC),
        Date(7, 8, 9, 10, 11, 12, 13, FixedZone("", 0)),
        Unix(81985467080890095, 0x76543210), // Time.sec: 0x0123456789ABCDEF
-       {}, // nil location
+       {},                                  // nil location
        Date(1, 2, 3, 4, 5, 6, 7, FixedZone("", 32767*60)),
        Date(1, 2, 3, 4, 5, 6, 7, FixedZone("", -32768*60)),
 }
@@ -995,6 +995,7 @@ var subTests = []struct {
        {Date(2300, 1, 1, 0, 0, 0, 0, UTC), Date(2000, 1, 1, 0, 0, 0, 0, UTC), Duration(maxDuration)},
        {Date(2000, 1, 1, 0, 0, 0, 0, UTC), Date(2290, 1, 1, 0, 0, 0, 0, UTC), -290*365*24*Hour - 71*24*Hour},
        {Date(2000, 1, 1, 0, 0, 0, 0, UTC), Date(2300, 1, 1, 0, 0, 0, 0, UTC), Duration(minDuration)},
+       {Date(2311, 11, 26, 02, 16, 47, 63535996, UTC), Date(2019, 8, 16, 2, 29, 30, 268436582, UTC), 9223372036795099414},
        {MinMonoTime, MaxMonoTime, minDuration},
        {MaxMonoTime, MinMonoTime, maxDuration},
 }