| 1 | // Copyright 2025 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package packagepath_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagepath_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 9 | |
| 10 | . "golang.org/x/tools/internal/packagepathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagepath`/" |
| 11 | ) |
| 12 | |
| 13 | func TestCanImportscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagepath_test`/TestCanImport().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 14 | for _, tt := range []struct { |
| 15 | from string |
| 16 | to string |
| 17 | want bool |
| 18 | }{ |
| 19 | {"fmt", "internal", true}, |
| 20 | {"fmt", "internal/foo", true}, |
| 21 | {"fmt", "fmt/internal/foo", true}, |
| 22 | {"fmt", "cmd/internal/archive", false}, |
| 23 | {"a.com/b", "internal", false}, |
| 24 | {"a.com/b", "xinternal", true}, |
| 25 | {"a.com/b", "internal/foo", false}, |
| 26 | {"a.com/b", "xinternal/foo", true}, |
| 27 | {"a.com/b", "a.com/internal", true}, |
| 28 | {"a.com/b", "a.com/b/internal", true}, |
| 29 | {"a.com/b", "a.com/b/internal/foo", true}, |
| 30 | {"a.com/b", "a.com/c/internal", false}, |
| 31 | {"a.com/b", "a.com/c/xinternal", true}, |
| 32 | {"a.com/b", "a.com/c/internal/foo", false}, |
| 33 | {"a.com/b", "a.com/c/xinternal/foo", true}, |
| 34 | } { |
| 35 | got := CanImportscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagepath`/CanImport().(tt.from, tt.to) |
| 36 | if got != tt.want { |
| 37 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("CanImport(%q, %q) = %v, want %v", tt.from, tt.to, got, tt.want) |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestIsStdPackagescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagepath_test`/TestIsStdPackage().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 43 | testCases := []struct { |
| 44 | pkgpath string |
| 45 | isStd bool |
| 46 | }{ |
| 47 | {pkgpath: "os", isStd: true}, |
| 48 | {pkgpath: "net/http", isStd: true}, |
| 49 | {pkgpath: "vendor/golang.org/x/net/dns/dnsmessage", isStd: true}, |
| 50 | {pkgpath: "golang.org/x/net/dns/dnsmessage", isStd: false}, |
| 51 | {pkgpath: "testdata", isStd: false}, |
| 52 | } |
| 53 | |
| 54 | for _, tc := range testCases { |
| 55 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tc.pkgpath, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 56 | got := IsStdPackagescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/packagepath`/IsStdPackage().(tc.pkgpath) |
| 57 | if got != tc.isStd { |
| 58 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("got %t want %t", got, tc.isStd) |
| 59 | } |
| 60 | }) |
| 61 | } |
| 62 | } |