| 1 | // Copyright 2023 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 driverutil_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 10 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 11 | |
| 12 | "golang.org/x/tools/go/analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/" |
| 13 | "golang.org/x/tools/internal/analysis/driverutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil`/" |
| 14 | ) |
| 15 | |
| 16 | func TestResolveURLsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil_test`/TestResolveURLs().(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#) { |
| 17 | // TestResolveURL test the 12 different combinations for how URLs can be resolved |
| 18 | // when Analyzer.URL are Diagnostic.Category are empty or non-empty, and when |
| 19 | // Diagnostic.URL is empty, absolute or relative. |
| 20 | |
| 21 | aURL := &analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#{URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#URL.: "https://analyzer.example"} |
| 22 | noURL := &analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#{URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#URL.: ""} |
| 23 | tests := []struct { |
| 24 | analyzer *analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer# |
| 25 | diagnostic analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic# |
| 26 | want string |
| 27 | }{ |
| 28 | {noURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: ""}, ""}, |
| 29 | {noURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "#relative"}, "#relative"}, |
| 30 | {noURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "https://absolute.diagnostic"}, "https://absolute.diagnostic"}, |
| 31 | {noURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "category", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: ""}, "#category"}, |
| 32 | {noURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "category", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "#relative"}, "#relative"}, |
| 33 | {noURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "category", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "https://absolute.diagnostic"}, "https://absolute.diagnostic"}, |
| 34 | {aURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: ""}, "https://analyzer.example"}, |
| 35 | {aURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "#relative"}, "https://analyzer.example#relative"}, |
| 36 | {aURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "https://absolute.diagnostic"}, "https://absolute.diagnostic"}, |
| 37 | {aURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "category", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: ""}, "https://analyzer.example#category"}, |
| 38 | {aURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "category", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "#relative"}, "https://analyzer.example#relative"}, |
| 39 | {aURL, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "category", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "https://absolute.diagnostic"}, "https://absolute.diagnostic"}, |
| 40 | } |
| 41 | for _, c := range tests { |
| 42 | got, err := driverutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil`/.ResolveURLscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil`/ResolveURL().(c.analyzer, c.diagnostic) |
| 43 | if err != nil { |
| 44 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Unexpected error from ResolveURL %s", err) |
| 45 | } else if got != c.want { |
| 46 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("ResolveURL(%q,%v)=%q. want %s", c.analyzer.URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#URL., c.diagnostic, got, c.want) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | func TestResolveURLErrorsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil_test`/TestResolveURLErrors().(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#) { |
| 52 | tests := []struct { |
| 53 | analyzer *analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer# |
| 54 | diagnostic analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic# |
| 55 | want string |
| 56 | }{ |
| 57 | {&analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#{URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#URL.: ":not a url"}, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: "#relative"}, "invalid Analyzer.URL"}, |
| 58 | {&analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Analyzerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#{URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#URL.: "https://analyzer.example"}, analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/.Diagnosticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#{Categoryscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#Category.: "", URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL.: ":not a URL"}, "invalid Diagnostic.URL"}, |
| 59 | } |
| 60 | for _, c := range tests { |
| 61 | _, err := driverutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil`/.ResolveURLscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/analysis/driverutil`/ResolveURL().(c.analyzer, c.diagnostic) |
| 62 | if got := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(err); !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(got, c.want) { |
| 63 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("ResolveURL(%q, %q) expected an error starting with %q. got %q", c.analyzer.URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Analyzer#URL., c.diagnostic.URLscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/analysis`/Diagnostic#URL., c.want, got) |
| 64 | } |
| 65 | } |
| 66 | } |