diff options
Diffstat (limited to 'libgo/go/time')
-rw-r--r-- | libgo/go/time/tick_test.go | 18 | ||||
-rw-r--r-- | libgo/go/time/time_test.go | 54 | ||||
-rw-r--r-- | libgo/go/time/zoneinfo_windows.go | 2 |
3 files changed, 73 insertions, 1 deletions
diff --git a/libgo/go/time/tick_test.go b/libgo/go/time/tick_test.go index d8a086ceb25..32f4740ad93 100644 --- a/libgo/go/time/tick_test.go +++ b/libgo/go/time/tick_test.go @@ -48,6 +48,24 @@ func TestTeardown(t *testing.T) { } } +// Test the Tick convenience wrapper. +func TestTick(t *testing.T) { + // Test that giving a negative duration returns nil. + if got := Tick(-1); got != nil { + t.Errorf("Tick(-1) = %v; want nil", got) + } +} + +// Test that NewTicker panics when given a duration less than zero. +func TestNewTickerLtZeroDuration(t *testing.T) { + defer func() { + if err := recover(); err == nil { + t.Errorf("NewTicker(-1) should have panicked") + } + }() + NewTicker(-1) +} + func BenchmarkTicker(b *testing.B) { ticker := NewTicker(1) b.ResetTimer() diff --git a/libgo/go/time/time_test.go b/libgo/go/time/time_test.go index 53ae97ea0af..77429b836b2 100644 --- a/libgo/go/time/time_test.go +++ b/libgo/go/time/time_test.go @@ -1463,6 +1463,60 @@ func TestSub(t *testing.T) { } } +var nsDurationTests = []struct { + d Duration + want int64 +}{ + {Duration(-1000), -1000}, + {Duration(-1), -1}, + {Duration(1), 1}, + {Duration(1000), 1000}, +} + +func TestDurationNanoseconds(t *testing.T) { + for _, tt := range nsDurationTests { + if got := tt.d.Nanoseconds(); got != tt.want { + t.Errorf("d.Nanoseconds() = %d; want: %d", got, tt.want) + } + } +} + +var minDurationTests = []struct { + d Duration + want float64 +}{ + {Duration(-60000000000), -1}, + {Duration(-1), -1 / 60e9}, + {Duration(1), 1 / 60e9}, + {Duration(60000000000), 1}, +} + +func TestDurationMinutes(t *testing.T) { + for _, tt := range minDurationTests { + if got := tt.d.Minutes(); got != tt.want { + t.Errorf("d.Minutes() = %d; want: %d", got, tt.want) + } + } +} + +var hourDurationTests = []struct { + d Duration + want float64 +}{ + {Duration(-3600000000000), -1}, + {Duration(-1), -1 / 3600e9}, + {Duration(1), 1 / 3600e9}, + {Duration(3600000000000), 1}, +} + +func TestDurationHours(t *testing.T) { + for _, tt := range hourDurationTests { + if got := tt.d.Hours(); got != tt.want { + t.Errorf("d.Hours() = %d; want: %d", got, tt.want) + } + } +} + func BenchmarkNow(b *testing.B) { for i := 0; i < b.N; i++ { t = Now() diff --git a/libgo/go/time/zoneinfo_windows.go b/libgo/go/time/zoneinfo_windows.go index be4e5c13ff0..7e4d146d89e 100644 --- a/libgo/go/time/zoneinfo_windows.go +++ b/libgo/go/time/zoneinfo_windows.go @@ -54,7 +54,7 @@ func matchZoneKey(zones syscall.Handle, kname string, stdname, dstname string) ( if err != nil { return false, err } - if s != dstname { + if s != dstname && dstname != stdname { return false, nil } return true, nil |