]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: use slices to simplify the test code
authorapocelipes <seve3r@outlook.com>
Fri, 22 Mar 2024 09:04:08 +0000 (09:04 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 22 Mar 2024 16:38:19 +0000 (16:38 +0000)
Change-Id: I020ca2ed8a6af60977f2c492cd742f824906d4ec
GitHub-Last-Rev: b27fda463058e86eafbe5bd10e5c99e10dd609a8
GitHub-Pull-Request: golang/go#66462
Reviewed-on: https://go-review.googlesource.com/c/go/+/573715
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/path/filepath/match_test.go
src/path/filepath/path_test.go

index d6282596fedbb93aeabc93fdc8029d43266098ae..c6b1c505205b36b8b60a57d0cff3a8e8eeb36ee7 100644 (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
index 8a66538f6ae63d415491da42b74f4466e1a7d999..b24f39c5aa4df93253ef4d68c9a9c2e77ad5c52e 100644 (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)