-
Notifications
You must be signed in to change notification settings - Fork 1
/
string_test.go
65 lines (60 loc) · 1.27 KB
/
string_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-FileCopyrightText: 2023 Weston Schmidt <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause
package approx_test
import (
"testing"
"time"
"github.com/goschtalt/approx"
)
func TestString(t *testing.T) {
tests := []struct {
alt string
d time.Duration
format string
expect string
}{
{
d: approx.Year,
expect: "1y0w0d0h0m0s",
format: "ywd",
}, {
d: 52*approx.Week + approx.Day,
expect: "1y0w0d0h0m0s",
format: "ywd",
alt: "weeks+days",
}, {
d: 4 * approx.Year,
expect: "4y0w0d0h0m0s",
format: "ywd",
}, {
d: 4*approx.Year + 3*approx.Week + 2*approx.Day + 1*time.Hour,
expect: "4y3w2d1h0m0s",
format: "ywd",
}, {
d: 3 * approx.Week,
expect: "3w0d0h0m0s",
format: "ywd",
}, {
d: 3*approx.Week + time.Second,
expect: "3w0d0h0m1s",
format: "ywd",
}, {
d: -1 * (3*approx.Week + time.Second),
expect: "-3w0d0h0m1s",
format: "ywd",
}, {
d: 60 * time.Minute,
expect: "1h0m0s",
format: "ywd",
},
}
for _, tc := range tests {
t.Run(tc.expect+tc.alt, func(t *testing.T) {
got := approx.String(tc.d, tc.format)
if tc.expect != got {
t.Logf("expected: %q got: %q\n", tc.expect, got)
t.Fail()
}
})
}
}