| 1 |
// Copyright (c) 2017, Daniel Martà <[email protected]> |
| 2 |
// See LICENSE for licensing information |
| 3 |
|
| 4 |
package interp |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
"time" |
| 9 |
) |
| 10 |
|
| 11 |
func TestElapsedString(t *testing.T) { |
| 12 |
t.Parallel() |
| 13 |
|
| 14 |
tests := []struct { |
| 15 |
in time.Duration |
| 16 |
posix bool |
| 17 |
want string |
| 18 |
}{ |
| 19 |
{time.Nanosecond, false, "0m0.000s"}, |
| 20 |
{time.Millisecond, false, "0m0.001s"}, |
| 21 |
{time.Millisecond, true, "0.00"}, |
| 22 |
{2500 * time.Millisecond, false, "0m2.500s"}, |
| 23 |
{2500 * time.Millisecond, true, "2.50"}, |
| 24 |
{ |
| 25 |
10*time.Minute + 10*time.Second, |
| 26 |
false, |
| 27 |
"10m10.000s", |
| 28 |
}, |
| 29 |
{ |
| 30 |
10*time.Minute + 10*time.Second, |
| 31 |
true, |
| 32 |
"610.00", |
| 33 |
}, |
| 34 |
{31 * time.Second, false, "0m31.000s"}, |
| 35 |
{102 * time.Second, false, "1m42.000s"}, |
| 36 |
} |
| 37 |
for _, tc := range tests { |
| 38 |
t.Run(tc.in.String(), func(t *testing.T) { |
| 39 |
got := elapsedString(tc.in, tc.posix) |
| 40 |
if got != tc.want { |
| 41 |
t.Fatalf("wanted %q, got %q", tc.want, got) |
| 42 |
} |
| 43 |
}) |
| 44 |
} |
| 45 |
} |