109 lines
1.9 KiB
Go
109 lines
1.9 KiB
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestHumanDuration(t *testing.T) {
|
|
tests := []struct {
|
|
i int
|
|
expected string
|
|
}{
|
|
{-1, ""},
|
|
{1, "1 second"},
|
|
{3, "3 seconds"},
|
|
{60, "1 minute"},
|
|
{120, "2 minutes"},
|
|
{3600, "1 hour"},
|
|
{7200, "2 hours"},
|
|
{86400, "1 day"},
|
|
{172800, "2 days"},
|
|
{604800, "1 week"},
|
|
{1209600, "2 weeks"},
|
|
{2678400, "1 month"},
|
|
{5356800, "2 months"},
|
|
{31536000, "1 year"},
|
|
{63072000, "2 years"},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(fmt.Sprintf("TestHumanDuration#%d", tc.i), func(t *testing.T) {
|
|
got := HumanDuration(tc.i)
|
|
if got != tc.expected {
|
|
t.Errorf("got '%s', want '%s'", got, tc.expected)
|
|
} else {
|
|
t.Logf("got '%s', want '%s'", got, tc.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestToLowerStringsSlice(t *testing.T) {
|
|
input := []string{
|
|
"Text",
|
|
"CSS",
|
|
"Dockerfile",
|
|
"Go",
|
|
"HCL",
|
|
"HTML",
|
|
"Javascript",
|
|
"JSON",
|
|
"Markdown",
|
|
"Perl",
|
|
"Python",
|
|
"Ruby",
|
|
"Rust",
|
|
"Shell",
|
|
"SQL",
|
|
"YAML",
|
|
}
|
|
expected := []string{
|
|
"text",
|
|
"css",
|
|
"dockerfile",
|
|
"go",
|
|
"hcl",
|
|
"html",
|
|
"javascript",
|
|
"json",
|
|
"markdown",
|
|
"perl",
|
|
"python",
|
|
"ruby",
|
|
"rust",
|
|
"shell",
|
|
"sql",
|
|
"yaml",
|
|
}
|
|
|
|
got := ToLowerStringSlice(input)
|
|
if slices.Compare(got, expected) != 0 {
|
|
t.Errorf("got '%s', want '%s'", got, expected)
|
|
} else {
|
|
t.Logf("got '%s', want '%s'", got, expected)
|
|
}
|
|
}
|
|
|
|
func TestInSlice(t *testing.T) {
|
|
tests := []struct {
|
|
elem string
|
|
s []string
|
|
expected bool
|
|
}{
|
|
{"linux", []string{"linux", "darwin"}, true},
|
|
{"windows", []string{"linux", "darwin"}, false},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(fmt.Sprintf("TestInSlice#%s", tc.elem), func(t *testing.T) {
|
|
got := InSlice(tc.s, tc.elem)
|
|
if got != tc.expected {
|
|
t.Errorf("got '%t', want '%t'", got, tc.expected)
|
|
} else {
|
|
t.Logf("got '%t', want '%t'", got, tc.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|