path/filepath: use slices to simplify the test code

This commit is contained in:
apocelipes 2024-03-22 17:39:32 +09:00
parent b5e377cedc
commit b27fda4630
2 changed files with 7 additions and 18 deletions

View File

@ -11,7 +11,7 @@ import (
. "path/filepath"
"reflect"
"runtime"
"sort"
"slices"
"strings"
"testing"
)
@ -107,16 +107,6 @@ func TestMatch(t *testing.T) {
}
}
// contains reports whether vector contains the string s.
func contains(vector []string, s string) bool {
for _, elem := range vector {
if elem == s {
return true
}
}
return false
}
var globTests = []struct {
pattern, result string
}{
@ -139,7 +129,7 @@ func TestGlob(t *testing.T) {
t.Errorf("Glob error for %q: %s", pattern, err)
continue
}
if !contains(matches, result) {
if !slices.Contains(matches, result) {
t.Errorf("Glob(%#q) = %#v want %v", pattern, matches, result)
}
}
@ -214,7 +204,7 @@ func TestGlobSymlink(t *testing.T) {
if err != nil {
t.Errorf("GlobSymlink error for %q: %s", dest, err)
}
if !contains(matches, dest) {
if !slices.Contains(matches, dest) {
t.Errorf("Glob(%#q) = %#v want %v", dest, matches, dest)
}
}
@ -230,7 +220,7 @@ func (test *globTest) buildWant(root string) []string {
for _, m := range test.matches {
want = append(want, root+FromSlash(m))
}
sort.Strings(want)
slices.Sort(want)
return want
}
@ -240,7 +230,7 @@ func (test *globTest) globAbs(root, rootPattern string) error {
if err != nil {
return err
}
sort.Strings(have)
slices.Sort(have)
want := test.buildWant(root + `\`)
if strings.Join(want, "_") == strings.Join(have, "_") {
return nil
@ -254,7 +244,7 @@ func (test *globTest) globRel(root string) error {
if err != nil {
return err
}
sort.Strings(have)
slices.Sort(have)
want := test.buildWant(root)
if strings.Join(want, "_") == strings.Join(have, "_") {
return nil

View File

@ -14,7 +14,6 @@ import (
"reflect"
"runtime"
"slices"
"sort"
"strings"
"syscall"
"testing"
@ -1790,7 +1789,7 @@ func testWalkSymlink(t *testing.T, mklink func(target, link string) error) {
if err != nil {
t.Fatal(err)
}
sort.Strings(visited)
slices.Sort(visited)
want := []string{".", "link"}
if fmt.Sprintf("%q", visited) != fmt.Sprintf("%q", want) {
t.Errorf("unexpected paths visited %q, want %q", visited, want)