MCPcopy Create free account
hub / github.com/cli/cli / TestFuzzyIn

Function TestFuzzyIn

internal/text/text_test.go:60–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func TestFuzzyIn(t *testing.T) {
61 const form = "2006-Jan-02 15:04:05"
62 now, _ := time.Parse(form, "2020-Nov-22 14:00:00")
63 cases := map[string]string{
64 "2020-Nov-22 14:00:00": "in less than a minute",
65 "2020-Nov-22 14:00:30": "in less than a minute",
66 "2020-Nov-22 14:01:00": "in about 1 minute",
67 "2020-Nov-22 14:30:00": "in about 30 minutes",
68 "2020-Nov-22 15:00:00": "in about 1 hour",
69 "2020-Nov-23 02:00:00": "in about 12 hours",
70 "2020-Nov-23 14:00:00": "in about 1 day",
71 "2020-Dec-07 14:00:00": "in about 15 days",
72 "2020-Dec-22 14:00:00": "in about 1 month",
73 "2021-Nov-22 14:00:00": "in about 1 year",
74 "2025-Nov-22 14:00:00": "in about 5 years",
75 // Durations just under a unit boundary round to the nominal value instead of reading one unit short.
76 "2020-Nov-22 15:59:59": "in about 2 hours",
77 "2021-May-21 13:59:59": "in about 6 months",
78 // Durations that round up to the next unit's threshold are reported in the larger unit.
79 "2020-Nov-22 14:59:50": "in about 1 hour",
80 "2020-Nov-23 13:50:00": "in about 1 day",
81 "2020-Dec-22 04:00:00": "in about 1 month",
82 "2021-Nov-07 14:00:00": "in about 1 year",
83 }
84 for target, expected := range cases {
85 d, err := time.Parse(form, target)
86 require.NoError(t, err)
87 assert.Equal(t, expected, FuzzyIn(now, d))
88 }
89}
90
91func TestFormatSlice(t *testing.T) {
92 tests := []struct {

Callers

nothing calls this directly

Calls 2

FuzzyInFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected