make test function names more consistent

This commit is contained in:
Lilian Jónsdóttir 2024-07-15 21:02:26 -07:00
parent 97e51dd2d9
commit 40ef230a4f

View file

@ -99,7 +99,7 @@ func testmatch(t *testing.T, testers []testholder) {
} }
} }
func blanktime(dir bool, names ...string) []singletest { func nameonly(dir bool, names ...string) []singletest {
out := make([]singletest, 0, len(names)) out := make([]singletest, 0, len(names))
for _, name := range names { for _, name := range names {
out = append(out, singletest{filename: name, modified: time.Time{}, isdir: dir, size: 0}) out = append(out, singletest{filename: name, modified: time.Time{}, isdir: dir, size: 0})
@ -107,7 +107,7 @@ func blanktime(dir bool, names ...string) []singletest {
return out return out
} }
func blankname(dir bool, times ...time.Time) []singletest { func timeonly(dir bool, times ...time.Time) []singletest {
out := make([]singletest, 0, len(times)) out := make([]singletest, 0, len(times))
for _, time := range times { for _, time := range times {
out = append(out, singletest{filename: "blank.txt", modified: time, isdir: dir, size: 0}) out = append(out, singletest{filename: "blank.txt", modified: time, isdir: dir, size: 0})
@ -127,43 +127,43 @@ func TestFilterOn(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
on: "2024-02-14", on: "2024-02-14",
good: blankname(false, time.Date(2024, 2, 14, 12, 0, 0, 0, time.Local)), good: timeonly(false, time.Date(2024, 2, 14, 12, 0, 0, 0, time.Local)),
bad: blankname(false, now, now.Add(time.Hour*72), now.Add(-time.Hour*18)), bad: timeonly(false, now, now.Add(time.Hour*72), now.Add(-time.Hour*18)),
}, },
{ {
on: "yesterday", on: "yesterday",
good: blankname(false, yesterday), good: timeonly(false, yesterday),
bad: blankname(false, now, oneweekago, onemonthago, oneyearago, twoweeksago, twomonthsago, twoyearsago), bad: timeonly(false, now, oneweekago, onemonthago, oneyearago, twoweeksago, twomonthsago, twoyearsago),
}, },
{ {
on: "one week ago", on: "one week ago",
good: blankname(false, oneweekago), good: timeonly(false, oneweekago),
bad: blankname(false, now), bad: timeonly(false, now),
}, },
{ {
on: "one month ago", on: "one month ago",
good: blankname(false, onemonthago), good: timeonly(false, onemonthago),
bad: blankname(false, now), bad: timeonly(false, now),
}, },
{ {
on: "two months ago", on: "two months ago",
good: blankname(false, twomonthsago), good: timeonly(false, twomonthsago),
bad: blankname(false, now), bad: timeonly(false, now),
}, },
{ {
on: "four months ago", on: "four months ago",
good: blankname(false, fourmonthsago), good: timeonly(false, fourmonthsago),
bad: blankname(false, now), bad: timeonly(false, now),
}, },
{ {
on: "one year ago", on: "one year ago",
good: blankname(false, oneyearago), good: timeonly(false, oneyearago),
bad: blankname(false, now), bad: timeonly(false, now),
}, },
{ {
on: "four years ago", on: "four years ago",
good: blankname(false, fouryearsago), good: timeonly(false, fouryearsago),
bad: blankname(false, now), bad: timeonly(false, now),
}, },
}) })
} }
@ -172,43 +172,43 @@ func TestFilterAfter(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
after: "2020-02-14", after: "2020-02-14",
good: blankname(false, time.Date(2024, 3, 14, 12, 0, 0, 0, time.Local), now, yesterday), good: timeonly(false, time.Date(2024, 3, 14, 12, 0, 0, 0, time.Local), now, yesterday),
bad: blankname(false, time.Date(2018, 2, 14, 12, 0, 0, 0, time.Local)), bad: timeonly(false, time.Date(2018, 2, 14, 12, 0, 0, 0, time.Local)),
}, },
{ {
after: "yesterday", after: "yesterday",
good: blankname(false, yesterday, yesterday.AddDate(1, 0, 0), now, now.AddDate(0, 3, 0)), good: timeonly(false, yesterday, yesterday.AddDate(1, 0, 0), now, now.AddDate(0, 3, 0)),
bad: blankname(false, yesterday.AddDate(-1, 0, 0), yesterday.AddDate(0, 0, -1), ereyesterday), bad: timeonly(false, yesterday.AddDate(-1, 0, 0), yesterday.AddDate(0, 0, -1), ereyesterday),
}, },
{ {
after: "one week ago", after: "one week ago",
good: blankname(false, now), good: timeonly(false, now),
bad: blankname(false, oneweekago.AddDate(0, 0, -1)), bad: timeonly(false, oneweekago.AddDate(0, 0, -1)),
}, },
{ {
after: "one month ago", after: "one month ago",
good: blankname(false, now, oneweekago, twoweeksago), good: timeonly(false, now, oneweekago, twoweeksago),
bad: blankname(false, onemonthago, twomonthsago, fourmonthsago, oneyearago), bad: timeonly(false, onemonthago, twomonthsago, fourmonthsago, oneyearago),
}, },
{ {
after: "two months ago", after: "two months ago",
good: blankname(false, now, onemonthago, oneweekago), good: timeonly(false, now, onemonthago, oneweekago),
bad: blankname(false, twomonthsago, oneyearago, fourmonthsago), bad: timeonly(false, twomonthsago, oneyearago, fourmonthsago),
}, },
{ {
after: "four months ago", after: "four months ago",
good: blankname(false, now, oneweekago, onemonthago, twoweeksago, twomonthsago, onemonthago), good: timeonly(false, now, oneweekago, onemonthago, twoweeksago, twomonthsago, onemonthago),
bad: blankname(false, fourmonthsago, oneyearago), bad: timeonly(false, fourmonthsago, oneyearago),
}, },
{ {
after: "one year ago", after: "one year ago",
good: blankname(false, now, onemonthago, twomonthsago, fourmonthsago), good: timeonly(false, now, onemonthago, twomonthsago, fourmonthsago),
bad: blankname(false, oneyearago, fouryearsago, twoyearsago), bad: timeonly(false, oneyearago, fouryearsago, twoyearsago),
}, },
{ {
after: "four years ago", after: "four years ago",
good: blankname(false, now, twoyearsago, onemonthago, fourmonthsago), good: timeonly(false, now, twoyearsago, onemonthago, fourmonthsago),
bad: blankname(false, fouryearsago, fouryearsago.AddDate(-1, 0, 0)), bad: timeonly(false, fouryearsago, fouryearsago.AddDate(-1, 0, 0)),
}, },
}) })
} }
@ -217,43 +217,43 @@ func TestFilterBefore(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
before: "2024-02-14", before: "2024-02-14",
good: blankname(false, time.Date(2020, 2, 14, 12, 0, 0, 0, time.Local), time.Date(1989, 8, 13, 18, 53, 0, 0, time.Local)), good: timeonly(false, time.Date(2020, 2, 14, 12, 0, 0, 0, time.Local), time.Date(1989, 8, 13, 18, 53, 0, 0, time.Local)),
bad: blankname(false, now, now.AddDate(0, 0, 10), now.AddDate(0, -2, 0)), bad: timeonly(false, now, now.AddDate(0, 0, 10), now.AddDate(0, -2, 0)),
}, },
{ {
before: "yesterday", before: "yesterday",
good: blankname(false, onemonthago, oneweekago, oneyearago), good: timeonly(false, onemonthago, oneweekago, oneyearago),
bad: blankname(false, now, now.AddDate(0, 0, 1)), bad: timeonly(false, now, now.AddDate(0, 0, 1)),
}, },
{ {
before: "one week ago", before: "one week ago",
good: blankname(false, onemonthago, oneyearago, twoweeksago), good: timeonly(false, onemonthago, oneyearago, twoweeksago),
bad: blankname(false, yesterday, now), bad: timeonly(false, yesterday, now),
}, },
{ {
before: "one month ago", before: "one month ago",
good: blankname(false, oneyearago, twomonthsago), good: timeonly(false, oneyearago, twomonthsago),
bad: blankname(false, oneweekago, yesterday, now), bad: timeonly(false, oneweekago, yesterday, now),
}, },
{ {
before: "two months ago", before: "two months ago",
good: blankname(false, fourmonthsago, oneyearago), good: timeonly(false, fourmonthsago, oneyearago),
bad: blankname(false, onemonthago, oneweekago, yesterday, now), bad: timeonly(false, onemonthago, oneweekago, yesterday, now),
}, },
{ {
before: "four months ago", before: "four months ago",
good: blankname(false, oneyearago, twoyearsago, fouryearsago), good: timeonly(false, oneyearago, twoyearsago, fouryearsago),
bad: blankname(false, twomonthsago, onemonthago, oneweekago, yesterday, now), bad: timeonly(false, twomonthsago, onemonthago, oneweekago, yesterday, now),
}, },
{ {
before: "one year ago", before: "one year ago",
good: blankname(false, twoyearsago, fouryearsago), good: timeonly(false, twoyearsago, fouryearsago),
bad: blankname(false, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now), bad: timeonly(false, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now),
}, },
{ {
before: "four years ago", before: "four years ago",
good: blankname(false, fouryearsago.AddDate(-1, 0, 0), fouryearsago.AddDate(-4, 0, 0)), good: timeonly(false, fouryearsago.AddDate(-1, 0, 0), fouryearsago.AddDate(-4, 0, 0)),
bad: blankname(false, oneyearago, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now), bad: timeonly(false, oneyearago, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now),
}, },
}) })
} }
@ -262,13 +262,13 @@ func TestFilterMatch(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
pattern: "[Tt]est", pattern: "[Tt]est",
good: blanktime(false, "test", "Test"), good: nameonly(false, "test", "Test"),
bad: blanktime(false, "TEST", "tEst", "tEST", "TEst"), bad: nameonly(false, "TEST", "tEst", "tEST", "TEst"),
}, },
{ {
pattern: "^h.*o$", pattern: "^h.*o$",
good: blanktime(false, "hello", "hippo", "how about some pasta with alfredo"), good: nameonly(false, "hello", "hippo", "how about some pasta with alfredo"),
bad: blanktime(false, "hi", "test", "hellO", "Hello", "oh hello there"), bad: nameonly(false, "hi", "test", "hellO", "Hello", "oh hello there"),
}, },
}) })
} }
@ -277,23 +277,23 @@ func TestFilterGlob(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
glob: "*.txt", glob: "*.txt",
good: blanktime(false, "test.txt", "alsotest.txt"), good: nameonly(false, "test.txt", "alsotest.txt"),
bad: blanktime(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text"), bad: nameonly(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text"),
}, },
{ {
glob: "*.tar.*", glob: "*.tar.*",
good: blanktime(false, "test.tar.gz", "test.tar.xz", "test.tar.zst", "test.tar.bz2"), good: nameonly(false, "test.tar.gz", "test.tar.xz", "test.tar.zst", "test.tar.bz2"),
bad: blanktime(false, "test.tar", "test.txt", "test.targz", "test.tgz"), bad: nameonly(false, "test.tar", "test.txt", "test.targz", "test.tgz"),
}, },
{ {
glob: "pot*o", glob: "pot*o",
good: blanktime(false, "potato", "potdonkeyo", "potesto"), good: nameonly(false, "potato", "potdonkeyo", "potesto"),
bad: blanktime(false, "salad", "test", "alsotest"), bad: nameonly(false, "salad", "test", "alsotest"),
}, },
{ {
glob: "t?st", glob: "t?st",
good: blanktime(false, "test", "tast", "tfst", "tnst"), good: nameonly(false, "test", "tast", "tfst", "tnst"),
bad: blanktime(false, "best", "fast", "most", "past"), bad: nameonly(false, "best", "fast", "most", "past"),
}, },
}) })
} }
@ -302,13 +302,13 @@ func TestFilterUnMatch(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
unpattern: "^ss_.*\\.zip", unpattern: "^ss_.*\\.zip",
good: blanktime(false, "hello.zip", "ss_potato.png", "sss.zip"), good: nameonly(false, "hello.zip", "ss_potato.png", "sss.zip"),
bad: blanktime(false, "ss_ost_flac.zip", "ss_guide.zip", "ss_controls.zip"), bad: nameonly(false, "ss_ost_flac.zip", "ss_guide.zip", "ss_controls.zip"),
}, },
{ {
unpattern: "^h.*o$", unpattern: "^h.*o$",
good: blanktime(false, "hi", "test", "hellO", "Hello", "oh hello there"), good: nameonly(false, "hi", "test", "hellO", "Hello", "oh hello there"),
bad: blanktime(false, "hello", "hippo", "how about some pasta with alfredo"), bad: nameonly(false, "hello", "hippo", "how about some pasta with alfredo"),
}, },
}) })
} }
@ -317,23 +317,23 @@ func TestFilterUnGlob(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
unglob: "*.txt", unglob: "*.txt",
good: blanktime(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text"), good: nameonly(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text"),
bad: blanktime(false, "test.txt", "alsotest.txt"), bad: nameonly(false, "test.txt", "alsotest.txt"),
}, },
{ {
unglob: "*.tar.*", unglob: "*.tar.*",
good: blanktime(false, "test.tar", "test.txt", "test.targz", "test.tgz"), good: nameonly(false, "test.tar", "test.txt", "test.targz", "test.tgz"),
bad: blanktime(false, "test.tar.gz", "test.tar.xz", "test.tar.zst", "test.tar.bz2"), bad: nameonly(false, "test.tar.gz", "test.tar.xz", "test.tar.zst", "test.tar.bz2"),
}, },
{ {
unglob: "pot*o", unglob: "pot*o",
good: blanktime(false, "salad", "test", "alsotest"), good: nameonly(false, "salad", "test", "alsotest"),
bad: blanktime(false, "potato", "potdonkeyo", "potesto"), bad: nameonly(false, "potato", "potdonkeyo", "potesto"),
}, },
{ {
unglob: "t?st", unglob: "t?st",
good: blanktime(false, "best", "fast", "most", "past"), good: nameonly(false, "best", "fast", "most", "past"),
bad: blanktime(false, "test", "tast", "tfst", "tnst"), bad: nameonly(false, "test", "tast", "tfst", "tnst"),
}, },
}) })
} }
@ -342,18 +342,18 @@ func TestFilterFilenames(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
filenames: []string{"test.txt", "alsotest.txt"}, filenames: []string{"test.txt", "alsotest.txt"},
good: blanktime(false, "test.txt", "alsotest.txt"), good: nameonly(false, "test.txt", "alsotest.txt"),
bad: blanktime(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text"), bad: nameonly(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text"),
}, },
{ {
filenames: []string{"test.md", "test.txt"}, filenames: []string{"test.md", "test.txt"},
good: blanktime(false, "test.txt", "test.md"), good: nameonly(false, "test.txt", "test.md"),
bad: blanktime(false, "alsotest.txt", "test.go", "test.tar.gz", "testxt", "test.text"), bad: nameonly(false, "alsotest.txt", "test.go", "test.tar.gz", "testxt", "test.text"),
}, },
{ {
filenames: []string{"hello.world"}, filenames: []string{"hello.world"},
good: blanktime(false, "hello.world"), good: nameonly(false, "hello.world"),
bad: blanktime(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text", "helloworld", "Hello.world"), bad: nameonly(false, "test.md", "test.go", "test.tar.gz", "testxt", "test.text", "helloworld", "Hello.world"),
}, },
}) })
} }
@ -362,8 +362,8 @@ func TestFilterFilesOnly(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
filesonly: true, filesonly: true,
good: blanktime(false, "test", "hellowold.txt", "test.md", "test.jpg"), good: nameonly(false, "test", "hellowold.txt", "test.md", "test.jpg"),
bad: blanktime(true, "test", "alsotest", "helloworld"), bad: nameonly(true, "test", "alsotest", "helloworld"),
}, },
}) })
} }
@ -372,13 +372,13 @@ func TestFilterDirsOnly(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
dirsonly: true, dirsonly: true,
good: blanktime(true, "test", "alsotest", "helloworld"), good: nameonly(true, "test", "alsotest", "helloworld"),
bad: blanktime(false, "test", "hellowold.txt", "test.md", "test.jpg"), bad: nameonly(false, "test", "hellowold.txt", "test.md", "test.jpg"),
}, },
{ {
dirsonly: true, dirsonly: true,
good: blankname(true, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now), good: timeonly(true, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now),
bad: blankname(false, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now), bad: timeonly(false, fourmonthsago, twomonthsago, onemonthago, oneweekago, yesterday, now),
}, },
}) })
} }
@ -387,12 +387,12 @@ func TestFilterShowHidden(t *testing.T) {
testmatch(t, []testholder{ testmatch(t, []testholder{
{ {
ignorehidden: true, ignorehidden: true,
good: append(blanktime(true, "test", "alsotest", "helloworld"), blanktime(false, "test", "alsotest", "helloworld")...), good: append(nameonly(true, "test", "alsotest", "helloworld"), nameonly(false, "test", "alsotest", "helloworld")...),
bad: append(blanktime(true, ".test", ".alsotest", ".helloworld"), blanktime(false, ".test", ".alsotest", ".helloworld")...), bad: append(nameonly(true, ".test", ".alsotest", ".helloworld"), nameonly(false, ".test", ".alsotest", ".helloworld")...),
}, },
{ {
ignorehidden: false, ignorehidden: false,
good: append(blanktime(true, "test", "alsotest", ".helloworld"), blanktime(false, "test", "alsotest", ".helloworld")...), good: append(nameonly(true, "test", "alsotest", ".helloworld"), nameonly(false, "test", "alsotest", ".helloworld")...),
}, },
}) })
} }
@ -455,8 +455,8 @@ func TestFilterMultipleParameters(t *testing.T) {
on: "today", on: "today",
after: "two weeks ago", after: "two weeks ago",
before: "one week ago", before: "one week ago",
good: blankname(false, now, twoam, sevenam, threepm, tenpm), good: timeonly(false, now, twoam, sevenam, threepm, tenpm),
bad: blankname(false, yesterday, oneweekago, onemonthago, oneyearago), bad: timeonly(false, yesterday, oneweekago, onemonthago, oneyearago),
}, },
{ {
unpattern: ".*\\.(jpg|png)", unpattern: ".*\\.(jpg|png)",
@ -474,7 +474,7 @@ func TestFilterMultipleParameters(t *testing.T) {
{ {
filesonly: true, filesonly: true,
unglob: "*.txt", unglob: "*.txt",
good: blanktime(false, "test.md", "test.jpg", "test.png"), good: nameonly(false, "test.md", "test.jpg", "test.png"),
bad: []singletest{ bad: []singletest{
{ {
filename: "test", filename: "test",
@ -493,7 +493,7 @@ func TestFilterMultipleParameters(t *testing.T) {
{ {
dirsonly: true, dirsonly: true,
pattern: "w(or|ea)ld", pattern: "w(or|ea)ld",
good: blanktime(true, "hello world", "high weald"), good: nameonly(true, "hello world", "high weald"),
bad: []singletest{ bad: []singletest{
{ {
filename: "hello_world.txt", filename: "hello_world.txt",