TestSpec_PublicAPI_FormatDuration validates the documented behavior of FormatDuration as described in the timeutil package README.md specification. Spec section: "### FormatDuration(d time.Duration) string"
(t *testing.T)
| 15 | // as described in the timeutil package README.md specification. |
| 16 | // Spec section: "### FormatDuration(d time.Duration) string" |
| 17 | func TestSpec_PublicAPI_FormatDuration(t *testing.T) { |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | input time.Duration |
| 21 | expected string |
| 22 | }{ |
| 23 | // From spec range table: < 1µs → e.g. "500ns" |
| 24 | {name: "sub-microsecond outputs nanoseconds", input: 500 * time.Nanosecond, expected: "500ns"}, |
| 25 | // From spec range table: 1µs – < 1ms → e.g. "250µs" |
| 26 | {name: "microsecond range outputs µs", input: 250 * time.Microsecond, expected: "250µs"}, |
| 27 | // From spec range table: 1ms – < 1s → e.g. "750ms" |
| 28 | {name: "millisecond range outputs ms", input: 750 * time.Millisecond, expected: "750ms"}, |
| 29 | // From spec range table: 1s – < 1min → e.g. "2.5s" |
| 30 | {name: "second range outputs s with decimal", input: 2500 * time.Millisecond, expected: "2.5s"}, |
| 31 | // From spec range table: 1min – < 1h → e.g. "1.3m" |
| 32 | {name: "minute range outputs m with decimal", input: 90 * time.Second, expected: "1.5m"}, |
| 33 | // From spec range table: ≥ 1h → e.g. "2.0h" |
| 34 | {name: "hour range outputs h with decimal", input: 2 * time.Hour, expected: "2.0h"}, |
| 35 | // From spec code examples |
| 36 | {name: "spec example: 500ms → 500ms", input: 500 * time.Millisecond, expected: "500ms"}, |
| 37 | {name: "spec example: 2500ms → 2.5s", input: 2500 * time.Millisecond, expected: "2.5s"}, |
| 38 | {name: "spec example: 90s → 1.5m", input: 90 * time.Second, expected: "1.5m"}, |
| 39 | } |
| 40 | |
| 41 | for _, tt := range tests { |
| 42 | t.Run(tt.name, func(t *testing.T) { |
| 43 | result := timeutil.FormatDuration(tt.input) |
| 44 | assert.Equal(t, tt.expected, result, |
| 45 | "FormatDuration(%v) should return %q as documented in spec", tt.input, tt.expected) |
| 46 | }) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // TestSpec_PublicAPI_FormatDurationMs validates the documented behavior of FormatDurationMs |
| 51 | // as described in the timeutil package README.md specification. |
nothing calls this directly
no test coverage detected