internal/stdlib: delete unused package
Change-Id: Ia71c0a1ed799adf4fb5afd93952d9e144361aaa0
Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/465217
Run-TryBot: Julie Qiu <julieqiu@google.com>
Auto-Submit: Julie Qiu <julieqiu@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/internal/stdlib/gorepo.go b/internal/stdlib/gorepo.go
deleted file mode 100644
index 7709384..0000000
--- a/internal/stdlib/gorepo.go
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright 2022 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package stdlib
-
-import (
- "fmt"
- "path/filepath"
-
- "github.com/go-git/go-billy/v5/osfs"
- "github.com/go-git/go-git/v5"
- "github.com/go-git/go-git/v5/config"
- "github.com/go-git/go-git/v5/plumbing"
- "github.com/go-git/go-git/v5/plumbing/object"
- "github.com/go-git/go-git/v5/storage/memory"
- "golang.org/x/pkgsite-metrics/internal/derrors"
- "golang.org/x/pkgsite-metrics/internal/testing/testhelper"
- "golang.org/x/pkgsite-metrics/internal/version"
-)
-
-// A goRepo represents a git repo holding the Go standard library.
-type goRepo interface {
- // Return the repo at the given version.
- repoAtVersion(version string) (*git.Repository, plumbing.ReferenceName, error)
-
- // Return all the refs of the repo.
- refs() ([]*plumbing.Reference, error)
-}
-
-type remoteGoRepo struct{}
-
-// repoAtVersion returns a repo object for the Go repo at version by cloning the
-// Go repo.
-func (remoteGoRepo) repoAtVersion(v string) (_ *git.Repository, ref plumbing.ReferenceName, err error) {
- defer derrors.Wrap(&err, "remoteGoRepo.repoAtVersion(%q)", v)
-
- ref, err = refNameForVersion(v)
- if err != nil {
- return nil, "", err
- }
- repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
- URL: GoRepoURL,
- ReferenceName: ref,
- SingleBranch: true,
- Depth: 1,
- Tags: git.NoTags,
- })
- if err != nil {
- return nil, "", err
- }
- return repo, ref, nil
-}
-
-func (remoteGoRepo) refs() (_ []*plumbing.Reference, err error) {
- defer derrors.Wrap(&err, "remoteGoRepo.refs")
-
- re := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{
- URLs: []string{GoRepoURL},
- })
- return re.List(&git.ListOptions{})
-}
-
-type localGoRepo struct {
- path string
- repo *git.Repository
-}
-
-func newLocalGoRepo(path string) (*localGoRepo, error) {
- repo, err := git.PlainOpen(path)
- if err != nil {
- return nil, err
- }
- return &localGoRepo{
- path: path,
- repo: repo,
- }, nil
-}
-
-func (g *localGoRepo) repoAtVersion(v string) (_ *git.Repository, ref plumbing.ReferenceName, err error) {
- defer derrors.Wrap(&err, "localGoRepo(%s).repoAtVersion(%q)", g.path, v)
- ref, err = refNameForVersion(v)
- if err != nil {
- return nil, "", err
- }
- return g.repo, ref, nil
-}
-
-func (g *localGoRepo) refs() (rs []*plumbing.Reference, err error) {
- defer derrors.Wrap(&err, "localGoRepo(%s).refs", g.path)
-
- iter, err := g.repo.References()
- if err != nil {
- return nil, err
- }
- defer iter.Close()
- err = iter.ForEach(func(r *plumbing.Reference) error {
- rs = append(rs, r)
- return nil
- })
- if err != nil {
- return nil, err
- }
- return rs, nil
-}
-
-type testGoRepo struct {
-}
-
-// repoAtVersion gets a Go repo for testing.
-func (t *testGoRepo) repoAtVersion(v string) (_ *git.Repository, ref plumbing.ReferenceName, err error) {
- defer derrors.Wrap(&err, "testGoRepo.repoAtVersion(%q)", v)
- if v == TestMasterVersion {
- v = version.Master
- }
- if v == TestDevFuzzVersion {
- v = DevFuzz
- }
- fs := osfs.New(filepath.Join(testhelper.TestDataPath("testdata"), v))
- repo, err := git.Init(memory.NewStorage(), fs)
- if err != nil {
- return nil, "", fmt.Errorf("git.Init: %v", err)
- }
- wt, err := repo.Worktree()
- if err != nil {
- return nil, "", fmt.Errorf("repo.Worktree: %v", err)
- }
- // Add all files in the directory.
- if _, err := wt.Add(""); err != nil {
- return nil, "", fmt.Errorf("wt.Add(): %v", err)
- }
- _, err = wt.Commit("", &git.CommitOptions{All: true, Author: &object.Signature{
- Name: "Joe Random",
- Email: "joe@example.com",
- When: TestCommitTime,
- }})
- if err != nil {
- return nil, "", fmt.Errorf("wt.Commit: %v", err)
- }
- return repo, plumbing.HEAD, nil
-}
-
-// References used for Versions during testing.
-var testRefs = []plumbing.ReferenceName{
- // stdlib versions
- "refs/tags/go1.2.1",
- "refs/tags/go1.3.2",
- "refs/tags/go1.4.2",
- "refs/tags/go1.4.3",
- "refs/tags/go1.6",
- "refs/tags/go1.6.3",
- "refs/tags/go1.6beta1",
- "refs/tags/go1.8",
- "refs/tags/go1.8rc2",
- "refs/tags/go1.9rc1",
- "refs/tags/go1.11",
- "refs/tags/go1.12",
- "refs/tags/go1.12.1",
- "refs/tags/go1.12.5",
- "refs/tags/go1.12.9",
- "refs/tags/go1.13",
- "refs/tags/go1.13beta1",
- "refs/tags/go1.14.6",
- "refs/heads/dev.fuzz",
- "refs/heads/master",
- // other tags
- "refs/changes/56/93156/13",
- "refs/tags/release.r59",
- "refs/tags/weekly.2011-04-13",
-}
-
-func (t *testGoRepo) refs() ([]*plumbing.Reference, error) {
- var rs []*plumbing.Reference
- for _, r := range testRefs {
- // Only the name is ever used, so the referent can be empty.
- rs = append(rs, plumbing.NewSymbolicReference(r, ""))
- }
- return rs, nil
-}
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go
deleted file mode 100644
index 82b4310..0000000
--- a/internal/stdlib/stdlib.go
+++ /dev/null
@@ -1,556 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package stdlib supports special handling of the Go standard library.
-// Regardless of the how the standard library has been split into modules for
-// development and testing, the discovery site treats it as a single module
-// named "std".
-package stdlib
-
-import (
- "archive/zip"
- "bytes"
- "fmt"
- "io"
- "io/fs"
- "os"
- "path"
- "regexp"
- "strings"
- "sync"
- "time"
-
- "golang.org/x/mod/semver"
- "golang.org/x/pkgsite-metrics/internal/derrors"
- "golang.org/x/pkgsite-metrics/internal/version"
-
- "github.com/go-git/go-git/v5"
- "github.com/go-git/go-git/v5/plumbing"
- "github.com/go-git/go-git/v5/plumbing/filemode"
- "github.com/go-git/go-git/v5/plumbing/object"
-)
-
-const (
- // ModulePath is the name of the module for the standard library.
- ModulePath = "std"
-
- // DevFuzz is the branch name for fuzzing in beta.
- DevFuzz = "dev.fuzz"
-
- // DevBoringCrypto is the branch name for dev.boringcrypto.
- DevBoringCrypto = "dev.boringcrypto"
-)
-
-var (
- // Regexp for matching go tags. The groups are:
- // 1 the major.minor version
- // 2 the patch version, or empty if none
- // 3 the entire prerelease, if present
- // 4 the prerelease type ("beta" or "rc")
- // 5 the prerelease number
- tagRegexp = regexp.MustCompile(`^go(\d+\.\d+)(\.\d+|)((beta|rc)(\d+))?$`)
-)
-
-// SupportedBranches are the branches of the stdlib repo supported by pkgsite.
-var SupportedBranches = map[string]bool{
- version.Master: true,
- DevBoringCrypto: true,
- DevFuzz: true,
-}
-
-// VersionForTag returns the semantic version for the Go tag, or "" if
-// tag doesn't correspond to a Go release or beta tag. In special cases,
-// when the tag specified is either `latest` or `master` it will return the tag.
-// Examples:
-//
-// "go1" => "v1.0.0"
-// "go1.2" => "v1.2.0"
-// "go1.13beta1" => "v1.13.0-beta.1"
-// "go1.9rc2" => "v1.9.0-rc.2"
-// "latest" => "latest"
-// "master" => "master"
-func VersionForTag(tag string) string {
- // Special cases for go1.
- if tag == "go1" {
- return "v1.0.0"
- }
- if tag == "go1.0" {
- return ""
- }
- // Special case for latest and master.
- if tag == version.Latest || SupportedBranches[tag] {
- return tag
- }
- m := tagRegexp.FindStringSubmatch(tag)
- if m == nil {
- return ""
- }
- version := "v" + m[1]
- if m[2] != "" {
- version += m[2]
- } else {
- version += ".0"
- }
- if m[3] != "" {
- version += "-" + m[4] + "." + m[5]
- }
- return version
-}
-
-// TagForVersion returns the Go standard library repository tag corresponding
-// to semver. The Go tags differ from standard semantic versions in a few ways,
-// such as beginning with "go" instead of "v".
-func TagForVersion(v string) (_ string, err error) {
- defer derrors.Wrap(&err, "TagForVersion(%q)", v)
-
- // Special case: master => master or dev.fuzz => dev.fuzz
- if SupportedBranches[v] {
- return v, nil
- }
- if strings.HasPrefix(v, "v0.0.0") {
- return version.Master, nil
- }
- // Special case: v1.0.0 => go1.
- if v == "v1.0.0" {
- return "go1", nil
- }
- if !semver.IsValid(v) {
- return "", fmt.Errorf("%w: requested version is not a valid semantic version: %q ", derrors.InvalidArgument, v)
- }
- goVersion := semver.Canonical(v)
- prerelease := semver.Prerelease(goVersion)
- versionWithoutPrerelease := strings.TrimSuffix(goVersion, prerelease)
- patch := strings.TrimPrefix(versionWithoutPrerelease, semver.MajorMinor(goVersion)+".")
- if patch == "0" {
- versionWithoutPrerelease = strings.TrimSuffix(versionWithoutPrerelease, ".0")
- }
- goVersion = fmt.Sprintf("go%s", strings.TrimPrefix(versionWithoutPrerelease, "v"))
- if prerelease != "" {
- // Go prereleases look like "beta1" instead of "beta.1".
- // "beta1" is bad for sorting (since beta10 comes before beta9), so
- // require the dot form.
- i := finalDigitsIndex(prerelease)
- if i >= 1 {
- if prerelease[i-1] != '.' {
- return "", fmt.Errorf("%w: final digits in a prerelease must follow a period", derrors.InvalidArgument)
- }
- // Remove the dot.
- prerelease = prerelease[:i-1] + prerelease[i:]
- }
- goVersion += strings.TrimPrefix(prerelease, "-")
- }
- return goVersion, nil
-}
-
-// MajorVersionForVersion returns the Go major version for version.
-// E.g. "v1.13.3" => "go1".
-func MajorVersionForVersion(version string) (_ string, err error) {
- defer derrors.Wrap(&err, "MajorVersionForVersion(%q)", version)
-
- tag, err := TagForVersion(version)
- if err != nil {
- return "", err
- }
- if tag == "go1" {
- return tag, nil
- }
- i := strings.IndexRune(tag, '.')
- if i < 0 {
- return "", fmt.Errorf("no '.' in go tag %q", tag)
- }
- return tag[:i], nil
-}
-
-// finalDigitsIndex returns the index of the first digit in the sequence of digits ending s.
-// If s doesn't end in digits, it returns -1.
-func finalDigitsIndex(s string) int {
- // Assume ASCII (since the semver package does anyway).
- var i int
- for i = len(s) - 1; i >= 0; i-- {
- if s[i] < '0' || s[i] > '9' {
- break
- }
- }
- if i == len(s)-1 {
- return -1
- }
- return i + 1
-}
-
-const (
- GoRepoURL = "https://go.googlesource.com/go"
- GoSourceRepoURL = "https://cs.opensource.google/go/go"
-
- GitHubRepo = "github.com/golang/go"
-)
-
-// TestCommitTime is the time used for all commits when UseTestData is true.
-var (
- TestCommitTime = time.Date(2019, 9, 4, 1, 2, 3, 0, time.UTC)
- TestMasterVersion = "v0.0.0-20190904010203-89fb59e2e920"
- TestDevFuzzVersion = "v0.0.0-20190904010203-12de34vf56uz"
-)
-
-var (
- goRepoMu sync.Mutex
- theGoRepo goRepo = &remoteGoRepo{}
-)
-
-func getGoRepo() goRepo {
- goRepoMu.Lock()
- defer goRepoMu.Unlock()
- return theGoRepo
-}
-
-func swapGoRepo(gr goRepo) goRepo {
- goRepoMu.Lock()
- defer goRepoMu.Unlock()
- old := theGoRepo
- theGoRepo = gr
- return old
-}
-
-// WithTestData arranges for this package to use a testing version of the Go repo.
-// The returned function restores the previous state. Use with defer:
-//
-// defer WithTestData()()
-func WithTestData() func() {
- return withGoRepo(&testGoRepo{})
-}
-
-func withGoRepo(gr goRepo) func() {
- old := swapGoRepo(gr)
- return func() {
- swapGoRepo(old)
- }
-}
-
-// SetGoRepoPath tells this package to obtain the Go repo from the
-// local filesystem at path, instead of cloning it.
-func SetGoRepoPath(path string) error {
- gr, err := newLocalGoRepo(path)
- if err != nil {
- return err
- }
- swapGoRepo(gr)
- return nil
-}
-
-func refNameForVersion(v string) (plumbing.ReferenceName, error) {
- if v == version.Master {
- return plumbing.HEAD, nil
- }
- if SupportedBranches[v] {
- return plumbing.NewBranchReferenceName(v), nil
- }
- tag, err := TagForVersion(v)
- if err != nil {
- return "", err
- }
- return plumbing.NewTagReferenceName(tag), nil
-}
-
-// Versions returns all the versions of Go that are relevant to the discovery
-// site. These are all release versions (tags of the forms "goN.N" and
-// "goN.N.N", where N is a number) and beta or rc versions (tags of the forms
-// "goN.NbetaN" and "goN.N.NbetaN", and similarly for "rc" replacing "beta").
-func Versions() (_ []string, err error) {
- defer derrors.Wrap(&err, "stdlib.Versions()")
-
- refs, err := getGoRepo().refs()
- if err != nil {
- return nil, err
- }
- var versions []string
- for _, r := range refs {
- v := VersionForTag(r.Name().Short())
- if v != "" {
- versions = append(versions, v)
- }
- }
- return versions, nil
-}
-
-// ResolveSupportedBranches returns the current hashes for each ref in
-// SupportedBranches.
-func ResolveSupportedBranches() (_ map[string]string, err error) {
- defer derrors.Wrap(&err, "ResolveSupportedBranches")
-
- refs, err := getGoRepo().refs()
- if err != nil {
- return nil, err
- }
- m := map[string]string{}
- for _, r := range refs {
- name := r.Name().Short()
- if SupportedBranches[name] {
- m[name] = r.Hash().String()
- }
- }
- return m, nil
-}
-
-// Directory returns the directory of the standard library relative to the repo root.
-func Directory(v string) string {
- if semver.Compare(v, "v1.4.0-beta.1") >= 0 ||
- SupportedBranches[v] || strings.HasPrefix(v, "v0.0.0") {
- return "src"
- }
- // For versions older than v1.4.0-beta.1, the stdlib is in src/pkg.
- return "src/pkg"
-}
-
-// EstimatedZipSize is the approximate size of
-// Zip("v1.15.2").
-const EstimatedZipSize = 16 * 1024 * 1024
-
-// ZipInfo returns the proxy .info information for the module std.
-func ZipInfo(requestedVersion string) (resolvedVersion string, err error) {
- defer derrors.Wrap(&err, "stdlib.ZipInfo(%q)", requestedVersion)
-
- resolvedVersion, err = semanticVersion(requestedVersion)
- if err != nil {
- return "", err
- }
- return resolvedVersion, nil
-}
-
-func zipInternal(requestedVersion string) (_ *zip.Reader, resolvedVersion string, commitTime time.Time, prefix string, err error) {
- if requestedVersion == version.Latest {
- requestedVersion, err = semanticVersion(requestedVersion)
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- }
- repo, refName, err := getGoRepo().repoAtVersion(requestedVersion)
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- var buf bytes.Buffer
- z := zip.NewWriter(&buf)
-
- ref, err := repo.Reference(refName, true)
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- commit, err := repo.CommitObject(ref.Hash())
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- resolvedVersion = requestedVersion
- if SupportedBranches[requestedVersion] {
- resolvedVersion = newPseudoVersion("v0.0.0", commit.Committer.When, commit.Hash)
- }
- root, err := repo.TreeObject(commit.TreeHash)
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- prefixPath := ModulePath + "@" + requestedVersion
- // Add top-level files.
- if err := addFiles(z, repo, root, prefixPath, false); err != nil {
- return nil, "", time.Time{}, "", err
- }
- // Add files from the stdlib directory.
- libdir := root
- for _, d := range strings.Split(Directory(resolvedVersion), "/") {
- libdir, err = subTree(repo, libdir, d)
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- }
- if err := addFiles(z, repo, libdir, prefixPath, true); err != nil {
- return nil, "", time.Time{}, "", err
- }
- if err := z.Close(); err != nil {
- return nil, "", time.Time{}, "", err
- }
- br := bytes.NewReader(buf.Bytes())
- zr, err := zip.NewReader(br, int64(br.Len()))
- if err != nil {
- return nil, "", time.Time{}, "", err
- }
- return zr, resolvedVersion, commit.Committer.When, prefixPath, nil
-}
-
-// ContentDir creates an fs.FS representing the entire Go standard library at the
-// given version (which must have been resolved with ZipInfo) and returns a
-// reader to it. It also returns the time of the commit for that version.
-//
-// Normally, ContentDir returns the resolved version it was passed. If the
-// resolved version is a supported branch like "master", ContentDir returns a
-// semantic version for the branch.
-//
-// ContentDir reads the standard library at the Go repository tag corresponding
-// to to the given semantic version.
-//
-// ContentDir ignores go.mod files in the standard library, treating it as if it
-// were a single module named "std" at the given version.
-func ContentDir(requestedVersion string) (_ fs.FS, resolvedVersion string, commitTime time.Time, err error) {
- defer derrors.Wrap(&err, "stdlib.ContentDir(%q)", requestedVersion)
-
- zr, resolvedVersion, commitTime, prefix, err := zipInternal(requestedVersion)
- if err != nil {
- return nil, "", time.Time{}, err
- }
- cdir, err := fs.Sub(zr, prefix)
- if err != nil {
- return nil, "", time.Time{}, err
- }
- return cdir, resolvedVersion, commitTime, nil
-}
-
-const pseudoHashLen = 12
-
-func newPseudoVersion(version string, commitTime time.Time, hash plumbing.Hash) string {
- return fmt.Sprintf("%s-%s-%s", version, commitTime.Format("20060102150405"), hash.String()[:pseudoHashLen])
-}
-
-// VersionMatchesHash reports whether v is a pseudo-version whose hash
-// part matches the prefix of the given hash.
-func VersionMatchesHash(v, hash string) bool {
- if !version.IsPseudo(v) {
- return false
- }
- return v[len(v)-pseudoHashLen:] == hash[:pseudoHashLen]
-}
-
-// semanticVersion returns the semantic version corresponding to the
-// requestedVersion. If the requested version is version.Master, then semanticVersion
-// returns it as is. The branch name is resolved to a proper pseudo-version in
-// Zip.
-func semanticVersion(requestedVersion string) (_ string, err error) {
- defer derrors.Wrap(&err, "semanticVersion(%q)", requestedVersion)
-
- if SupportedBranches[requestedVersion] {
- return requestedVersion, nil
- }
-
- knownVersions, err := Versions()
- if err != nil {
- return "", err
- }
-
- switch requestedVersion {
- case version.Latest:
- var latestVersion string
- for _, v := range knownVersions {
- if !strings.HasPrefix(v, "v") {
- continue
- }
- versionType, err := version.ParseType(v)
- if err != nil {
- return "", err
- }
- if versionType != version.TypeRelease {
- // We expect there to always be at least 1 release version.
- continue
- }
- if semver.Compare(v, latestVersion) > 0 {
- latestVersion = v
- }
- }
- return latestVersion, nil
- default:
- for _, v := range knownVersions {
- if v == requestedVersion {
- return requestedVersion, nil
- }
- }
- }
-
- return "", fmt.Errorf("%w: requested version unknown: %q", derrors.InvalidArgument, requestedVersion)
-}
-
-// addFiles adds the files in t to z, using dirpath as the path prefix.
-// If recursive is true, it also adds the files in all subdirectories.
-func addFiles(z *zip.Writer, r *git.Repository, t *object.Tree, dirpath string, recursive bool) (err error) {
- defer derrors.Wrap(&err, "addFiles(zip, repository, tree, %q, %t)", dirpath, recursive)
-
- for _, e := range t.Entries {
- if strings.HasPrefix(e.Name, ".") || strings.HasPrefix(e.Name, "_") {
- continue
- }
- if e.Name == "go.mod" {
- // Ignore; we don't need it.
- continue
- }
- if strings.HasPrefix(e.Name, "README") && !strings.Contains(dirpath, "/") {
- // For versions newer than v1.4.0-beta.1, the stdlib is in src/pkg.
- // This means that our construction of the zip files will return
- // two READMEs at the root:
- // https://golang.org/README.md and
- // https://golang.org/src/README.vendor
- //
- // We do not want to display the README.md
- // or any README.vendor.
- // However, we do want to store the README in
- // other directories.
- continue
- }
- switch e.Mode {
- case filemode.Regular, filemode.Executable:
- blob, err := r.BlobObject(e.Hash)
- if err != nil {
- return err
- }
- src, err := blob.Reader()
- if err != nil {
- return err
- }
- if err := writeZipFile(z, path.Join(dirpath, e.Name), src); err != nil {
- _ = src.Close()
- return err
- }
- if err := src.Close(); err != nil {
- return err
- }
- case filemode.Dir:
- if !recursive || e.Name == "testdata" {
- continue
- }
- t2, err := r.TreeObject(e.Hash)
- if err != nil {
- return err
- }
- if err := addFiles(z, r, t2, path.Join(dirpath, e.Name), recursive); err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-func writeZipFile(z *zip.Writer, pathname string, src io.Reader) (err error) {
- defer derrors.Wrap(&err, "writeZipFile(zip, %q, src)", pathname)
-
- dst, err := z.Create(pathname)
- if err != nil {
- return err
- }
- _, err = io.Copy(dst, src)
- return err
-}
-
-// subTree looks non-recursively for a directory with the given name in t,
-// and returns the corresponding tree.
-// If a directory with such name doesn't exist in t, it returns os.ErrNotExist.
-func subTree(r *git.Repository, t *object.Tree, name string) (_ *object.Tree, err error) {
- defer derrors.Wrap(&err, "subTree(repository, tree, %q)", name)
-
- for _, e := range t.Entries {
- if e.Name == name {
- return r.TreeObject(e.Hash)
- }
- }
- return nil, os.ErrNotExist
-}
-
-// Contains reports whether the given import path could be part of the Go standard library,
-// by reporting whether the first component lacks a '.'.
-func Contains(path string) bool {
- if i := strings.IndexByte(path, '/'); i != -1 {
- path = path[:i]
- }
- return !strings.Contains(path, ".")
-}
diff --git a/internal/stdlib/stdlib_test.go b/internal/stdlib/stdlib_test.go
deleted file mode 100644
index 0aef287..0000000
--- a/internal/stdlib/stdlib_test.go
+++ /dev/null
@@ -1,396 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package stdlib
-
-import (
- "errors"
- "flag"
- "io/fs"
- "reflect"
- "testing"
-
- "golang.org/x/mod/semver"
- "golang.org/x/pkgsite-metrics/internal/version"
-)
-
-var (
- clone = flag.Bool("clone", false, "test actual clones of the Go repo")
- repoPath = flag.String("path", "", "path to Go repo to test")
-)
-
-func TestTagForVersion(t *testing.T) {
- for _, test := range []struct {
- name string
- version string
- want string
- wantErr bool
- }{
- {
- name: "std version v1.0.0",
- version: "v1.0.0",
- want: "go1",
- },
- {
- name: "std version v1.12.5",
- version: "v1.12.5",
- want: "go1.12.5",
- },
- {
- name: "std version v1.13, incomplete canonical version",
- version: "v1.13",
- want: "go1.13",
- },
- {
- name: "std version v1.13.0-beta.1",
- version: "v1.13.0-beta.1",
- want: "go1.13beta1",
- },
- {
- name: "std version v1.9.0-rc.2",
- version: "v1.9.0-rc.2",
- want: "go1.9rc2",
- },
- {
- name: "std with digitless prerelease",
- version: "v1.13.0-prerelease",
- want: "go1.13prerelease",
- },
- {
- name: "version v1.13.0",
- version: "v1.13.0",
- want: "go1.13",
- },
- {
- name: "master branch",
- version: "master",
- want: "master",
- },
- {
- name: "bad std semver",
- version: "v1.x",
- wantErr: true,
- },
- {
- name: "more bad std semver",
- version: "v1.0-",
- wantErr: true,
- },
- {
- name: "bad prerelease",
- version: "v1.13.0-beta1",
- wantErr: true,
- },
- {
- name: "another bad prerelease",
- version: "v1.13.0-whatevs99",
- wantErr: true,
- },
- } {
- t.Run(test.name, func(t *testing.T) {
- got, err := TagForVersion(test.version)
- if (err != nil) != test.wantErr {
- t.Errorf("TagForVersion(%q) = %q, %v, wantErr %v", test.version, got, err, test.wantErr)
- return
- }
- if got != test.want {
- t.Errorf("TagForVersion(%q) = %q, %v, wanted %q, %v", test.version, got, err, test.want, nil)
- }
- })
- }
-}
-
-func TestMajorVersionForVersion(t *testing.T) {
- for _, test := range []struct {
- in string
- want string // empty => error
- }{
- {"", ""},
- {"garbage", ""},
- {"v1.0.0", "go1"},
- {"v1.13.3", "go1"},
- {"v1.9.0-rc.2", "go1"},
- {"v2.1.3", "go2"},
- } {
- got, err := MajorVersionForVersion(test.in)
- if (err != nil) != (test.want == "") {
- t.Errorf("%q: err: got %v, wanted error: %t", test.in, err, test.want == "")
- }
- if err == nil && got != test.want {
- t.Errorf("%q: got %q, want %q", test.in, got, test.want)
- }
- }
-}
-
-func TestContentDir(t *testing.T) {
- defer WithTestData()()
- for _, resolvedVersion := range []string{
- "v1.3.2",
- "v1.12.5",
- "v1.14.6",
- DevFuzz,
- version.Master,
- } {
- t.Run(resolvedVersion, func(t *testing.T) {
- cdir, gotResolvedVersion, gotTime, err := ContentDir(resolvedVersion)
- if err != nil {
- t.Fatal(err)
- }
- if SupportedBranches[resolvedVersion] {
- if !version.IsPseudo(gotResolvedVersion) {
- t.Errorf("resolved version: %s is not a pseudo-version", gotResolvedVersion)
- }
- } else if gotResolvedVersion != resolvedVersion {
- t.Errorf("resolved version: got %s, want %s", gotResolvedVersion, resolvedVersion)
- }
- if !gotTime.Equal(TestCommitTime) {
- t.Errorf("commit time: got %s, want %s", gotTime, TestCommitTime)
- }
- checkContentDirFiles(t, cdir, resolvedVersion)
- })
- }
-}
-
-func TestContentDirCloneAndOpen(t *testing.T) {
- run := func(t *testing.T) {
- for _, resolvedVersion := range []string{
- "v1.3.2",
- "v1.14.6",
- version.Master,
- version.Latest,
- } {
- t.Run(resolvedVersion, func(t *testing.T) {
- cdir, _, _, err := ContentDir(resolvedVersion)
- if err != nil {
- t.Fatal(err)
- }
- checkContentDirFiles(t, cdir, resolvedVersion)
- })
- }
- }
-
- t.Run("clone", func(t *testing.T) {
- if !*clone {
- t.Skip("-clone not supplied")
- }
- defer withGoRepo(&remoteGoRepo{})()
- run(t)
- })
- t.Run("local", func(t *testing.T) {
- if *repoPath == "" {
- t.Skip("-path not supplied")
- }
- lgr, err := newLocalGoRepo(*repoPath)
- if err != nil {
- t.Fatal(err)
- }
- defer withGoRepo(lgr)()
- run(t)
- })
-}
-
-func checkContentDirFiles(t *testing.T, cdir fs.FS, resolvedVersion string) {
- wantFiles := map[string]bool{
- "LICENSE": true,
- "errors/errors.go": true,
- "errors/errors_test.go": true,
- }
- if semver.Compare(resolvedVersion, "v1.13.0") > 0 || resolvedVersion == TestMasterVersion {
- wantFiles["cmd/README.vendor"] = true
- }
- if semver.Compare(resolvedVersion, "v1.14.0") > 0 {
- wantFiles["context/context.go"] = true
- }
- const readmeVendorFile = "README.vendor"
- if _, err := fs.Stat(cdir, readmeVendorFile); !errors.Is(err, fs.ErrNotExist) {
- t.Fatalf("fs.Stat returned %v; want %q to be removed", err, readmeVendorFile)
- }
- err := fs.WalkDir(cdir, ".", func(path string, d fs.DirEntry, err error) error {
- if err != nil {
- return err
- }
- if d.IsDir() {
- return nil
- }
- delete(wantFiles, path)
- return nil
- })
- if err != nil {
- t.Fatal(err)
- }
- if len(wantFiles) > 0 {
- t.Errorf("zip missing files: %v", reflect.ValueOf(wantFiles).MapKeys())
- }
-}
-
-func TestZipInfo(t *testing.T) {
- defer WithTestData()()
-
- for _, tc := range []struct {
- requestedVersion string
- want string
- }{
- {
- requestedVersion: "latest",
- want: "v1.14.6",
- },
- {
- requestedVersion: "master",
- want: "master",
- },
- } {
- gotVersion, err := ZipInfo(tc.requestedVersion)
- if err != nil {
- t.Fatal(err)
- }
- if want := tc.want; gotVersion != want {
- t.Errorf("version: got %q, want %q", gotVersion, want)
- }
- }
-}
-
-func TestVersions(t *testing.T) {
- testVersions := func(wants []string) {
- got, err := Versions()
- if err != nil {
- t.Fatal(err)
- }
- gotmap := map[string]bool{}
- for _, g := range got {
- gotmap[g] = true
- }
- for _, w := range wants {
- if !gotmap[w] {
- t.Errorf("missing %s", w)
- }
- }
- }
-
- commonWants := []string{
- "v1.4.2",
- "v1.9.0-rc.1",
- "v1.11.0",
- "v1.13.0-beta.1",
- }
- otherWants := append([]string{"v1.17.6"}, commonWants...)
- t.Run("test", func(t *testing.T) {
- defer WithTestData()()
- testVersions(commonWants)
- })
- t.Run("local", func(t *testing.T) {
- if *repoPath == "" {
- t.Skip("-path not supplied")
- }
- lgr, err := newLocalGoRepo(*repoPath)
- if err != nil {
- t.Fatal(err)
- }
- defer withGoRepo(lgr)()
- testVersions(otherWants)
- })
- t.Run("remote", func(t *testing.T) {
- if !*clone {
- t.Skip("-clone not supplied")
- }
- defer withGoRepo(&remoteGoRepo{})()
- testVersions(otherWants)
- })
-}
-
-func TestVersionForTag(t *testing.T) {
- for _, test := range []struct {
- in, want string
- }{
- {"", ""},
- {"go1", "v1.0.0"},
- {"go1.9beta2", "v1.9.0-beta.2"},
- {"go1.12", "v1.12.0"},
- {"go1.9.7", "v1.9.7"},
- {"go2.0", "v2.0.0"},
- {"go1.9rc2", "v1.9.0-rc.2"},
- {"go1.1beta", ""},
- {"go1.0", ""},
- {"weekly.2012-02-14", ""},
- {"latest", "latest"},
- } {
- got := VersionForTag(test.in)
- if got != test.want {
- t.Errorf("VersionForTag(%q) = %q, want %q", test.in, got, test.want)
- }
- }
-}
-
-func TestContains(t *testing.T) {
- for _, test := range []struct {
- in string
- want bool
- }{
- {"fmt", true},
- {"encoding/json", true},
- {"something/with.dots", true},
- {"example.com", false},
- {"example.com/fmt", false},
- } {
- got := Contains(test.in)
- if got != test.want {
- t.Errorf("Contains(%q) = %t, want %t", test.in, got, test.want)
- }
- }
-}
-
-func TestDirectory(t *testing.T) {
- for _, tc := range []struct {
- version string
- want string
- }{
- {
- version: "v1.3.0-beta2",
- want: "src/pkg",
- },
- {
- version: "v1.16.0-beta1",
- want: "src",
- },
- {
- version: "master",
- want: "src",
- },
- } {
- got := Directory(tc.version)
- if got != tc.want {
- t.Errorf("Directory(%s) = %s, want %s", tc.version, got, tc.want)
- }
- }
-}
-
-func TestVersionMatchesHash(t *testing.T) {
- v := "v0.0.0-20210910212848-c8dfa306babb"
- h := "c8dfa306babb91e88f8ba25329b3ef8aa11944e1"
- if !VersionMatchesHash(v, h) {
- t.Error("got false, want true")
- }
- h = "c8dfa306babXb91e88f8ba25329b3ef8aa11944e1"
- if VersionMatchesHash(v, h) {
- t.Error("got true, want false")
- }
-}
-
-func TestResolveSupportedBranches(t *testing.T) {
- // Fix test
- t.Skip()
-
- got, err := ResolveSupportedBranches()
- if err != nil {
- t.Fatal(err)
- }
- // We can't check the hashes because they change, but we can check the keys.
- for key := range got {
- if !SupportedBranches[key] {
- t.Errorf("got key %q not in SupportedBranches", key)
- }
- }
- if g, w := len(got), len(SupportedBranches); g != w {
- t.Errorf("got %d hashes, want %d", g, w)
- }
-}
diff --git a/internal/stdlib/testdata/dev.fuzz/LICENSE b/internal/stdlib/testdata/dev.fuzz/LICENSE
deleted file mode 100644
index 6a66aea..0000000
--- a/internal/stdlib/testdata/dev.fuzz/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2009 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/internal/stdlib/testdata/dev.fuzz/README.md b/internal/stdlib/testdata/dev.fuzz/README.md
deleted file mode 100644
index d6d2b9d..0000000
--- a/internal/stdlib/testdata/dev.fuzz/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# The Go Programming Language
diff --git a/internal/stdlib/testdata/dev.fuzz/src/README.vendor b/internal/stdlib/testdata/dev.fuzz/src/README.vendor
deleted file mode 100644
index e74fc2f..0000000
--- a/internal/stdlib/testdata/dev.fuzz/src/README.vendor
+++ /dev/null
@@ -1,54 +0,0 @@
-Vendoring in std and cmd
-========================
-
-The Go command maintains copies of external packages needed by the
-standard library in the src/vendor and src/cmd/vendor directories.
-
-In GOPATH mode, imports of vendored packages are resolved to these
-directories following normal vendor directory logic
-(see golang.org/s/go15vendor).
-
-In module mode, std and cmd are modules (defined in src/go.mod and
-src/cmd/go.mod). When a package outside std or cmd is imported
-by a package inside std or cmd, the import path is interpreted
-as if it had a "vendor/" prefix. For example, within "crypto/tls",
-an import of "golang.org/x/crypto/cryptobyte" resolves to
-"vendor/golang.org/x/crypto/cryptobyte". When a package with the
-same path is imported from a package outside std or cmd, it will
-be resolved normally. Consequently, a binary may be built with two
-copies of a package at different versions if the package is
-imported normally and vendored by the standard library.
-
-Vendored packages are internally renamed with a "vendor/" prefix
-to preserve the invariant that all packages have distinct paths.
-This is necessary to avoid compiler and linker conflicts. Adding
-a "vendor/" prefix also maintains the invariant that standard
-library packages begin with a dotless path element.
-
-The module requirements of std and cmd do not influence version
-selection in other modules. They are only considered when running
-module commands like 'go get' and 'go mod vendor' from a directory
-in GOROOT/src.
-
-Maintaining vendor directories
-==============================
-
-Before updating vendor directories, ensure that module mode is enabled.
-Make sure GO111MODULE=off is not set ('on' or 'auto' should work).
-
-Requirements may be added, updated, and removed with 'go get'.
-The vendor directory may be updated with 'go mod vendor'.
-A typical sequence might be:
-
- cd src
- go get -d golang.org/x/net@latest
- go mod tidy
- go mod vendor
-
-Use caution when passing '-u' to 'go get'. The '-u' flag updates
-modules providing all transitively imported packages, not only
-the module providing the target package.
-
-Note that 'go mod vendor' only copies packages that are transitively
-imported by packages in the current module. If a new package is needed,
-it should be imported before running 'go mod vendor'.
diff --git a/internal/stdlib/testdata/dev.fuzz/src/cmd/README.vendor b/internal/stdlib/testdata/dev.fuzz/src/cmd/README.vendor
deleted file mode 100644
index ac0df5e..0000000
--- a/internal/stdlib/testdata/dev.fuzz/src/cmd/README.vendor
+++ /dev/null
@@ -1,2 +0,0 @@
-See src/README.vendor for information on loading vendored packages
-and updating the vendor directory.
diff --git a/internal/stdlib/testdata/dev.fuzz/src/errors/errors.go b/internal/stdlib/testdata/dev.fuzz/src/errors/errors.go
deleted file mode 100644
index b8a4692..0000000
--- a/internal/stdlib/testdata/dev.fuzz/src/errors/errors.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package errors implements functions to manipulate errors.
-package errors
-
-// New returns an error that formats as the given text.
-func New(text string) error {
- return &errorString{text}
-}
-
-// errorString is a trivial implementation of error.
-type errorString struct {
- s string
-}
-
-func (e *errorString) Error() string {
- return e.s
-}
diff --git a/internal/stdlib/testdata/dev.fuzz/src/errors/errors_test.go b/internal/stdlib/testdata/dev.fuzz/src/errors/errors_test.go
deleted file mode 100644
index cf4df90..0000000
--- a/internal/stdlib/testdata/dev.fuzz/src/errors/errors_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "errors"
- "fmt"
- "testing"
-)
-
-func TestNewEqual(t *testing.T) {
- // Different allocations should not be equal.
- if errors.New("abc") == errors.New("abc") {
- t.Errorf(`New("abc") == New("abc")`)
- }
- if errors.New("abc") == errors.New("xyz") {
- t.Errorf(`New("abc") == New("xyz")`)
- }
-
- // Same allocation should be equal to itself (not crash).
- err := errors.New("jkl")
- if err != err {
- t.Errorf(`err != err`)
- }
-}
-
-func TestErrorMethod(t *testing.T) {
- err := errors.New("abc")
- if err.Error() != "abc" {
- t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
- }
-}
-
-func ExampleNew() {
- err := errors.New("emit macho dwarf: elf header corrupted")
- if err != nil {
- fmt.Print(err)
- }
- // Output: emit macho dwarf: elf header corrupted
-}
-
-// The fmt package's Errorf function lets us use the package's formatting
-// features to create descriptive error messages.
-func ExampleNew_errorf() {
- const name, id = "bimmler", 17
- err := fmt.Errorf("user %q (id %d) not found", name, id)
- if err != nil {
- fmt.Print(err)
- }
- // Output: user "bimmler" (id 17) not found
-}
diff --git a/internal/stdlib/testdata/master/LICENSE b/internal/stdlib/testdata/master/LICENSE
deleted file mode 100644
index 6a66aea..0000000
--- a/internal/stdlib/testdata/master/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2009 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/internal/stdlib/testdata/master/README.md b/internal/stdlib/testdata/master/README.md
deleted file mode 100644
index d6d2b9d..0000000
--- a/internal/stdlib/testdata/master/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# The Go Programming Language
diff --git a/internal/stdlib/testdata/master/src/README.vendor b/internal/stdlib/testdata/master/src/README.vendor
deleted file mode 100644
index e74fc2f..0000000
--- a/internal/stdlib/testdata/master/src/README.vendor
+++ /dev/null
@@ -1,54 +0,0 @@
-Vendoring in std and cmd
-========================
-
-The Go command maintains copies of external packages needed by the
-standard library in the src/vendor and src/cmd/vendor directories.
-
-In GOPATH mode, imports of vendored packages are resolved to these
-directories following normal vendor directory logic
-(see golang.org/s/go15vendor).
-
-In module mode, std and cmd are modules (defined in src/go.mod and
-src/cmd/go.mod). When a package outside std or cmd is imported
-by a package inside std or cmd, the import path is interpreted
-as if it had a "vendor/" prefix. For example, within "crypto/tls",
-an import of "golang.org/x/crypto/cryptobyte" resolves to
-"vendor/golang.org/x/crypto/cryptobyte". When a package with the
-same path is imported from a package outside std or cmd, it will
-be resolved normally. Consequently, a binary may be built with two
-copies of a package at different versions if the package is
-imported normally and vendored by the standard library.
-
-Vendored packages are internally renamed with a "vendor/" prefix
-to preserve the invariant that all packages have distinct paths.
-This is necessary to avoid compiler and linker conflicts. Adding
-a "vendor/" prefix also maintains the invariant that standard
-library packages begin with a dotless path element.
-
-The module requirements of std and cmd do not influence version
-selection in other modules. They are only considered when running
-module commands like 'go get' and 'go mod vendor' from a directory
-in GOROOT/src.
-
-Maintaining vendor directories
-==============================
-
-Before updating vendor directories, ensure that module mode is enabled.
-Make sure GO111MODULE=off is not set ('on' or 'auto' should work).
-
-Requirements may be added, updated, and removed with 'go get'.
-The vendor directory may be updated with 'go mod vendor'.
-A typical sequence might be:
-
- cd src
- go get -d golang.org/x/net@latest
- go mod tidy
- go mod vendor
-
-Use caution when passing '-u' to 'go get'. The '-u' flag updates
-modules providing all transitively imported packages, not only
-the module providing the target package.
-
-Note that 'go mod vendor' only copies packages that are transitively
-imported by packages in the current module. If a new package is needed,
-it should be imported before running 'go mod vendor'.
diff --git a/internal/stdlib/testdata/master/src/cmd/README.vendor b/internal/stdlib/testdata/master/src/cmd/README.vendor
deleted file mode 100644
index ac0df5e..0000000
--- a/internal/stdlib/testdata/master/src/cmd/README.vendor
+++ /dev/null
@@ -1,2 +0,0 @@
-See src/README.vendor for information on loading vendored packages
-and updating the vendor directory.
diff --git a/internal/stdlib/testdata/master/src/errors/errors.go b/internal/stdlib/testdata/master/src/errors/errors.go
deleted file mode 100644
index b8a4692..0000000
--- a/internal/stdlib/testdata/master/src/errors/errors.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package errors implements functions to manipulate errors.
-package errors
-
-// New returns an error that formats as the given text.
-func New(text string) error {
- return &errorString{text}
-}
-
-// errorString is a trivial implementation of error.
-type errorString struct {
- s string
-}
-
-func (e *errorString) Error() string {
- return e.s
-}
diff --git a/internal/stdlib/testdata/master/src/errors/errors_test.go b/internal/stdlib/testdata/master/src/errors/errors_test.go
deleted file mode 100644
index cf4df90..0000000
--- a/internal/stdlib/testdata/master/src/errors/errors_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "errors"
- "fmt"
- "testing"
-)
-
-func TestNewEqual(t *testing.T) {
- // Different allocations should not be equal.
- if errors.New("abc") == errors.New("abc") {
- t.Errorf(`New("abc") == New("abc")`)
- }
- if errors.New("abc") == errors.New("xyz") {
- t.Errorf(`New("abc") == New("xyz")`)
- }
-
- // Same allocation should be equal to itself (not crash).
- err := errors.New("jkl")
- if err != err {
- t.Errorf(`err != err`)
- }
-}
-
-func TestErrorMethod(t *testing.T) {
- err := errors.New("abc")
- if err.Error() != "abc" {
- t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
- }
-}
-
-func ExampleNew() {
- err := errors.New("emit macho dwarf: elf header corrupted")
- if err != nil {
- fmt.Print(err)
- }
- // Output: emit macho dwarf: elf header corrupted
-}
-
-// The fmt package's Errorf function lets us use the package's formatting
-// features to create descriptive error messages.
-func ExampleNew_errorf() {
- const name, id = "bimmler", 17
- err := fmt.Errorf("user %q (id %d) not found", name, id)
- if err != nil {
- fmt.Print(err)
- }
- // Output: user "bimmler" (id 17) not found
-}
diff --git a/internal/stdlib/testdata/v1.12.5/LICENSE b/internal/stdlib/testdata/v1.12.5/LICENSE
deleted file mode 100644
index 6a66aea..0000000
--- a/internal/stdlib/testdata/v1.12.5/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2009 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/internal/stdlib/testdata/v1.12.5/README.md b/internal/stdlib/testdata/v1.12.5/README.md
deleted file mode 100644
index d6d2b9d..0000000
--- a/internal/stdlib/testdata/v1.12.5/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# The Go Programming Language
diff --git a/internal/stdlib/testdata/v1.12.5/src/_foo/README.md b/internal/stdlib/testdata/v1.12.5/src/_foo/README.md
deleted file mode 100644
index 177b08e..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/_foo/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Can not read content
diff --git a/internal/stdlib/testdata/v1.12.5/src/builtin/builtin.go b/internal/stdlib/testdata/v1.12.5/src/builtin/builtin.go
deleted file mode 100644
index c78fe09..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/builtin/builtin.go
+++ /dev/null
@@ -1,263 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-/*
- Package builtin provides documentation for Go's predeclared identifiers.
- The items documented here are not actually in package builtin
- but their descriptions here allow godoc to present documentation
- for the language's special identifiers.
-*/
-package builtin
-
-// bool is the set of boolean values, true and false.
-type bool bool
-
-// true and false are the two untyped boolean values.
-const (
- true = 0 == 0 // Untyped bool.
- false = 0 != 0 // Untyped bool.
-)
-
-// uint8 is the set of all unsigned 8-bit integers.
-// Range: 0 through 255.
-type uint8 uint8
-
-// uint16 is the set of all unsigned 16-bit integers.
-// Range: 0 through 65535.
-type uint16 uint16
-
-// uint32 is the set of all unsigned 32-bit integers.
-// Range: 0 through 4294967295.
-type uint32 uint32
-
-// uint64 is the set of all unsigned 64-bit integers.
-// Range: 0 through 18446744073709551615.
-type uint64 uint64
-
-// int8 is the set of all signed 8-bit integers.
-// Range: -128 through 127.
-type int8 int8
-
-// int16 is the set of all signed 16-bit integers.
-// Range: -32768 through 32767.
-type int16 int16
-
-// int32 is the set of all signed 32-bit integers.
-// Range: -2147483648 through 2147483647.
-type int32 int32
-
-// int64 is the set of all signed 64-bit integers.
-// Range: -9223372036854775808 through 9223372036854775807.
-type int64 int64
-
-// float32 is the set of all IEEE-754 32-bit floating-point numbers.
-type float32 float32
-
-// float64 is the set of all IEEE-754 64-bit floating-point numbers.
-type float64 float64
-
-// complex64 is the set of all complex numbers with float32 real and
-// imaginary parts.
-type complex64 complex64
-
-// complex128 is the set of all complex numbers with float64 real and
-// imaginary parts.
-type complex128 complex128
-
-// string is the set of all strings of 8-bit bytes, conventionally but not
-// necessarily representing UTF-8-encoded text. A string may be empty, but
-// not nil. Values of string type are immutable.
-type string string
-
-// int is a signed integer type that is at least 32 bits in size. It is a
-// distinct type, however, and not an alias for, say, int32.
-type int int
-
-// uint is an unsigned integer type that is at least 32 bits in size. It is a
-// distinct type, however, and not an alias for, say, uint32.
-type uint uint
-
-// uintptr is an integer type that is large enough to hold the bit pattern of
-// any pointer.
-type uintptr uintptr
-
-// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
-// used, by convention, to distinguish byte values from 8-bit unsigned
-// integer values.
-type byte = uint8
-
-// rune is an alias for int32 and is equivalent to int32 in all ways. It is
-// used, by convention, to distinguish character values from integer values.
-type rune = int32
-
-// iota is a predeclared identifier representing the untyped integer ordinal
-// number of the current const specification in a (usually parenthesized)
-// const declaration. It is zero-indexed.
-const iota = 0 // Untyped int.
-
-// nil is a predeclared identifier representing the zero value for a
-// pointer, channel, func, interface, map, or slice type.
-var nil Type // Type must be a pointer, channel, func, interface, map, or slice type
-
-// Type is here for the purposes of documentation only. It is a stand-in
-// for any Go type, but represents the same type for any given function
-// invocation.
-type Type int
-
-// Type1 is here for the purposes of documentation only. It is a stand-in
-// for any Go type, but represents the same type for any given function
-// invocation.
-type Type1 int
-
-// IntegerType is here for the purposes of documentation only. It is a stand-in
-// for any integer type: int, uint, int8 etc.
-type IntegerType int
-
-// FloatType is here for the purposes of documentation only. It is a stand-in
-// for either float type: float32 or float64.
-type FloatType float32
-
-// ComplexType is here for the purposes of documentation only. It is a
-// stand-in for either complex type: complex64 or complex128.
-type ComplexType complex64
-
-// The append built-in function appends elements to the end of a slice. If
-// it has sufficient capacity, the destination is resliced to accommodate the
-// new elements. If it does not, a new underlying array will be allocated.
-// Append returns the updated slice. It is therefore necessary to store the
-// result of append, often in the variable holding the slice itself:
-// slice = append(slice, elem1, elem2)
-// slice = append(slice, anotherSlice...)
-// As a special case, it is legal to append a string to a byte slice, like this:
-// slice = append([]byte("hello "), "world"...)
-func append(slice []Type, elems ...Type) []Type
-
-// The copy built-in function copies elements from a source slice into a
-// destination slice. (As a special case, it also will copy bytes from a
-// string to a slice of bytes.) The source and destination may overlap. Copy
-// returns the number of elements copied, which will be the minimum of
-// len(src) and len(dst).
-func copy(dst, src []Type) int
-
-// The delete built-in function deletes the element with the specified key
-// (m[key]) from the map. If m is nil or there is no such element, delete
-// is a no-op.
-func delete(m map[Type]Type1, key Type)
-
-// The len built-in function returns the length of v, according to its type:
-// Array: the number of elements in v.
-// Pointer to array: the number of elements in *v (even if v is nil).
-// Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
-// String: the number of bytes in v.
-// Channel: the number of elements queued (unread) in the channel buffer;
-// if v is nil, len(v) is zero.
-// For some arguments, such as a string literal or a simple array expression, the
-// result can be a constant. See the Go language specification's "Length and
-// capacity" section for details.
-func len(v Type) int
-
-// The cap built-in function returns the capacity of v, according to its type:
-// Array: the number of elements in v (same as len(v)).
-// Pointer to array: the number of elements in *v (same as len(v)).
-// Slice: the maximum length the slice can reach when resliced;
-// if v is nil, cap(v) is zero.
-// Channel: the channel buffer capacity, in units of elements;
-// if v is nil, cap(v) is zero.
-// For some arguments, such as a simple array expression, the result can be a
-// constant. See the Go language specification's "Length and capacity" section for
-// details.
-func cap(v Type) int
-
-// The make built-in function allocates and initializes an object of type
-// slice, map, or chan (only). Like new, the first argument is a type, not a
-// value. Unlike new, make's return type is the same as the type of its
-// argument, not a pointer to it. The specification of the result depends on
-// the type:
-// Slice: The size specifies the length. The capacity of the slice is
-// equal to its length. A second integer argument may be provided to
-// specify a different capacity; it must be no smaller than the
-// length. For example, make([]int, 0, 10) allocates an underlying array
-// of size 10 and returns a slice of length 0 and capacity 10 that is
-// backed by this underlying array.
-// Map: An empty map is allocated with enough space to hold the
-// specified number of elements. The size may be omitted, in which case
-// a small starting size is allocated.
-// Channel: The channel's buffer is initialized with the specified
-// buffer capacity. If zero, or the size is omitted, the channel is
-// unbuffered.
-func make(t Type, size ...IntegerType) Type
-
-// The new built-in function allocates memory. The first argument is a type,
-// not a value, and the value returned is a pointer to a newly
-// allocated zero value of that type.
-func new(Type) *Type
-
-// The complex built-in function constructs a complex value from two
-// floating-point values. The real and imaginary parts must be of the same
-// size, either float32 or float64 (or assignable to them), and the return
-// value will be the corresponding complex type (complex64 for float32,
-// complex128 for float64).
-func complex(r, i FloatType) ComplexType
-
-// The real built-in function returns the real part of the complex number c.
-// The return value will be floating point type corresponding to the type of c.
-func real(c ComplexType) FloatType
-
-// The imag built-in function returns the imaginary part of the complex
-// number c. The return value will be floating point type corresponding to
-// the type of c.
-func imag(c ComplexType) FloatType
-
-// The close built-in function closes a channel, which must be either
-// bidirectional or send-only. It should be executed only by the sender,
-// never the receiver, and has the effect of shutting down the channel after
-// the last sent value is received. After the last value has been received
-// from a closed channel c, any receive from c will succeed without
-// blocking, returning the zero value for the channel element. The form
-// x, ok := <-c
-// will also set ok to false for a closed channel.
-func close(c chan<- Type)
-
-// The panic built-in function stops normal execution of the current
-// goroutine. When a function F calls panic, normal execution of F stops
-// immediately. Any functions whose execution was deferred by F are run in
-// the usual way, and then F returns to its caller. To the caller G, the
-// invocation of F then behaves like a call to panic, terminating G's
-// execution and running any deferred functions. This continues until all
-// functions in the executing goroutine have stopped, in reverse order. At
-// that point, the program is terminated and the error condition is reported,
-// including the value of the argument to panic. This termination sequence
-// is called panicking and can be controlled by the built-in function
-// recover.
-func panic(v interface{})
-
-// The recover built-in function allows a program to manage behavior of a
-// panicking goroutine. Executing a call to recover inside a deferred
-// function (but not any function called by it) stops the panicking sequence
-// by restoring normal execution and retrieves the error value passed to the
-// call of panic. If recover is called outside the deferred function it will
-// not stop a panicking sequence. In this case, or when the goroutine is not
-// panicking, or if the argument supplied to panic was nil, recover returns
-// nil. Thus the return value from recover reports whether the goroutine is
-// panicking.
-func recover() interface{}
-
-// The print built-in function formats its arguments in an
-// implementation-specific way and writes the result to standard error.
-// Print is useful for bootstrapping and debugging; it is not guaranteed
-// to stay in the language.
-func print(args ...Type)
-
-// The println built-in function formats its arguments in an
-// implementation-specific way and writes the result to standard error.
-// Spaces are always added between arguments and a newline is appended.
-// Println is useful for bootstrapping and debugging; it is not guaranteed
-// to stay in the language.
-func println(args ...Type)
-
-// The error built-in interface type is the conventional interface for
-// representing an error condition, with the nil value representing no error.
-type error interface {
- Error() string
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/README b/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/README
deleted file mode 100644
index 9de1f51..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/README
+++ /dev/null
@@ -1 +0,0 @@
-This directory is the copy of Google's pprof shipped as part of the Go distribution.
diff --git a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/doc.go b/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/doc.go
deleted file mode 100644
index 84de036..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/doc.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Pprof interprets and displays profiles of Go programs.
-//
-// Usage:
-//
-// go tool pprof binary profile
-//
-// For more information, see https://blog.golang.org/profiling-go-programs.
-package main
diff --git a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/pprof.go b/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/pprof.go
deleted file mode 100644
index 89f3969..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/pprof.go
+++ /dev/null
@@ -1,376 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// pprof is a tool for visualization of profile.data. It is based on
-// the upstream version at github.com/google/pprof, with minor
-// modifications specific to the Go distribution. Please consider
-// upstreaming any modifications to these packages.
-
-package main
-
-import (
- "crypto/tls"
- "debug/dwarf"
- "fmt"
- "io"
- "net/http"
- "net/url"
- "os"
- "regexp"
- "strconv"
- "strings"
- "sync"
- "time"
-
- "cmd/internal/objfile"
-
- "github.com/google/pprof/driver"
- "github.com/google/pprof/profile"
-)
-
-func main() {
- options := &driver.Options{
- Fetch: new(fetcher),
- Obj: new(objTool),
- UI: newUI(),
- }
- if err := driver.PProf(options); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- os.Exit(2)
- }
-}
-
-type fetcher struct {
-}
-
-func (f *fetcher) Fetch(src string, duration, timeout time.Duration) (*profile.Profile, string, error) {
- sourceURL, timeout := adjustURL(src, duration, timeout)
- if sourceURL == "" {
- // Could not recognize URL, let regular pprof attempt to fetch the profile (eg. from a file)
- return nil, "", nil
- }
- fmt.Fprintln(os.Stderr, "Fetching profile over HTTP from", sourceURL)
- if duration > 0 {
- fmt.Fprintf(os.Stderr, "Please wait... (%v)\n", duration)
- }
- p, err := getProfile(sourceURL, timeout)
- return p, sourceURL, err
-}
-
-func getProfile(source string, timeout time.Duration) (*profile.Profile, error) {
- url, err := url.Parse(source)
- if err != nil {
- return nil, err
- }
-
- var tlsConfig *tls.Config
- if url.Scheme == "https+insecure" {
- tlsConfig = &tls.Config{
- InsecureSkipVerify: true,
- }
- url.Scheme = "https"
- source = url.String()
- }
-
- client := &http.Client{
- Transport: &http.Transport{
- ResponseHeaderTimeout: timeout + 5*time.Second,
- Proxy: http.ProxyFromEnvironment,
- TLSClientConfig: tlsConfig,
- },
- }
- resp, err := client.Get(source)
- if err != nil {
- return nil, err
- }
- if resp.StatusCode != http.StatusOK {
- defer resp.Body.Close()
- return nil, statusCodeError(resp)
- }
- return profile.Parse(resp.Body)
-}
-
-func statusCodeError(resp *http.Response) error {
- if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
- // error is from pprof endpoint
- if body, err := io.ReadAll(resp.Body); err == nil {
- return fmt.Errorf("server response: %s - %s", resp.Status, body)
- }
- }
- return fmt.Errorf("server response: %s", resp.Status)
-}
-
-// cpuProfileHandler is the Go pprof CPU profile handler URL.
-const cpuProfileHandler = "/debug/pprof/profile"
-
-// adjustURL applies the duration/timeout values and Go specific defaults
-func adjustURL(source string, duration, timeout time.Duration) (string, time.Duration) {
- u, err := url.Parse(source)
- if err != nil || (u.Host == "" && u.Scheme != "" && u.Scheme != "file") {
- // Try adding http:// to catch sources of the form hostname:port/path.
- // url.Parse treats "hostname" as the scheme.
- u, err = url.Parse("http://" + source)
- }
- if err != nil || u.Host == "" {
- return "", 0
- }
-
- if u.Path == "" || u.Path == "/" {
- u.Path = cpuProfileHandler
- }
-
- // Apply duration/timeout overrides to URL.
- values := u.Query()
- if duration > 0 {
- values.Set("seconds", fmt.Sprint(int(duration.Seconds())))
- } else {
- if urlSeconds := values.Get("seconds"); urlSeconds != "" {
- if us, err := strconv.ParseInt(urlSeconds, 10, 32); err == nil {
- duration = time.Duration(us) * time.Second
- }
- }
- }
- if timeout <= 0 {
- if duration > 0 {
- timeout = duration + duration/2
- } else {
- timeout = 60 * time.Second
- }
- }
- u.RawQuery = values.Encode()
- return u.String(), timeout
-}
-
-// objTool implements driver.ObjTool using Go libraries
-// (instead of invoking GNU binutils).
-type objTool struct {
- mu sync.Mutex
- disasmCache map[string]*objfile.Disasm
-}
-
-func (*objTool) Open(name string, start, limit, offset uint64) (driver.ObjFile, error) {
- of, err := objfile.Open(name)
- if err != nil {
- return nil, err
- }
- f := &file{
- name: name,
- file: of,
- }
- if start != 0 {
- if load, err := of.LoadAddress(); err == nil {
- f.offset = start - load
- }
- }
- return f, nil
-}
-
-func (*objTool) Demangle(names []string) (map[string]string, error) {
- // No C++, nothing to demangle.
- return make(map[string]string), nil
-}
-
-func (t *objTool) Disasm(file string, start, end uint64) ([]driver.Inst, error) {
- d, err := t.cachedDisasm(file)
- if err != nil {
- return nil, err
- }
- var asm []driver.Inst
- d.Decode(start, end, nil, func(pc, size uint64, file string, line int, text string) {
- asm = append(asm, driver.Inst{Addr: pc, File: file, Line: line, Text: text})
- })
- return asm, nil
-}
-
-func (t *objTool) cachedDisasm(file string) (*objfile.Disasm, error) {
- t.mu.Lock()
- defer t.mu.Unlock()
- if t.disasmCache == nil {
- t.disasmCache = make(map[string]*objfile.Disasm)
- }
- d := t.disasmCache[file]
- if d != nil {
- return d, nil
- }
- f, err := objfile.Open(file)
- if err != nil {
- return nil, err
- }
- d, err = f.Disasm()
- f.Close()
- if err != nil {
- return nil, err
- }
- t.disasmCache[file] = d
- return d, nil
-}
-
-func (*objTool) SetConfig(config string) {
- // config is usually used to say what binaries to invoke.
- // Ignore entirely.
-}
-
-// file implements driver.ObjFile using Go libraries
-// (instead of invoking GNU binutils).
-// A file represents a single executable being analyzed.
-type file struct {
- name string
- offset uint64
- sym []objfile.Sym
- file *objfile.File
- pcln objfile.Liner
-
- triedDwarf bool
- dwarf *dwarf.Data
-}
-
-func (f *file) Name() string {
- return f.name
-}
-
-func (f *file) Base() uint64 {
- // No support for shared libraries.
- return 0
-}
-
-func (f *file) BuildID() string {
- // No support for build ID.
- return ""
-}
-
-func (f *file) SourceLine(addr uint64) ([]driver.Frame, error) {
- if f.pcln == nil {
- pcln, err := f.file.PCLineTable()
- if err != nil {
- return nil, err
- }
- f.pcln = pcln
- }
- addr -= f.offset
- file, line, fn := f.pcln.PCToLine(addr)
- if fn != nil {
- frame := []driver.Frame{
- {
- Func: fn.Name,
- File: file,
- Line: line,
- },
- }
- return frame, nil
- }
-
- frames := f.dwarfSourceLine(addr)
- if frames != nil {
- return frames, nil
- }
-
- return nil, fmt.Errorf("no line information for PC=%#x", addr)
-}
-
-// dwarfSourceLine tries to get file/line information using DWARF.
-// This is for C functions that appear in the profile.
-// Returns nil if there is no information available.
-func (f *file) dwarfSourceLine(addr uint64) []driver.Frame {
- if f.dwarf == nil && !f.triedDwarf {
- // Ignore any error--we don't care exactly why there
- // is no DWARF info.
- f.dwarf, _ = f.file.DWARF()
- f.triedDwarf = true
- }
-
- if f.dwarf != nil {
- r := f.dwarf.Reader()
- unit, err := r.SeekPC(addr)
- if err == nil {
- if frames := f.dwarfSourceLineEntry(r, unit, addr); frames != nil {
- return frames
- }
- }
- }
-
- return nil
-}
-
-// dwarfSourceLineEntry tries to get file/line information from a
-// DWARF compilation unit. Returns nil if it doesn't find anything.
-func (f *file) dwarfSourceLineEntry(r *dwarf.Reader, entry *dwarf.Entry, addr uint64) []driver.Frame {
- lines, err := f.dwarf.LineReader(entry)
- if err != nil {
- return nil
- }
- var lentry dwarf.LineEntry
- if err := lines.SeekPC(addr, &lentry); err != nil {
- return nil
- }
-
- // Try to find the function name.
- name := ""
-FindName:
- for entry, err := r.Next(); entry != nil && err == nil; entry, err = r.Next() {
- if entry.Tag == dwarf.TagSubprogram {
- ranges, err := f.dwarf.Ranges(entry)
- if err != nil {
- return nil
- }
- for _, pcs := range ranges {
- if pcs[0] <= addr && addr < pcs[1] {
- var ok bool
- // TODO: AT_linkage_name, AT_MIPS_linkage_name.
- name, ok = entry.Val(dwarf.AttrName).(string)
- if ok {
- break FindName
- }
- }
- }
- }
- }
-
- // TODO: Report inlined functions.
-
- frames := []driver.Frame{
- {
- Func: name,
- File: lentry.File.Name,
- Line: lentry.Line,
- },
- }
-
- return frames
-}
-
-func (f *file) Symbols(r *regexp.Regexp, addr uint64) ([]*driver.Sym, error) {
- if f.sym == nil {
- sym, err := f.file.Symbols()
- if err != nil {
- return nil, err
- }
- f.sym = sym
- }
- var out []*driver.Sym
- for _, s := range f.sym {
- // Ignore a symbol with address 0 and size 0.
- // An ELF STT_FILE symbol will look like that.
- if s.Addr == 0 && s.Size == 0 {
- continue
- }
- if (r == nil || r.MatchString(s.Name)) && (addr == 0 || s.Addr <= addr && addr < s.Addr+uint64(s.Size)) {
- out = append(out, &driver.Sym{
- Name: []string{s.Name},
- File: f.name,
- Start: s.Addr,
- End: s.Addr + uint64(s.Size) - 1,
- })
- }
- }
- return out, nil
-}
-
-func (f *file) Close() error {
- f.file.Close()
- return nil
-}
-
-// newUI will be set in readlineui.go in some platforms
-// for interactive readline functionality.
-var newUI = func() driver.UI { return nil }
diff --git a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/readlineui.go b/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/readlineui.go
deleted file mode 100644
index 5b9701a..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/cmd/pprof/readlineui.go
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file contains an driver.UI implementation
-// that provides the readline functionality if possible.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
-// +build !appengine
-// +build !android
-
-package main
-
-import (
- "fmt"
- "io"
- "os"
- "strings"
-
- "github.com/google/pprof/driver"
- "golang.org/x/crypto/ssh/terminal"
-)
-
-func init() {
- newUI = newReadlineUI
-}
-
-// readlineUI implements driver.UI interface using the
-// golang.org/x/crypto/ssh/terminal package.
-// The upstream pprof command implements the same functionality
-// using the github.com/chzyer/readline package.
-type readlineUI struct {
- term *terminal.Terminal
-}
-
-func newReadlineUI() driver.UI {
- // disable readline UI in dumb terminal. (golang.org/issue/26254)
- if v := strings.ToLower(os.Getenv("TERM")); v == "" || v == "dumb" {
- return nil
- }
- // test if we can use terminal.ReadLine
- // that assumes operation in the raw mode.
- oldState, err := terminal.MakeRaw(0)
- if err != nil {
- return nil
- }
- terminal.Restore(0, oldState)
-
- rw := struct {
- io.Reader
- io.Writer
- }{os.Stdin, os.Stderr}
- return &readlineUI{term: terminal.NewTerminal(rw, "")}
-}
-
-// Read returns a line of text (a command) read from the user.
-// prompt is printed before reading the command.
-func (r *readlineUI) ReadLine(prompt string) (string, error) {
- r.term.SetPrompt(prompt)
-
- // skip error checking because we tested it
- // when creating this readlineUI initially.
- oldState, _ := terminal.MakeRaw(0)
- defer terminal.Restore(0, oldState)
-
- s, err := r.term.ReadLine()
- return s, err
-}
-
-// Print shows a message to the user.
-// It formats the text as fmt.Print would and adds a final \n if not already present.
-// For line-based UI, Print writes to standard error.
-// (Standard output is reserved for report data.)
-func (r *readlineUI) Print(args ...interface{}) {
- r.print(false, args...)
-}
-
-// PrintErr shows an error message to the user.
-// It formats the text as fmt.Print would and adds a final \n if not already present.
-// For line-based UI, PrintErr writes to standard error.
-func (r *readlineUI) PrintErr(args ...interface{}) {
- r.print(true, args...)
-}
-
-func (r *readlineUI) print(withColor bool, args ...interface{}) {
- text := fmt.Sprint(args...)
- if !strings.HasSuffix(text, "\n") {
- text += "\n"
- }
- if withColor {
- text = colorize(text)
- }
- fmt.Fprint(r.term, text)
-}
-
-// colorize prints the msg in red using ANSI color escapes.
-func colorize(msg string) string {
- const red = 31
- var colorEscape = fmt.Sprintf("\033[0;%dm", red)
- var colorResetEscape = "\033[0m"
- return colorEscape + msg + colorResetEscape
-}
-
-// IsTerminal reports whether the UI is known to be tied to an
-// interactive terminal (as opposed to being redirected to a file).
-func (r *readlineUI) IsTerminal() bool {
- const stdout = 1
- return terminal.IsTerminal(stdout)
-}
-
-// WantBrowser indicates whether browser should be opened with the -http option.
-func (r *readlineUI) WantBrowser() bool {
- return r.IsTerminal()
-}
-
-// SetAutoComplete instructs the UI to call complete(cmd) to obtain
-// the auto-completion of cmd, if the UI supports auto-completion at all.
-func (r *readlineUI) SetAutoComplete(complete func(string) string) {
- // TODO: Implement auto-completion support.
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/context/benchmark_test.go b/internal/stdlib/testdata/v1.12.5/src/context/benchmark_test.go
deleted file mode 100644
index 5d56863..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/context/benchmark_test.go
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context_test
-
-import (
- . "context"
- "fmt"
- "runtime"
- "sync"
- "testing"
- "time"
-)
-
-func BenchmarkCommonParentCancel(b *testing.B) {
- root := WithValue(Background(), "key", "value")
- shared, sharedcancel := WithCancel(root)
- defer sharedcancel()
-
- b.ResetTimer()
- b.RunParallel(func(pb *testing.PB) {
- x := 0
- for pb.Next() {
- ctx, cancel := WithCancel(shared)
- if ctx.Value("key").(string) != "value" {
- b.Fatal("should not be reached")
- }
- for i := 0; i < 100; i++ {
- x /= x + 1
- }
- cancel()
- for i := 0; i < 100; i++ {
- x /= x + 1
- }
- }
- })
-}
-
-func BenchmarkWithTimeout(b *testing.B) {
- for concurrency := 40; concurrency <= 4e5; concurrency *= 100 {
- name := fmt.Sprintf("concurrency=%d", concurrency)
- b.Run(name, func(b *testing.B) {
- benchmarkWithTimeout(b, concurrency)
- })
- }
-}
-
-func benchmarkWithTimeout(b *testing.B, concurrentContexts int) {
- gomaxprocs := runtime.GOMAXPROCS(0)
- perPContexts := concurrentContexts / gomaxprocs
- root := Background()
-
- // Generate concurrent contexts.
- var wg sync.WaitGroup
- ccf := make([][]CancelFunc, gomaxprocs)
- for i := range ccf {
- wg.Add(1)
- go func(i int) {
- defer wg.Done()
- cf := make([]CancelFunc, perPContexts)
- for j := range cf {
- _, cf[j] = WithTimeout(root, time.Hour)
- }
- ccf[i] = cf
- }(i)
- }
- wg.Wait()
-
- b.ResetTimer()
- b.RunParallel(func(pb *testing.PB) {
- wcf := make([]CancelFunc, 10)
- for pb.Next() {
- for i := range wcf {
- _, wcf[i] = WithTimeout(root, time.Hour)
- }
- for _, f := range wcf {
- f()
- }
- }
- })
- b.StopTimer()
-
- for _, cf := range ccf {
- for _, f := range cf {
- f()
- }
- }
-}
-
-func BenchmarkCancelTree(b *testing.B) {
- depths := []int{1, 10, 100, 1000}
- for _, d := range depths {
- b.Run(fmt.Sprintf("depth=%d", d), func(b *testing.B) {
- b.Run("Root=Background", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- buildContextTree(Background(), d)
- }
- })
- b.Run("Root=OpenCanceler", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- ctx, cancel := WithCancel(Background())
- buildContextTree(ctx, d)
- cancel()
- }
- })
- b.Run("Root=ClosedCanceler", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- ctx, cancel := WithCancel(Background())
- cancel()
- buildContextTree(ctx, d)
- }
- })
- })
- }
-}
-
-func buildContextTree(root Context, depth int) {
- for d := 0; d < depth; d++ {
- root, _ = WithCancel(root)
- }
-}
-
-func BenchmarkCheckCanceled(b *testing.B) {
- ctx, cancel := WithCancel(Background())
- cancel()
- b.Run("Err", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- ctx.Err()
- }
- })
- b.Run("Done", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- select {
- case <-ctx.Done():
- default:
- }
- }
- })
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/context/context.go b/internal/stdlib/testdata/v1.12.5/src/context/context.go
deleted file mode 100644
index 21a40d5..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/context/context.go
+++ /dev/null
@@ -1,493 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package context defines the Context type, which carries deadlines,
-// cancelation signals, and other request-scoped values across API boundaries
-// and between processes.
-//
-// Incoming requests to a server should create a Context, and outgoing
-// calls to servers should accept a Context. The chain of function
-// calls between them must propagate the Context, optionally replacing
-// it with a derived Context created using WithCancel, WithDeadline,
-// WithTimeout, or WithValue. When a Context is canceled, all
-// Contexts derived from it are also canceled.
-//
-// The WithCancel, WithDeadline, and WithTimeout functions take a
-// Context (the parent) and return a derived Context (the child) and a
-// CancelFunc. Calling the CancelFunc cancels the child and its
-// children, removes the parent's reference to the child, and stops
-// any associated timers. Failing to call the CancelFunc leaks the
-// child and its children until the parent is canceled or the timer
-// fires. The go vet tool checks that CancelFuncs are used on all
-// control-flow paths.
-//
-// Programs that use Contexts should follow these rules to keep interfaces
-// consistent across packages and enable static analysis tools to check context
-// propagation:
-//
-// Do not store Contexts inside a struct type; instead, pass a Context
-// explicitly to each function that needs it. The Context should be the first
-// parameter, typically named ctx:
-//
-// func DoSomething(ctx context.Context, arg Arg) error {
-// // ... use ctx ...
-// }
-//
-// Do not pass a nil Context, even if a function permits it. Pass context.TODO
-// if you are unsure about which Context to use.
-//
-// Use context Values only for request-scoped data that transits processes and
-// APIs, not for passing optional parameters to functions.
-//
-// The same Context may be passed to functions running in different goroutines;
-// Contexts are safe for simultaneous use by multiple goroutines.
-//
-// See https://blog.golang.org/context for example code for a server that uses
-// Contexts.
-package context
-
-import (
- "errors"
- "fmt"
- "reflect"
- "sync"
- "time"
-)
-
-// A Context carries a deadline, a cancelation signal, and other values across
-// API boundaries.
-//
-// Context's methods may be called by multiple goroutines simultaneously.
-type Context interface {
- // Deadline returns the time when work done on behalf of this context
- // should be canceled. Deadline returns ok==false when no deadline is
- // set. Successive calls to Deadline return the same results.
- Deadline() (deadline time.Time, ok bool)
-
- // Done returns a channel that's closed when work done on behalf of this
- // context should be canceled. Done may return nil if this context can
- // never be canceled. Successive calls to Done return the same value.
- //
- // WithCancel arranges for Done to be closed when cancel is called;
- // WithDeadline arranges for Done to be closed when the deadline
- // expires; WithTimeout arranges for Done to be closed when the timeout
- // elapses.
- //
- // Done is provided for use in select statements:
- //
- // // Stream generates values with DoSomething and sends them to out
- // // until DoSomething returns an error or ctx.Done is closed.
- // func Stream(ctx context.Context, out chan<- Value) error {
- // for {
- // v, err := DoSomething(ctx)
- // if err != nil {
- // return err
- // }
- // select {
- // case <-ctx.Done():
- // return ctx.Err()
- // case out <- v:
- // }
- // }
- // }
- //
- // See https://blog.golang.org/pipelines for more examples of how to use
- // a Done channel for cancelation.
- Done() <-chan struct{}
-
- // If Done is not yet closed, Err returns nil.
- // If Done is closed, Err returns a non-nil error explaining why:
- // Canceled if the context was canceled
- // or DeadlineExceeded if the context's deadline passed.
- // After Err returns a non-nil error, successive calls to Err return the same error.
- Err() error
-
- // Value returns the value associated with this context for key, or nil
- // if no value is associated with key. Successive calls to Value with
- // the same key returns the same result.
- //
- // Use context values only for request-scoped data that transits
- // processes and API boundaries, not for passing optional parameters to
- // functions.
- //
- // A key identifies a specific value in a Context. Functions that wish
- // to store values in Context typically allocate a key in a global
- // variable then use that key as the argument to context.WithValue and
- // Context.Value. A key can be any type that supports equality;
- // packages should define keys as an unexported type to avoid
- // collisions.
- //
- // Packages that define a Context key should provide type-safe accessors
- // for the values stored using that key:
- //
- // // Package user defines a User type that's stored in Contexts.
- // package user
- //
- // import "context"
- //
- // // User is the type of value stored in the Contexts.
- // type User struct {...}
- //
- // // key is an unexported type for keys defined in this package.
- // // This prevents collisions with keys defined in other packages.
- // type key int
- //
- // // userKey is the key for user.User values in Contexts. It is
- // // unexported; clients use user.NewContext and user.FromContext
- // // instead of using this key directly.
- // var userKey key
- //
- // // NewContext returns a new Context that carries value u.
- // func NewContext(ctx context.Context, u *User) context.Context {
- // return context.WithValue(ctx, userKey, u)
- // }
- //
- // // FromContext returns the User value stored in ctx, if any.
- // func FromContext(ctx context.Context) (*User, bool) {
- // u, ok := ctx.Value(userKey).(*User)
- // return u, ok
- // }
- Value(key interface{}) interface{}
-}
-
-// Canceled is the error returned by Context.Err when the context is canceled.
-var Canceled = errors.New("context canceled")
-
-// DeadlineExceeded is the error returned by Context.Err when the context's
-// deadline passes.
-var DeadlineExceeded error = deadlineExceededError{}
-
-type deadlineExceededError struct{}
-
-func (deadlineExceededError) Error() string { return "context deadline exceeded" }
-func (deadlineExceededError) Timeout() bool { return true }
-func (deadlineExceededError) Temporary() bool { return true }
-
-// An emptyCtx is never canceled, has no values, and has no deadline. It is not
-// struct{}, since vars of this type must have distinct addresses.
-type emptyCtx int
-
-func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
- return
-}
-
-func (*emptyCtx) Done() <-chan struct{} {
- return nil
-}
-
-func (*emptyCtx) Err() error {
- return nil
-}
-
-func (*emptyCtx) Value(key interface{}) interface{} {
- return nil
-}
-
-func (e *emptyCtx) String() string {
- switch e {
- case background:
- return "context.Background"
- case todo:
- return "context.TODO"
- }
- return "unknown empty Context"
-}
-
-var (
- background = new(emptyCtx)
- todo = new(emptyCtx)
-)
-
-// Background returns a non-nil, empty Context. It is never canceled, has no
-// values, and has no deadline. It is typically used by the main function,
-// initialization, and tests, and as the top-level Context for incoming
-// requests.
-func Background() Context {
- return background
-}
-
-// TODO returns a non-nil, empty Context. Code should use context.TODO when
-// it's unclear which Context to use or it is not yet available (because the
-// surrounding function has not yet been extended to accept a Context
-// parameter).
-func TODO() Context {
- return todo
-}
-
-// A CancelFunc tells an operation to abandon its work.
-// A CancelFunc does not wait for the work to stop.
-// After the first call, subsequent calls to a CancelFunc do nothing.
-type CancelFunc func()
-
-// WithCancel returns a copy of parent with a new Done channel. The returned
-// context's Done channel is closed when the returned cancel function is called
-// or when the parent context's Done channel is closed, whichever happens first.
-//
-// Canceling this context releases resources associated with it, so code should
-// call cancel as soon as the operations running in this Context complete.
-func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
- c := newCancelCtx(parent)
- propagateCancel(parent, &c)
- return &c, func() { c.cancel(true, Canceled) }
-}
-
-// newCancelCtx returns an initialized cancelCtx.
-func newCancelCtx(parent Context) cancelCtx {
- return cancelCtx{Context: parent}
-}
-
-// propagateCancel arranges for child to be canceled when parent is.
-func propagateCancel(parent Context, child canceler) {
- if parent.Done() == nil {
- return // parent is never canceled
- }
- if p, ok := parentCancelCtx(parent); ok {
- p.mu.Lock()
- if p.err != nil {
- // parent has already been canceled
- child.cancel(false, p.err)
- } else {
- if p.children == nil {
- p.children = make(map[canceler]struct{})
- }
- p.children[child] = struct{}{}
- }
- p.mu.Unlock()
- } else {
- go func() {
- select {
- case <-parent.Done():
- child.cancel(false, parent.Err())
- case <-child.Done():
- }
- }()
- }
-}
-
-// parentCancelCtx follows a chain of parent references until it finds a
-// *cancelCtx. This function understands how each of the concrete types in this
-// package represents its parent.
-func parentCancelCtx(parent Context) (*cancelCtx, bool) {
- for {
- switch c := parent.(type) {
- case *cancelCtx:
- return c, true
- case *timerCtx:
- return &c.cancelCtx, true
- case *valueCtx:
- parent = c.Context
- default:
- return nil, false
- }
- }
-}
-
-// removeChild removes a context from its parent.
-func removeChild(parent Context, child canceler) {
- p, ok := parentCancelCtx(parent)
- if !ok {
- return
- }
- p.mu.Lock()
- if p.children != nil {
- delete(p.children, child)
- }
- p.mu.Unlock()
-}
-
-// A canceler is a context type that can be canceled directly. The
-// implementations are *cancelCtx and *timerCtx.
-type canceler interface {
- cancel(removeFromParent bool, err error)
- Done() <-chan struct{}
-}
-
-// closedchan is a reusable closed channel.
-var closedchan = make(chan struct{})
-
-func init() {
- close(closedchan)
-}
-
-// A cancelCtx can be canceled. When canceled, it also cancels any children
-// that implement canceler.
-type cancelCtx struct {
- Context
-
- mu sync.Mutex // protects following fields
- done chan struct{} // created lazily, closed by first cancel call
- children map[canceler]struct{} // set to nil by the first cancel call
- err error // set to non-nil by the first cancel call
-}
-
-func (c *cancelCtx) Done() <-chan struct{} {
- c.mu.Lock()
- if c.done == nil {
- c.done = make(chan struct{})
- }
- d := c.done
- c.mu.Unlock()
- return d
-}
-
-func (c *cancelCtx) Err() error {
- c.mu.Lock()
- err := c.err
- c.mu.Unlock()
- return err
-}
-
-func (c *cancelCtx) String() string {
- return fmt.Sprintf("%v.WithCancel", c.Context)
-}
-
-// cancel closes c.done, cancels each of c's children, and, if
-// removeFromParent is true, removes c from its parent's children.
-func (c *cancelCtx) cancel(removeFromParent bool, err error) {
- if err == nil {
- panic("context: internal error: missing cancel error")
- }
- c.mu.Lock()
- if c.err != nil {
- c.mu.Unlock()
- return // already canceled
- }
- c.err = err
- if c.done == nil {
- c.done = closedchan
- } else {
- close(c.done)
- }
- for child := range c.children {
- // NOTE: acquiring the child's lock while holding parent's lock.
- child.cancel(false, err)
- }
- c.children = nil
- c.mu.Unlock()
-
- if removeFromParent {
- removeChild(c.Context, c)
- }
-}
-
-// WithDeadline returns a copy of the parent context with the deadline adjusted
-// to be no later than d. If the parent's deadline is already earlier than d,
-// WithDeadline(parent, d) is semantically equivalent to parent. The returned
-// context's Done channel is closed when the deadline expires, when the returned
-// cancel function is called, or when the parent context's Done channel is
-// closed, whichever happens first.
-//
-// Canceling this context releases resources associated with it, so code should
-// call cancel as soon as the operations running in this Context complete.
-func WithDeadline(parent Context, d time.Time) (Context, CancelFunc) {
- if cur, ok := parent.Deadline(); ok && cur.Before(d) {
- // The current deadline is already sooner than the new one.
- return WithCancel(parent)
- }
- c := &timerCtx{
- cancelCtx: newCancelCtx(parent),
- deadline: d,
- }
- propagateCancel(parent, c)
- dur := time.Until(d)
- if dur <= 0 {
- c.cancel(true, DeadlineExceeded) // deadline has already passed
- return c, func() { c.cancel(false, Canceled) }
- }
- c.mu.Lock()
- defer c.mu.Unlock()
- if c.err == nil {
- c.timer = time.AfterFunc(dur, func() {
- c.cancel(true, DeadlineExceeded)
- })
- }
- return c, func() { c.cancel(true, Canceled) }
-}
-
-// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
-// implement Done and Err. It implements cancel by stopping its timer then
-// delegating to cancelCtx.cancel.
-type timerCtx struct {
- cancelCtx
- timer *time.Timer // Under cancelCtx.mu.
-
- deadline time.Time
-}
-
-func (c *timerCtx) Deadline() (deadline time.Time, ok bool) {
- return c.deadline, true
-}
-
-func (c *timerCtx) String() string {
- return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, time.Until(c.deadline))
-}
-
-func (c *timerCtx) cancel(removeFromParent bool, err error) {
- c.cancelCtx.cancel(false, err)
- if removeFromParent {
- // Remove this timerCtx from its parent cancelCtx's children.
- removeChild(c.cancelCtx.Context, c)
- }
- c.mu.Lock()
- if c.timer != nil {
- c.timer.Stop()
- c.timer = nil
- }
- c.mu.Unlock()
-}
-
-// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
-//
-// Canceling this context releases resources associated with it, so code should
-// call cancel as soon as the operations running in this Context complete:
-//
-// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
-// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
-// defer cancel() // releases resources if slowOperation completes before timeout elapses
-// return slowOperation(ctx)
-// }
-func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
- return WithDeadline(parent, time.Now().Add(timeout))
-}
-
-// WithValue returns a copy of parent in which the value associated with key is
-// val.
-//
-// Use context Values only for request-scoped data that transits processes and
-// APIs, not for passing optional parameters to functions.
-//
-// The provided key must be comparable and should not be of type
-// string or any other built-in type to avoid collisions between
-// packages using context. Users of WithValue should define their own
-// types for keys. To avoid allocating when assigning to an
-// interface{}, context keys often have concrete type
-// struct{}. Alternatively, exported context key variables' static
-// type should be a pointer or interface.
-func WithValue(parent Context, key, val interface{}) Context {
- if key == nil {
- panic("nil key")
- }
- if !reflect.TypeOf(key).Comparable() {
- panic("key is not comparable")
- }
- return &valueCtx{parent, key, val}
-}
-
-// A valueCtx carries a key-value pair. It implements Value for that key and
-// delegates all other calls to the embedded Context.
-type valueCtx struct {
- Context
- key, val interface{}
-}
-
-func (c *valueCtx) String() string {
- return fmt.Sprintf("%v.WithValue(%#v, %#v)", c.Context, c.key, c.val)
-}
-
-func (c *valueCtx) Value(key interface{}) interface{} {
- if c.key == key {
- return c.val
- }
- return c.Context.Value(key)
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/context/context_test.go b/internal/stdlib/testdata/v1.12.5/src/context/context_test.go
deleted file mode 100644
index 0b6ca74..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/context/context_test.go
+++ /dev/null
@@ -1,650 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context
-
-import (
- "fmt"
- "math/rand"
- "runtime"
- "strings"
- "sync"
- "time"
-)
-
-type testingT interface {
- Error(args ...interface{})
- Errorf(format string, args ...interface{})
- Fail()
- FailNow()
- Failed() bool
- Fatal(args ...interface{})
- Fatalf(format string, args ...interface{})
- Log(args ...interface{})
- Logf(format string, args ...interface{})
- Name() string
- Skip(args ...interface{})
- SkipNow()
- Skipf(format string, args ...interface{})
- Skipped() bool
-}
-
-// otherContext is a Context that's not one of the types defined in context.go.
-// This lets us test code paths that differ based on the underlying type of the
-// Context.
-type otherContext struct {
- Context
-}
-
-func XTestBackground(t testingT) {
- c := Background()
- if c == nil {
- t.Fatalf("Background returned nil")
- }
- select {
- case x := <-c.Done():
- t.Errorf("<-c.Done() == %v want nothing (it should block)", x)
- default:
- }
- if got, want := fmt.Sprint(c), "context.Background"; got != want {
- t.Errorf("Background().String() = %q want %q", got, want)
- }
-}
-
-func XTestTODO(t testingT) {
- c := TODO()
- if c == nil {
- t.Fatalf("TODO returned nil")
- }
- select {
- case x := <-c.Done():
- t.Errorf("<-c.Done() == %v want nothing (it should block)", x)
- default:
- }
- if got, want := fmt.Sprint(c), "context.TODO"; got != want {
- t.Errorf("TODO().String() = %q want %q", got, want)
- }
-}
-
-func XTestWithCancel(t testingT) {
- c1, cancel := WithCancel(Background())
-
- if got, want := fmt.Sprint(c1), "context.Background.WithCancel"; got != want {
- t.Errorf("c1.String() = %q want %q", got, want)
- }
-
- o := otherContext{c1}
- c2, _ := WithCancel(o)
- contexts := []Context{c1, o, c2}
-
- for i, c := range contexts {
- if d := c.Done(); d == nil {
- t.Errorf("c[%d].Done() == %v want non-nil", i, d)
- }
- if e := c.Err(); e != nil {
- t.Errorf("c[%d].Err() == %v want nil", i, e)
- }
-
- select {
- case x := <-c.Done():
- t.Errorf("<-c.Done() == %v want nothing (it should block)", x)
- default:
- }
- }
-
- cancel()
- time.Sleep(100 * time.Millisecond) // let cancelation propagate
-
- for i, c := range contexts {
- select {
- case <-c.Done():
- default:
- t.Errorf("<-c[%d].Done() blocked, but shouldn't have", i)
- }
- if e := c.Err(); e != Canceled {
- t.Errorf("c[%d].Err() == %v want %v", i, e, Canceled)
- }
- }
-}
-
-func contains(m map[canceler]struct{}, key canceler) bool {
- _, ret := m[key]
- return ret
-}
-
-func XTestParentFinishesChild(t testingT) {
- // Context tree:
- // parent -> cancelChild
- // parent -> valueChild -> timerChild
- parent, cancel := WithCancel(Background())
- cancelChild, stop := WithCancel(parent)
- defer stop()
- valueChild := WithValue(parent, "key", "value")
- timerChild, stop := WithTimeout(valueChild, 10000*time.Hour)
- defer stop()
-
- select {
- case x := <-parent.Done():
- t.Errorf("<-parent.Done() == %v want nothing (it should block)", x)
- case x := <-cancelChild.Done():
- t.Errorf("<-cancelChild.Done() == %v want nothing (it should block)", x)
- case x := <-timerChild.Done():
- t.Errorf("<-timerChild.Done() == %v want nothing (it should block)", x)
- case x := <-valueChild.Done():
- t.Errorf("<-valueChild.Done() == %v want nothing (it should block)", x)
- default:
- }
-
- // The parent's children should contain the two cancelable children.
- pc := parent.(*cancelCtx)
- cc := cancelChild.(*cancelCtx)
- test := timerChild.(*timerCtx)
- pc.mu.Lock()
- if len(pc.children) != 2 || !contains(pc.children, cc) || !contains(pc.children, test) {
- t.Errorf("bad linkage: pc.children = %v, want %v and %v",
- pc.children, cc, test)
- }
- pc.mu.Unlock()
-
- if p, ok := parentCancelCtx(cc.Context); !ok || p != pc {
- t.Errorf("bad linkage: parentCancelCtx(cancelChild.Context) = %v, %v want %v, true", p, ok, pc)
- }
- if p, ok := parentCancelCtx(test.Context); !ok || p != pc {
- t.Errorf("bad linkage: parentCancelCtx(timerChild.Context) = %v, %v want %v, true", p, ok, pc)
- }
-
- cancel()
-
- pc.mu.Lock()
- if len(pc.children) != 0 {
- t.Errorf("pc.cancel didn't clear pc.children = %v", pc.children)
- }
- pc.mu.Unlock()
-
- // parent and children should all be finished.
- check := func(ctx Context, name string) {
- select {
- case <-ctx.Done():
- default:
- t.Errorf("<-%s.Done() blocked, but shouldn't have", name)
- }
- if e := ctx.Err(); e != Canceled {
- t.Errorf("%s.Err() == %v want %v", name, e, Canceled)
- }
- }
- check(parent, "parent")
- check(cancelChild, "cancelChild")
- check(valueChild, "valueChild")
- check(timerChild, "timerChild")
-
- // WithCancel should return a canceled context on a canceled parent.
- precanceledChild := WithValue(parent, "key", "value")
- select {
- case <-precanceledChild.Done():
- default:
- t.Errorf("<-precanceledChild.Done() blocked, but shouldn't have")
- }
- if e := precanceledChild.Err(); e != Canceled {
- t.Errorf("precanceledChild.Err() == %v want %v", e, Canceled)
- }
-}
-
-func XTestChildFinishesFirst(t testingT) {
- cancelable, stop := WithCancel(Background())
- defer stop()
- for _, parent := range []Context{Background(), cancelable} {
- child, cancel := WithCancel(parent)
-
- select {
- case x := <-parent.Done():
- t.Errorf("<-parent.Done() == %v want nothing (it should block)", x)
- case x := <-child.Done():
- t.Errorf("<-child.Done() == %v want nothing (it should block)", x)
- default:
- }
-
- cc := child.(*cancelCtx)
- pc, pcok := parent.(*cancelCtx) // pcok == false when parent == Background()
- if p, ok := parentCancelCtx(cc.Context); ok != pcok || (ok && pc != p) {
- t.Errorf("bad linkage: parentCancelCtx(cc.Context) = %v, %v want %v, %v", p, ok, pc, pcok)
- }
-
- if pcok {
- pc.mu.Lock()
- if len(pc.children) != 1 || !contains(pc.children, cc) {
- t.Errorf("bad linkage: pc.children = %v, cc = %v", pc.children, cc)
- }
- pc.mu.Unlock()
- }
-
- cancel()
-
- if pcok {
- pc.mu.Lock()
- if len(pc.children) != 0 {
- t.Errorf("child's cancel didn't remove self from pc.children = %v", pc.children)
- }
- pc.mu.Unlock()
- }
-
- // child should be finished.
- select {
- case <-child.Done():
- default:
- t.Errorf("<-child.Done() blocked, but shouldn't have")
- }
- if e := child.Err(); e != Canceled {
- t.Errorf("child.Err() == %v want %v", e, Canceled)
- }
-
- // parent should not be finished.
- select {
- case x := <-parent.Done():
- t.Errorf("<-parent.Done() == %v want nothing (it should block)", x)
- default:
- }
- if e := parent.Err(); e != nil {
- t.Errorf("parent.Err() == %v want nil", e)
- }
- }
-}
-
-func testDeadline(c Context, name string, failAfter time.Duration, t testingT) {
- select {
- case <-time.After(failAfter):
- t.Fatalf("%s: context should have timed out", name)
- case <-c.Done():
- }
- if e := c.Err(); e != DeadlineExceeded {
- t.Errorf("%s: c.Err() == %v; want %v", name, e, DeadlineExceeded)
- }
-}
-
-func XTestDeadline(t testingT) {
- c, _ := WithDeadline(Background(), time.Now().Add(50*time.Millisecond))
- if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
- t.Errorf("c.String() = %q want prefix %q", got, prefix)
- }
- testDeadline(c, "WithDeadline", time.Second, t)
-
- c, _ = WithDeadline(Background(), time.Now().Add(50*time.Millisecond))
- o := otherContext{c}
- testDeadline(o, "WithDeadline+otherContext", time.Second, t)
-
- c, _ = WithDeadline(Background(), time.Now().Add(50*time.Millisecond))
- o = otherContext{c}
- c, _ = WithDeadline(o, time.Now().Add(4*time.Second))
- testDeadline(c, "WithDeadline+otherContext+WithDeadline", 2*time.Second, t)
-
- c, _ = WithDeadline(Background(), time.Now().Add(-time.Millisecond))
- testDeadline(c, "WithDeadline+inthepast", time.Second, t)
-
- c, _ = WithDeadline(Background(), time.Now())
- testDeadline(c, "WithDeadline+now", time.Second, t)
-}
-
-func XTestTimeout(t testingT) {
- c, _ := WithTimeout(Background(), 50*time.Millisecond)
- if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
- t.Errorf("c.String() = %q want prefix %q", got, prefix)
- }
- testDeadline(c, "WithTimeout", time.Second, t)
-
- c, _ = WithTimeout(Background(), 50*time.Millisecond)
- o := otherContext{c}
- testDeadline(o, "WithTimeout+otherContext", time.Second, t)
-
- c, _ = WithTimeout(Background(), 50*time.Millisecond)
- o = otherContext{c}
- c, _ = WithTimeout(o, 3*time.Second)
- testDeadline(c, "WithTimeout+otherContext+WithTimeout", 2*time.Second, t)
-}
-
-func XTestCanceledTimeout(t testingT) {
- c, _ := WithTimeout(Background(), time.Second)
- o := otherContext{c}
- c, cancel := WithTimeout(o, 2*time.Second)
- cancel()
- time.Sleep(100 * time.Millisecond) // let cancelation propagate
- select {
- case <-c.Done():
- default:
- t.Errorf("<-c.Done() blocked, but shouldn't have")
- }
- if e := c.Err(); e != Canceled {
- t.Errorf("c.Err() == %v want %v", e, Canceled)
- }
-}
-
-type key1 int
-type key2 int
-
-var k1 = key1(1)
-var k2 = key2(1) // same int as k1, different type
-var k3 = key2(3) // same type as k2, different int
-
-func XTestValues(t testingT) {
- check := func(c Context, nm, v1, v2, v3 string) {
- if v, ok := c.Value(k1).(string); ok == (len(v1) == 0) || v != v1 {
- t.Errorf(`%s.Value(k1).(string) = %q, %t want %q, %t`, nm, v, ok, v1, len(v1) != 0)
- }
- if v, ok := c.Value(k2).(string); ok == (len(v2) == 0) || v != v2 {
- t.Errorf(`%s.Value(k2).(string) = %q, %t want %q, %t`, nm, v, ok, v2, len(v2) != 0)
- }
- if v, ok := c.Value(k3).(string); ok == (len(v3) == 0) || v != v3 {
- t.Errorf(`%s.Value(k3).(string) = %q, %t want %q, %t`, nm, v, ok, v3, len(v3) != 0)
- }
- }
-
- c0 := Background()
- check(c0, "c0", "", "", "")
-
- c1 := WithValue(Background(), k1, "c1k1")
- check(c1, "c1", "c1k1", "", "")
-
- if got, want := fmt.Sprint(c1), `context.Background.WithValue(1, "c1k1")`; got != want {
- t.Errorf("c.String() = %q want %q", got, want)
- }
-
- c2 := WithValue(c1, k2, "c2k2")
- check(c2, "c2", "c1k1", "c2k2", "")
-
- c3 := WithValue(c2, k3, "c3k3")
- check(c3, "c2", "c1k1", "c2k2", "c3k3")
-
- c4 := WithValue(c3, k1, nil)
- check(c4, "c4", "", "c2k2", "c3k3")
-
- o0 := otherContext{Background()}
- check(o0, "o0", "", "", "")
-
- o1 := otherContext{WithValue(Background(), k1, "c1k1")}
- check(o1, "o1", "c1k1", "", "")
-
- o2 := WithValue(o1, k2, "o2k2")
- check(o2, "o2", "c1k1", "o2k2", "")
-
- o3 := otherContext{c4}
- check(o3, "o3", "", "c2k2", "c3k3")
-
- o4 := WithValue(o3, k3, nil)
- check(o4, "o4", "", "c2k2", "")
-}
-
-func XTestAllocs(t testingT, testingShort func() bool, testingAllocsPerRun func(int, func()) float64) {
- bg := Background()
- for _, test := range []struct {
- desc string
- f func()
- limit float64
- gccgoLimit float64
- }{
- {
- desc: "Background()",
- f: func() { Background() },
- limit: 0,
- gccgoLimit: 0,
- },
- {
- desc: fmt.Sprintf("WithValue(bg, %v, nil)", k1),
- f: func() {
- c := WithValue(bg, k1, nil)
- c.Value(k1)
- },
- limit: 3,
- gccgoLimit: 3,
- },
- {
- desc: "WithTimeout(bg, 15*time.Millisecond)",
- f: func() {
- c, _ := WithTimeout(bg, 15*time.Millisecond)
- <-c.Done()
- },
- limit: 8,
- gccgoLimit: 15,
- },
- {
- desc: "WithCancel(bg)",
- f: func() {
- c, cancel := WithCancel(bg)
- cancel()
- <-c.Done()
- },
- limit: 5,
- gccgoLimit: 8,
- },
- {
- desc: "WithTimeout(bg, 5*time.Millisecond)",
- f: func() {
- c, cancel := WithTimeout(bg, 5*time.Millisecond)
- cancel()
- <-c.Done()
- },
- limit: 8,
- gccgoLimit: 25,
- },
- } {
- limit := test.limit
- if runtime.Compiler == "gccgo" {
- // gccgo does not yet do escape analysis.
- // TODO(iant): Remove this when gccgo does do escape analysis.
- limit = test.gccgoLimit
- }
- numRuns := 100
- if testingShort() {
- numRuns = 10
- }
- if n := testingAllocsPerRun(numRuns, test.f); n > limit {
- t.Errorf("%s allocs = %f want %d", test.desc, n, int(limit))
- }
- }
-}
-
-func XTestSimultaneousCancels(t testingT) {
- root, cancel := WithCancel(Background())
- m := map[Context]CancelFunc{root: cancel}
- q := []Context{root}
- // Create a tree of contexts.
- for len(q) != 0 && len(m) < 100 {
- parent := q[0]
- q = q[1:]
- for i := 0; i < 4; i++ {
- ctx, cancel := WithCancel(parent)
- m[ctx] = cancel
- q = append(q, ctx)
- }
- }
- // Start all the cancels in a random order.
- var wg sync.WaitGroup
- wg.Add(len(m))
- for _, cancel := range m {
- go func(cancel CancelFunc) {
- cancel()
- wg.Done()
- }(cancel)
- }
- // Wait on all the contexts in a random order.
- for ctx := range m {
- select {
- case <-ctx.Done():
- case <-time.After(1 * time.Second):
- buf := make([]byte, 10<<10)
- n := runtime.Stack(buf, true)
- t.Fatalf("timed out waiting for <-ctx.Done(); stacks:\n%s", buf[:n])
- }
- }
- // Wait for all the cancel functions to return.
- done := make(chan struct{})
- go func() {
- wg.Wait()
- close(done)
- }()
- select {
- case <-done:
- case <-time.After(1 * time.Second):
- buf := make([]byte, 10<<10)
- n := runtime.Stack(buf, true)
- t.Fatalf("timed out waiting for cancel functions; stacks:\n%s", buf[:n])
- }
-}
-
-func XTestInterlockedCancels(t testingT) {
- parent, cancelParent := WithCancel(Background())
- child, cancelChild := WithCancel(parent)
- go func() {
- parent.Done()
- cancelChild()
- }()
- cancelParent()
- select {
- case <-child.Done():
- case <-time.After(1 * time.Second):
- buf := make([]byte, 10<<10)
- n := runtime.Stack(buf, true)
- t.Fatalf("timed out waiting for child.Done(); stacks:\n%s", buf[:n])
- }
-}
-
-func XTestLayersCancel(t testingT) {
- testLayers(t, time.Now().UnixNano(), false)
-}
-
-func XTestLayersTimeout(t testingT) {
- testLayers(t, time.Now().UnixNano(), true)
-}
-
-func testLayers(t testingT, seed int64, testTimeout bool) {
- rand.Seed(seed)
- errorf := func(format string, a ...interface{}) {
- t.Errorf(fmt.Sprintf("seed=%d: %s", seed, format), a...)
- }
- const (
- timeout = 200 * time.Millisecond
- minLayers = 30
- )
- type value int
- var (
- vals []*value
- cancels []CancelFunc
- numTimers int
- ctx = Background()
- )
- for i := 0; i < minLayers || numTimers == 0 || len(cancels) == 0 || len(vals) == 0; i++ {
- switch rand.Intn(3) {
- case 0:
- v := new(value)
- ctx = WithValue(ctx, v, v)
- vals = append(vals, v)
- case 1:
- var cancel CancelFunc
- ctx, cancel = WithCancel(ctx)
- cancels = append(cancels, cancel)
- case 2:
- var cancel CancelFunc
- ctx, cancel = WithTimeout(ctx, timeout)
- cancels = append(cancels, cancel)
- numTimers++
- }
- }
- checkValues := func(when string) {
- for _, key := range vals {
- if val := ctx.Value(key).(*value); key != val {
- errorf("%s: ctx.Value(%p) = %p want %p", when, key, val, key)
- }
- }
- }
- select {
- case <-ctx.Done():
- errorf("ctx should not be canceled yet")
- default:
- }
- if s, prefix := fmt.Sprint(ctx), "context.Background."; !strings.HasPrefix(s, prefix) {
- t.Errorf("ctx.String() = %q want prefix %q", s, prefix)
- }
- t.Log(ctx)
- checkValues("before cancel")
- if testTimeout {
- select {
- case <-ctx.Done():
- case <-time.After(timeout + time.Second):
- errorf("ctx should have timed out")
- }
- checkValues("after timeout")
- } else {
- cancel := cancels[rand.Intn(len(cancels))]
- cancel()
- select {
- case <-ctx.Done():
- default:
- errorf("ctx should be canceled")
- }
- checkValues("after cancel")
- }
-}
-
-func XTestCancelRemoves(t testingT) {
- checkChildren := func(when string, ctx Context, want int) {
- if got := len(ctx.(*cancelCtx).children); got != want {
- t.Errorf("%s: context has %d children, want %d", when, got, want)
- }
- }
-
- ctx, _ := WithCancel(Background())
- checkChildren("after creation", ctx, 0)
- _, cancel := WithCancel(ctx)
- checkChildren("with WithCancel child ", ctx, 1)
- cancel()
- checkChildren("after canceling WithCancel child", ctx, 0)
-
- ctx, _ = WithCancel(Background())
- checkChildren("after creation", ctx, 0)
- _, cancel = WithTimeout(ctx, 60*time.Minute)
- checkChildren("with WithTimeout child ", ctx, 1)
- cancel()
- checkChildren("after canceling WithTimeout child", ctx, 0)
-}
-
-func XTestWithCancelCanceledParent(t testingT) {
- parent, pcancel := WithCancel(Background())
- pcancel()
-
- c, _ := WithCancel(parent)
- select {
- case <-c.Done():
- case <-time.After(5 * time.Second):
- t.Fatal("timeout waiting for Done")
- }
- if got, want := c.Err(), Canceled; got != want {
- t.Errorf("child not cancelled; got = %v, want = %v", got, want)
- }
-}
-
-func XTestWithValueChecksKey(t testingT) {
- panicVal := recoveredValue(func() { WithValue(Background(), []byte("foo"), "bar") })
- if panicVal == nil {
- t.Error("expected panic")
- }
- panicVal = recoveredValue(func() { WithValue(Background(), nil, "bar") })
- if got, want := fmt.Sprint(panicVal), "nil key"; got != want {
- t.Errorf("panic = %q; want %q", got, want)
- }
-}
-
-func recoveredValue(fn func()) (v interface{}) {
- defer func() { v = recover() }()
- fn()
- return
-}
-
-func XTestDeadlineExceededSupportsTimeout(t testingT) {
- i, ok := DeadlineExceeded.(interface {
- Timeout() bool
- })
- if !ok {
- t.Fatal("DeadlineExceeded does not support Timeout interface")
- }
- if !i.Timeout() {
- t.Fatal("wrong value for timeout")
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/context/example_test.go b/internal/stdlib/testdata/v1.12.5/src/context/example_test.go
deleted file mode 100644
index 2b28b57..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/context/example_test.go
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context_test
-
-import (
- "context"
- "fmt"
- "time"
-)
-
-// This example demonstrates the use of a cancelable context to prevent a
-// goroutine leak. By the end of the example function, the goroutine started
-// by gen will return without leaking.
-func ExampleWithCancel() {
- // gen generates integers in a separate goroutine and
- // sends them to the returned channel.
- // The callers of gen need to cancel the context once
- // they are done consuming generated integers not to leak
- // the internal goroutine started by gen.
- gen := func(ctx context.Context) <-chan int {
- dst := make(chan int)
- n := 1
- go func() {
- for {
- select {
- case <-ctx.Done():
- return // returning not to leak the goroutine
- case dst <- n:
- n++
- }
- }
- }()
- return dst
- }
-
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel() // cancel when we are finished consuming integers
-
- for n := range gen(ctx) {
- fmt.Println(n)
- if n == 5 {
- break
- }
- }
- // Output:
- // 1
- // 2
- // 3
- // 4
- // 5
-}
-
-// This example passes a context with an arbitrary deadline to tell a blocking
-// function that it should abandon its work as soon as it gets to it.
-func ExampleWithDeadline() {
- d := time.Now().Add(50 * time.Millisecond)
- ctx, cancel := context.WithDeadline(context.Background(), d)
-
- // Even though ctx will be expired, it is good practice to call its
- // cancelation function in any case. Failure to do so may keep the
- // context and its parent alive longer than necessary.
- defer cancel()
-
- select {
- case <-time.After(1 * time.Second):
- fmt.Println("overslept")
- case <-ctx.Done():
- fmt.Println(ctx.Err())
- }
-
- // Output:
- // context deadline exceeded
-}
-
-// This example passes a context with a timeout to tell a blocking function that
-// it should abandon its work after the timeout elapses.
-func ExampleWithTimeout() {
- // Pass a context with a timeout to tell a blocking function that it
- // should abandon its work after the timeout elapses.
- ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
- defer cancel()
-
- select {
- case <-time.After(1 * time.Second):
- fmt.Println("overslept")
- case <-ctx.Done():
- fmt.Println(ctx.Err()) // prints "context deadline exceeded"
- }
-
- // Output:
- // context deadline exceeded
-}
-
-// This example demonstrates how a value can be passed to the context
-// and also how to retrieve it if it exists.
-func ExampleWithValue() {
- type favContextKey string
-
- f := func(ctx context.Context, k favContextKey) {
- if v := ctx.Value(k); v != nil {
- fmt.Println("found value:", v)
- return
- }
- fmt.Println("key not found:", k)
- }
-
- k := favContextKey("language")
- ctx := context.WithValue(context.Background(), k, "Go")
-
- f(ctx, k)
- f(ctx, favContextKey("color"))
-
- // Output:
- // found value: Go
- // key not found: color
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/context/net_test.go b/internal/stdlib/testdata/v1.12.5/src/context/net_test.go
deleted file mode 100644
index a007689..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/context/net_test.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context_test
-
-import (
- "context"
- "net"
- "testing"
-)
-
-func TestDeadlineExceededIsNetError(t *testing.T) {
- err, ok := context.DeadlineExceeded.(net.Error)
- if !ok {
- t.Fatal("DeadlineExceeded does not implement net.Error")
- }
- if !err.Timeout() || !err.Temporary() {
- t.Fatalf("Timeout() = %v, Temporary() = %v, want true, true", err.Timeout(), err.Temporary())
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/context/x_test.go b/internal/stdlib/testdata/v1.12.5/src/context/x_test.go
deleted file mode 100644
index d14b6f1..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/context/x_test.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context_test
-
-import (
- . "context"
- "testing"
-)
-
-func TestBackground(t *testing.T) { XTestBackground(t) }
-func TestTODO(t *testing.T) { XTestTODO(t) }
-func TestWithCancel(t *testing.T) { XTestWithCancel(t) }
-func TestParentFinishesChild(t *testing.T) { XTestParentFinishesChild(t) }
-func TestChildFinishesFirst(t *testing.T) { XTestChildFinishesFirst(t) }
-func TestDeadline(t *testing.T) { XTestDeadline(t) }
-func TestTimeout(t *testing.T) { XTestTimeout(t) }
-func TestCanceledTimeout(t *testing.T) { XTestCanceledTimeout(t) }
-func TestValues(t *testing.T) { XTestValues(t) }
-func TestAllocs(t *testing.T) { XTestAllocs(t, testing.Short, testing.AllocsPerRun) }
-func TestSimultaneousCancels(t *testing.T) { XTestSimultaneousCancels(t) }
-func TestInterlockedCancels(t *testing.T) { XTestInterlockedCancels(t) }
-func TestLayersCancel(t *testing.T) { XTestLayersCancel(t) }
-func TestLayersTimeout(t *testing.T) { XTestLayersTimeout(t) }
-func TestCancelRemoves(t *testing.T) { XTestCancelRemoves(t) }
-func TestWithCancelCanceledParent(t *testing.T) { XTestWithCancelCanceledParent(t) }
-func TestWithValueChecksKey(t *testing.T) { XTestWithValueChecksKey(t) }
-func TestDeadlineExceededSupportsTimeout(t *testing.T) { XTestDeadlineExceededSupportsTimeout(t) }
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/bench_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/bench_test.go
deleted file mode 100644
index 6a72e77..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/bench_test.go
+++ /dev/null
@@ -1,363 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Large data benchmark.
-// The JSON data is a summary of agl's changes in the
-// go, webkit, and chromium open source projects.
-// We benchmark converting between the JSON form
-// and in-memory data structures.
-
-package json
-
-import (
- "bytes"
- "compress/gzip"
- "fmt"
- "internal/testenv"
- "io"
- "os"
- "reflect"
- "runtime"
- "strings"
- "sync"
- "testing"
-)
-
-type codeResponse struct {
- Tree *codeNode `json:"tree"`
- Username string `json:"username"`
-}
-
-type codeNode struct {
- Name string `json:"name"`
- Kids []*codeNode `json:"kids"`
- CLWeight float64 `json:"cl_weight"`
- Touches int `json:"touches"`
- MinT int64 `json:"min_t"`
- MaxT int64 `json:"max_t"`
- MeanT int64 `json:"mean_t"`
-}
-
-var codeJSON []byte
-var codeStruct codeResponse
-
-func codeInit() {
- f, err := os.Open("testdata/code.json.gz")
- if err != nil {
- panic(err)
- }
- defer f.Close()
- gz, err := gzip.NewReader(f)
- if err != nil {
- panic(err)
- }
- data, err := io.ReadAll(gz)
- if err != nil {
- panic(err)
- }
-
- codeJSON = data
-
- if err := Unmarshal(codeJSON, &codeStruct); err != nil {
- panic("unmarshal code.json: " + err.Error())
- }
-
- if data, err = Marshal(&codeStruct); err != nil {
- panic("marshal code.json: " + err.Error())
- }
-
- if !bytes.Equal(data, codeJSON) {
- println("different lengths", len(data), len(codeJSON))
- for i := 0; i < len(data) && i < len(codeJSON); i++ {
- if data[i] != codeJSON[i] {
- println("re-marshal: changed at byte", i)
- println("orig: ", string(codeJSON[i-10:i+10]))
- println("new: ", string(data[i-10:i+10]))
- break
- }
- }
- panic("re-marshal code.json: different result")
- }
-}
-
-func BenchmarkCodeEncoder(b *testing.B) {
- if codeJSON == nil {
- b.StopTimer()
- codeInit()
- b.StartTimer()
- }
- b.RunParallel(func(pb *testing.PB) {
- enc := NewEncoder(io.Discard)
- for pb.Next() {
- if err := enc.Encode(&codeStruct); err != nil {
- b.Fatal("Encode:", err)
- }
- }
- })
- b.SetBytes(int64(len(codeJSON)))
-}
-
-func BenchmarkCodeMarshal(b *testing.B) {
- if codeJSON == nil {
- b.StopTimer()
- codeInit()
- b.StartTimer()
- }
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- if _, err := Marshal(&codeStruct); err != nil {
- b.Fatal("Marshal:", err)
- }
- }
- })
- b.SetBytes(int64(len(codeJSON)))
-}
-
-func benchMarshalBytes(n int) func(*testing.B) {
- sample := []byte("hello world")
- // Use a struct pointer, to avoid an allocation when passing it as an
- // interface parameter to Marshal.
- v := &struct {
- Bytes []byte
- }{
- bytes.Repeat(sample, (n/len(sample))+1)[:n],
- }
- return func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- if _, err := Marshal(v); err != nil {
- b.Fatal("Marshal:", err)
- }
- }
- }
-}
-
-func BenchmarkMarshalBytes(b *testing.B) {
- // 32 fits within encodeState.scratch.
- b.Run("32", benchMarshalBytes(32))
- // 256 doesn't fit in encodeState.scratch, but is small enough to
- // allocate and avoid the slower base64.NewEncoder.
- b.Run("256", benchMarshalBytes(256))
- // 4096 is large enough that we want to avoid allocating for it.
- b.Run("4096", benchMarshalBytes(4096))
-}
-
-func BenchmarkCodeDecoder(b *testing.B) {
- if codeJSON == nil {
- b.StopTimer()
- codeInit()
- b.StartTimer()
- }
- b.RunParallel(func(pb *testing.PB) {
- var buf bytes.Buffer
- dec := NewDecoder(&buf)
- var r codeResponse
- for pb.Next() {
- buf.Write(codeJSON)
- // hide EOF
- buf.WriteByte('\n')
- buf.WriteByte('\n')
- buf.WriteByte('\n')
- if err := dec.Decode(&r); err != nil {
- b.Fatal("Decode:", err)
- }
- }
- })
- b.SetBytes(int64(len(codeJSON)))
-}
-
-func BenchmarkUnicodeDecoder(b *testing.B) {
- j := []byte(`"\uD83D\uDE01"`)
- b.SetBytes(int64(len(j)))
- r := bytes.NewReader(j)
- dec := NewDecoder(r)
- var out string
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- if err := dec.Decode(&out); err != nil {
- b.Fatal("Decode:", err)
- }
- r.Seek(0, 0)
- }
-}
-
-func BenchmarkDecoderStream(b *testing.B) {
- b.StopTimer()
- var buf bytes.Buffer
- dec := NewDecoder(&buf)
- buf.WriteString(`"` + strings.Repeat("x", 1000000) + `"` + "\n\n\n")
- var x interface{}
- if err := dec.Decode(&x); err != nil {
- b.Fatal("Decode:", err)
- }
- ones := strings.Repeat(" 1\n", 300000) + "\n\n\n"
- b.StartTimer()
- for i := 0; i < b.N; i++ {
- if i%300000 == 0 {
- buf.WriteString(ones)
- }
- x = nil
- if err := dec.Decode(&x); err != nil || x != 1.0 {
- b.Fatalf("Decode: %v after %d", err, i)
- }
- }
-}
-
-func BenchmarkCodeUnmarshal(b *testing.B) {
- if codeJSON == nil {
- b.StopTimer()
- codeInit()
- b.StartTimer()
- }
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- var r codeResponse
- if err := Unmarshal(codeJSON, &r); err != nil {
- b.Fatal("Unmarshal:", err)
- }
- }
- })
- b.SetBytes(int64(len(codeJSON)))
-}
-
-func BenchmarkCodeUnmarshalReuse(b *testing.B) {
- if codeJSON == nil {
- b.StopTimer()
- codeInit()
- b.StartTimer()
- }
- b.RunParallel(func(pb *testing.PB) {
- var r codeResponse
- for pb.Next() {
- if err := Unmarshal(codeJSON, &r); err != nil {
- b.Fatal("Unmarshal:", err)
- }
- }
- })
- // TODO(bcmills): Is there a missing b.SetBytes here?
-}
-
-func BenchmarkUnmarshalString(b *testing.B) {
- data := []byte(`"hello, world"`)
- b.RunParallel(func(pb *testing.PB) {
- var s string
- for pb.Next() {
- if err := Unmarshal(data, &s); err != nil {
- b.Fatal("Unmarshal:", err)
- }
- }
- })
-}
-
-func BenchmarkUnmarshalFloat64(b *testing.B) {
- data := []byte(`3.14`)
- b.RunParallel(func(pb *testing.PB) {
- var f float64
- for pb.Next() {
- if err := Unmarshal(data, &f); err != nil {
- b.Fatal("Unmarshal:", err)
- }
- }
- })
-}
-
-func BenchmarkUnmarshalInt64(b *testing.B) {
- data := []byte(`3`)
- b.RunParallel(func(pb *testing.PB) {
- var x int64
- for pb.Next() {
- if err := Unmarshal(data, &x); err != nil {
- b.Fatal("Unmarshal:", err)
- }
- }
- })
-}
-
-func BenchmarkIssue10335(b *testing.B) {
- b.ReportAllocs()
- j := []byte(`{"a":{ }}`)
- b.RunParallel(func(pb *testing.PB) {
- var s struct{}
- for pb.Next() {
- if err := Unmarshal(j, &s); err != nil {
- b.Fatal(err)
- }
- }
- })
-}
-
-func BenchmarkUnmapped(b *testing.B) {
- b.ReportAllocs()
- j := []byte(`{"s": "hello", "y": 2, "o": {"x": 0}, "a": [1, 99, {"x": 1}]}`)
- b.RunParallel(func(pb *testing.PB) {
- var s struct{}
- for pb.Next() {
- if err := Unmarshal(j, &s); err != nil {
- b.Fatal(err)
- }
- }
- })
-}
-
-func BenchmarkTypeFieldsCache(b *testing.B) {
- var maxTypes int = 1e6
- if testenv.Builder() != "" {
- maxTypes = 1e3 // restrict cache sizes on builders
- }
-
- // Dynamically generate many new types.
- types := make([]reflect.Type, maxTypes)
- fs := []reflect.StructField{{
- Type: reflect.TypeOf(""),
- Index: []int{0},
- }}
- for i := range types {
- fs[0].Name = fmt.Sprintf("TypeFieldsCache%d", i)
- types[i] = reflect.StructOf(fs)
- }
-
- // clearClear clears the cache. Other JSON operations, must not be running.
- clearCache := func() {
- fieldCache = sync.Map{}
- }
-
- // MissTypes tests the performance of repeated cache misses.
- // This measures the time to rebuild a cache of size nt.
- for nt := 1; nt <= maxTypes; nt *= 10 {
- ts := types[:nt]
- b.Run(fmt.Sprintf("MissTypes%d", nt), func(b *testing.B) {
- nc := runtime.GOMAXPROCS(0)
- for i := 0; i < b.N; i++ {
- clearCache()
- var wg sync.WaitGroup
- for j := 0; j < nc; j++ {
- wg.Add(1)
- go func(j int) {
- for _, t := range ts[(j*len(ts))/nc : ((j+1)*len(ts))/nc] {
- cachedTypeFields(t)
- }
- wg.Done()
- }(j)
- }
- wg.Wait()
- }
- })
- }
-
- // HitTypes tests the performance of repeated cache hits.
- // This measures the average time of each cache lookup.
- for nt := 1; nt <= maxTypes; nt *= 10 {
- // Pre-warm a cache of size nt.
- clearCache()
- for _, t := range types[:nt] {
- cachedTypeFields(t)
- }
- b.Run(fmt.Sprintf("HitTypes%d", nt), func(b *testing.B) {
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- cachedTypeFields(types[0])
- }
- })
- })
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/decode.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/decode.go
deleted file mode 100644
index 731553d..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/decode.go
+++ /dev/null
@@ -1,1292 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Represents JSON data structure using native Go types: booleans, floats,
-// strings, arrays, and maps.
-
-package json
-
-import (
- "bytes"
- "encoding"
- "encoding/base64"
- "fmt"
- "reflect"
- "strconv"
- "unicode"
- "unicode/utf16"
- "unicode/utf8"
-)
-
-// Unmarshal parses the JSON-encoded data and stores the result
-// in the value pointed to by v. If v is nil or not a pointer,
-// Unmarshal returns an InvalidUnmarshalError.
-//
-// Unmarshal uses the inverse of the encodings that
-// Marshal uses, allocating maps, slices, and pointers as necessary,
-// with the following additional rules:
-//
-// To unmarshal JSON into a pointer, Unmarshal first handles the case of
-// the JSON being the JSON literal null. In that case, Unmarshal sets
-// the pointer to nil. Otherwise, Unmarshal unmarshals the JSON into
-// the value pointed at by the pointer. If the pointer is nil, Unmarshal
-// allocates a new value for it to point to.
-//
-// To unmarshal JSON into a value implementing the Unmarshaler interface,
-// Unmarshal calls that value's UnmarshalJSON method, including
-// when the input is a JSON null.
-// Otherwise, if the value implements encoding.TextUnmarshaler
-// and the input is a JSON quoted string, Unmarshal calls that value's
-// UnmarshalText method with the unquoted form of the string.
-//
-// To unmarshal JSON into a struct, Unmarshal matches incoming object
-// keys to the keys used by Marshal (either the struct field name or its tag),
-// preferring an exact match but also accepting a case-insensitive match. By
-// default, object keys which don't have a corresponding struct field are
-// ignored (see Decoder.DisallowUnknownFields for an alternative).
-//
-// To unmarshal JSON into an interface value,
-// Unmarshal stores one of these in the interface value:
-//
-// bool, for JSON booleans
-// float64, for JSON numbers
-// string, for JSON strings
-// []interface{}, for JSON arrays
-// map[string]interface{}, for JSON objects
-// nil for JSON null
-//
-// To unmarshal a JSON array into a slice, Unmarshal resets the slice length
-// to zero and then appends each element to the slice.
-// As a special case, to unmarshal an empty JSON array into a slice,
-// Unmarshal replaces the slice with a new empty slice.
-//
-// To unmarshal a JSON array into a Go array, Unmarshal decodes
-// JSON array elements into corresponding Go array elements.
-// If the Go array is smaller than the JSON array,
-// the additional JSON array elements are discarded.
-// If the JSON array is smaller than the Go array,
-// the additional Go array elements are set to zero values.
-//
-// To unmarshal a JSON object into a map, Unmarshal first establishes a map to
-// use. If the map is nil, Unmarshal allocates a new map. Otherwise Unmarshal
-// reuses the existing map, keeping existing entries. Unmarshal then stores
-// key-value pairs from the JSON object into the map. The map's key type must
-// either be a string, an integer, or implement encoding.TextUnmarshaler.
-//
-// If a JSON value is not appropriate for a given target type,
-// or if a JSON number overflows the target type, Unmarshal
-// skips that field and completes the unmarshaling as best it can.
-// If no more serious errors are encountered, Unmarshal returns
-// an UnmarshalTypeError describing the earliest such error. In any
-// case, it's not guaranteed that all the remaining fields following
-// the problematic one will be unmarshaled into the target object.
-//
-// The JSON null value unmarshals into an interface, map, pointer, or slice
-// by setting that Go value to nil. Because null is often used in JSON to mean
-// ``not present,'' unmarshaling a JSON null into any other Go type has no effect
-// on the value and produces no error.
-//
-// When unmarshaling quoted strings, invalid UTF-8 or
-// invalid UTF-16 surrogate pairs are not treated as an error.
-// Instead, they are replaced by the Unicode replacement
-// character U+FFFD.
-//
-func Unmarshal(data []byte, v interface{}) error {
- // Check for well-formedness.
- // Avoids filling out half a data structure
- // before discovering a JSON syntax error.
- var d decodeState
- err := checkValid(data, &d.scan)
- if err != nil {
- return err
- }
-
- d.init(data)
- return d.unmarshal(v)
-}
-
-// Unmarshaler is the interface implemented by types
-// that can unmarshal a JSON description of themselves.
-// The input can be assumed to be a valid encoding of
-// a JSON value. UnmarshalJSON must copy the JSON data
-// if it wishes to retain the data after returning.
-//
-// By convention, to approximate the behavior of Unmarshal itself,
-// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op.
-type Unmarshaler interface {
- UnmarshalJSON([]byte) error
-}
-
-// An UnmarshalTypeError describes a JSON value that was
-// not appropriate for a value of a specific Go type.
-type UnmarshalTypeError struct {
- Value string // description of JSON value - "bool", "array", "number -5"
- Type reflect.Type // type of Go value it could not be assigned to
- Offset int64 // error occurred after reading Offset bytes
- Struct string // name of the struct type containing the field
- Field string // name of the field holding the Go value
-}
-
-func (e *UnmarshalTypeError) Error() string {
- if e.Struct != "" || e.Field != "" {
- return "json: cannot unmarshal " + e.Value + " into Go struct field " + e.Struct + "." + e.Field + " of type " + e.Type.String()
- }
- return "json: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String()
-}
-
-// An UnmarshalFieldError describes a JSON object key that
-// led to an unexported (and therefore unwritable) struct field.
-//
-// Deprecated: No longer used; kept for compatibility.
-type UnmarshalFieldError struct {
- Key string
- Type reflect.Type
- Field reflect.StructField
-}
-
-func (e *UnmarshalFieldError) Error() string {
- return "json: cannot unmarshal object key " + strconv.Quote(e.Key) + " into unexported field " + e.Field.Name + " of type " + e.Type.String()
-}
-
-// An InvalidUnmarshalError describes an invalid argument passed to Unmarshal.
-// (The argument to Unmarshal must be a non-nil pointer.)
-type InvalidUnmarshalError struct {
- Type reflect.Type
-}
-
-func (e *InvalidUnmarshalError) Error() string {
- if e.Type == nil {
- return "json: Unmarshal(nil)"
- }
-
- if e.Type.Kind() != reflect.Ptr {
- return "json: Unmarshal(non-pointer " + e.Type.String() + ")"
- }
- return "json: Unmarshal(nil " + e.Type.String() + ")"
-}
-
-func (d *decodeState) unmarshal(v interface{}) error {
- rv := reflect.ValueOf(v)
- if rv.Kind() != reflect.Ptr || rv.IsNil() {
- return &InvalidUnmarshalError{reflect.TypeOf(v)}
- }
-
- d.scan.reset()
- d.scanWhile(scanSkipSpace)
- // We decode rv not rv.Elem because the Unmarshaler interface
- // test must be applied at the top level of the value.
- err := d.value(rv)
- if err != nil {
- return d.addErrorContext(err)
- }
- return d.savedError
-}
-
-// A Number represents a JSON number literal.
-type Number string
-
-// String returns the literal text of the number.
-func (n Number) String() string { return string(n) }
-
-// Float64 returns the number as a float64.
-func (n Number) Float64() (float64, error) {
- return strconv.ParseFloat(string(n), 64)
-}
-
-// Int64 returns the number as an int64.
-func (n Number) Int64() (int64, error) {
- return strconv.ParseInt(string(n), 10, 64)
-}
-
-// isValidNumber reports whether s is a valid JSON number literal.
-func isValidNumber(s string) bool {
- // This function implements the JSON numbers grammar.
- // See https://tools.ietf.org/html/rfc7159#section-6
- // and https://json.org/number.gif
-
- if s == "" {
- return false
- }
-
- // Optional -
- if s[0] == '-' {
- s = s[1:]
- if s == "" {
- return false
- }
- }
-
- // Digits
- switch {
- default:
- return false
-
- case s[0] == '0':
- s = s[1:]
-
- case '1' <= s[0] && s[0] <= '9':
- s = s[1:]
- for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
- s = s[1:]
- }
- }
-
- // . followed by 1 or more digits.
- if len(s) >= 2 && s[0] == '.' && '0' <= s[1] && s[1] <= '9' {
- s = s[2:]
- for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
- s = s[1:]
- }
- }
-
- // e or E followed by an optional - or + and
- // 1 or more digits.
- if len(s) >= 2 && (s[0] == 'e' || s[0] == 'E') {
- s = s[1:]
- if s[0] == '+' || s[0] == '-' {
- s = s[1:]
- if s == "" {
- return false
- }
- }
- for len(s) > 0 && '0' <= s[0] && s[0] <= '9' {
- s = s[1:]
- }
- }
-
- // Make sure we are at the end.
- return s == ""
-}
-
-// decodeState represents the state while decoding a JSON value.
-type decodeState struct {
- data []byte
- off int // next read offset in data
- opcode int // last read result
- scan scanner
- errorContext struct { // provides context for type errors
- Struct reflect.Type
- Field string
- }
- savedError error
- useNumber bool
- disallowUnknownFields bool
-}
-
-// readIndex returns the position of the last byte read.
-func (d *decodeState) readIndex() int {
- return d.off - 1
-}
-
-// phasePanicMsg is used as a panic message when we end up with something that
-// shouldn't happen. It can indicate a bug in the JSON decoder, or that
-// something is editing the data slice while the decoder executes.
-const phasePanicMsg = "JSON decoder out of sync - data changing underfoot?"
-
-func (d *decodeState) init(data []byte) *decodeState {
- d.data = data
- d.off = 0
- d.savedError = nil
- d.errorContext.Struct = nil
- d.errorContext.Field = ""
- return d
-}
-
-// saveError saves the first err it is called with,
-// for reporting at the end of the unmarshal.
-func (d *decodeState) saveError(err error) {
- if d.savedError == nil {
- d.savedError = d.addErrorContext(err)
- }
-}
-
-// addErrorContext returns a new error enhanced with information from d.errorContext
-func (d *decodeState) addErrorContext(err error) error {
- if d.errorContext.Struct != nil || d.errorContext.Field != "" {
- switch err := err.(type) {
- case *UnmarshalTypeError:
- err.Struct = d.errorContext.Struct.Name()
- err.Field = d.errorContext.Field
- return err
- }
- }
- return err
-}
-
-// skip scans to the end of what was started.
-func (d *decodeState) skip() {
- s, data, i := &d.scan, d.data, d.off
- depth := len(s.parseState)
- for {
- op := s.step(s, data[i])
- i++
- if len(s.parseState) < depth {
- d.off = i
- d.opcode = op
- return
- }
- }
-}
-
-// scanNext processes the byte at d.data[d.off].
-func (d *decodeState) scanNext() {
- if d.off < len(d.data) {
- d.opcode = d.scan.step(&d.scan, d.data[d.off])
- d.off++
- } else {
- d.opcode = d.scan.eof()
- d.off = len(d.data) + 1 // mark processed EOF with len+1
- }
-}
-
-// scanWhile processes bytes in d.data[d.off:] until it
-// receives a scan code not equal to op.
-func (d *decodeState) scanWhile(op int) {
- s, data, i := &d.scan, d.data, d.off
- for i < len(data) {
- newOp := s.step(s, data[i])
- i++
- if newOp != op {
- d.opcode = newOp
- d.off = i
- return
- }
- }
-
- d.off = len(data) + 1 // mark processed EOF with len+1
- d.opcode = d.scan.eof()
-}
-
-// value consumes a JSON value from d.data[d.off-1:], decoding into v, and
-// reads the following byte ahead. If v is invalid, the value is discarded.
-// The first byte of the value has been read already.
-func (d *decodeState) value(v reflect.Value) error {
- switch d.opcode {
- default:
- panic(phasePanicMsg)
-
- case scanBeginArray:
- if v.IsValid() {
- if err := d.array(v); err != nil {
- return err
- }
- } else {
- d.skip()
- }
- d.scanNext()
-
- case scanBeginObject:
- if v.IsValid() {
- if err := d.object(v); err != nil {
- return err
- }
- } else {
- d.skip()
- }
- d.scanNext()
-
- case scanBeginLiteral:
- // All bytes inside literal return scanContinue op code.
- start := d.readIndex()
- d.scanWhile(scanContinue)
-
- if v.IsValid() {
- if err := d.literalStore(d.data[start:d.readIndex()], v, false); err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-type unquotedValue struct{}
-
-// valueQuoted is like value but decodes a
-// quoted string literal or literal null into an interface value.
-// If it finds anything other than a quoted string literal or null,
-// valueQuoted returns unquotedValue{}.
-func (d *decodeState) valueQuoted() interface{} {
- switch d.opcode {
- default:
- panic(phasePanicMsg)
-
- case scanBeginArray, scanBeginObject:
- d.skip()
- d.scanNext()
-
- case scanBeginLiteral:
- v := d.literalInterface()
- switch v.(type) {
- case nil, string:
- return v
- }
- }
- return unquotedValue{}
-}
-
-// indirect walks down v allocating pointers as needed,
-// until it gets to a non-pointer.
-// if it encounters an Unmarshaler, indirect stops and returns that.
-// if decodingNull is true, indirect stops at the last pointer so it can be set to nil.
-func indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnmarshaler, reflect.Value) {
- // Issue #24153 indicates that it is generally not a guaranteed property
- // that you may round-trip a reflect.Value by calling Value.Addr().Elem()
- // and expect the value to still be settable for values derived from
- // unexported embedded struct fields.
- //
- // The logic below effectively does this when it first addresses the value
- // (to satisfy possible pointer methods) and continues to dereference
- // subsequent pointers as necessary.
- //
- // After the first round-trip, we set v back to the original value to
- // preserve the original RW flags contained in reflect.Value.
- v0 := v
- haveAddr := false
-
- // If v is a named type and is addressable,
- // start with its address, so that if the type has pointer methods,
- // we find them.
- if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
- haveAddr = true
- v = v.Addr()
- }
- for {
- // Load value from interface, but only if the result will be
- // usefully addressable.
- if v.Kind() == reflect.Interface && !v.IsNil() {
- e := v.Elem()
- if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) {
- haveAddr = false
- v = e
- continue
- }
- }
-
- if v.Kind() != reflect.Ptr {
- break
- }
-
- if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() {
- break
- }
- if v.IsNil() {
- v.Set(reflect.New(v.Type().Elem()))
- }
- if v.Type().NumMethod() > 0 && v.CanInterface() {
- if u, ok := v.Interface().(Unmarshaler); ok {
- return u, nil, reflect.Value{}
- }
- if !decodingNull {
- if u, ok := v.Interface().(encoding.TextUnmarshaler); ok {
- return nil, u, reflect.Value{}
- }
- }
- }
-
- if haveAddr {
- v = v0 // restore original value after round-trip Value.Addr().Elem()
- haveAddr = false
- } else {
- v = v.Elem()
- }
- }
- return nil, nil, v
-}
-
-// array consumes an array from d.data[d.off-1:], decoding into v.
-// The first byte of the array ('[') has been read already.
-func (d *decodeState) array(v reflect.Value) error {
- // Check for unmarshaler.
- u, ut, pv := indirect(v, false)
- if u != nil {
- start := d.readIndex()
- d.skip()
- return u.UnmarshalJSON(d.data[start:d.off])
- }
- if ut != nil {
- d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type(), Offset: int64(d.off)})
- d.skip()
- return nil
- }
- v = pv
-
- // Check type of target.
- switch v.Kind() {
- case reflect.Interface:
- if v.NumMethod() == 0 {
- // Decoding into nil interface? Switch to non-reflect code.
- ai := d.arrayInterface()
- v.Set(reflect.ValueOf(ai))
- return nil
- }
- // Otherwise it's invalid.
- fallthrough
- default:
- d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type(), Offset: int64(d.off)})
- d.skip()
- return nil
- case reflect.Array, reflect.Slice:
- break
- }
-
- i := 0
- for {
- // Look ahead for ] - can only happen on first iteration.
- d.scanWhile(scanSkipSpace)
- if d.opcode == scanEndArray {
- break
- }
-
- // Get element of array, growing if necessary.
- if v.Kind() == reflect.Slice {
- // Grow slice if necessary
- if i >= v.Cap() {
- newcap := v.Cap() + v.Cap()/2
- if newcap < 4 {
- newcap = 4
- }
- newv := reflect.MakeSlice(v.Type(), v.Len(), newcap)
- reflect.Copy(newv, v)
- v.Set(newv)
- }
- if i >= v.Len() {
- v.SetLen(i + 1)
- }
- }
-
- if i < v.Len() {
- // Decode into element.
- if err := d.value(v.Index(i)); err != nil {
- return err
- }
- } else {
- // Ran out of fixed array: skip.
- if err := d.value(reflect.Value{}); err != nil {
- return err
- }
- }
- i++
-
- // Next token must be , or ].
- if d.opcode == scanSkipSpace {
- d.scanWhile(scanSkipSpace)
- }
- if d.opcode == scanEndArray {
- break
- }
- if d.opcode != scanArrayValue {
- panic(phasePanicMsg)
- }
- }
-
- if i < v.Len() {
- if v.Kind() == reflect.Array {
- // Array. Zero the rest.
- z := reflect.Zero(v.Type().Elem())
- for ; i < v.Len(); i++ {
- v.Index(i).Set(z)
- }
- } else {
- v.SetLen(i)
- }
- }
- if i == 0 && v.Kind() == reflect.Slice {
- v.Set(reflect.MakeSlice(v.Type(), 0, 0))
- }
- return nil
-}
-
-var nullLiteral = []byte("null")
-var textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
-
-// object consumes an object from d.data[d.off-1:], decoding into v.
-// The first byte ('{') of the object has been read already.
-func (d *decodeState) object(v reflect.Value) error {
- // Check for unmarshaler.
- u, ut, pv := indirect(v, false)
- if u != nil {
- start := d.readIndex()
- d.skip()
- return u.UnmarshalJSON(d.data[start:d.off])
- }
- if ut != nil {
- d.saveError(&UnmarshalTypeError{Value: "object", Type: v.Type(), Offset: int64(d.off)})
- d.skip()
- return nil
- }
- v = pv
- t := v.Type()
-
- // Decoding into nil interface? Switch to non-reflect code.
- if v.Kind() == reflect.Interface && v.NumMethod() == 0 {
- oi := d.objectInterface()
- v.Set(reflect.ValueOf(oi))
- return nil
- }
-
- var fields []field
-
- // Check type of target:
- // struct or
- // map[T1]T2 where T1 is string, an integer type,
- // or an encoding.TextUnmarshaler
- switch v.Kind() {
- case reflect.Map:
- // Map key must either have string kind, have an integer kind,
- // or be an encoding.TextUnmarshaler.
- switch t.Key().Kind() {
- case reflect.String,
- reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
- reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- default:
- if !reflect.PtrTo(t.Key()).Implements(textUnmarshalerType) {
- d.saveError(&UnmarshalTypeError{Value: "object", Type: t, Offset: int64(d.off)})
- d.skip()
- return nil
- }
- }
- if v.IsNil() {
- v.Set(reflect.MakeMap(t))
- }
- case reflect.Struct:
- fields = cachedTypeFields(t)
- // ok
- default:
- d.saveError(&UnmarshalTypeError{Value: "object", Type: t, Offset: int64(d.off)})
- d.skip()
- return nil
- }
-
- var mapElem reflect.Value
- originalErrorContext := d.errorContext
-
- for {
- // Read opening " of string key or closing }.
- d.scanWhile(scanSkipSpace)
- if d.opcode == scanEndObject {
- // closing } - can only happen on first iteration.
- break
- }
- if d.opcode != scanBeginLiteral {
- panic(phasePanicMsg)
- }
-
- // Read key.
- start := d.readIndex()
- d.scanWhile(scanContinue)
- item := d.data[start:d.readIndex()]
- key, ok := unquoteBytes(item)
- if !ok {
- panic(phasePanicMsg)
- }
-
- // Figure out field corresponding to key.
- var subv reflect.Value
- destring := false // whether the value is wrapped in a string to be decoded first
-
- if v.Kind() == reflect.Map {
- elemType := t.Elem()
- if !mapElem.IsValid() {
- mapElem = reflect.New(elemType).Elem()
- } else {
- mapElem.Set(reflect.Zero(elemType))
- }
- subv = mapElem
- } else {
- var f *field
- for i := range fields {
- ff := &fields[i]
- if bytes.Equal(ff.nameBytes, key) {
- f = ff
- break
- }
- if f == nil && ff.equalFold(ff.nameBytes, key) {
- f = ff
- }
- }
- if f != nil {
- subv = v
- destring = f.quoted
- for _, i := range f.index {
- if subv.Kind() == reflect.Ptr {
- if subv.IsNil() {
- // If a struct embeds a pointer to an unexported type,
- // it is not possible to set a newly allocated value
- // since the field is unexported.
- //
- // See https://golang.org/issue/21357
- if !subv.CanSet() {
- d.saveError(fmt.Errorf("json: cannot set embedded pointer to unexported struct: %v", subv.Type().Elem()))
- // Invalidate subv to ensure d.value(subv) skips over
- // the JSON value without assigning it to subv.
- subv = reflect.Value{}
- destring = false
- break
- }
- subv.Set(reflect.New(subv.Type().Elem()))
- }
- subv = subv.Elem()
- }
- subv = subv.Field(i)
- }
- d.errorContext.Field = f.name
- d.errorContext.Struct = t
- } else if d.disallowUnknownFields {
- d.saveError(fmt.Errorf("json: unknown field %q", key))
- }
- }
-
- // Read : before value.
- if d.opcode == scanSkipSpace {
- d.scanWhile(scanSkipSpace)
- }
- if d.opcode != scanObjectKey {
- panic(phasePanicMsg)
- }
- d.scanWhile(scanSkipSpace)
-
- if destring {
- switch qv := d.valueQuoted().(type) {
- case nil:
- if err := d.literalStore(nullLiteral, subv, false); err != nil {
- return err
- }
- case string:
- if err := d.literalStore([]byte(qv), subv, true); err != nil {
- return err
- }
- default:
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal unquoted value into %v", subv.Type()))
- }
- } else {
- if err := d.value(subv); err != nil {
- return err
- }
- }
-
- // Write value back to map;
- // if using struct, subv points into struct already.
- if v.Kind() == reflect.Map {
- kt := t.Key()
- var kv reflect.Value
- switch {
- case kt.Kind() == reflect.String:
- kv = reflect.ValueOf(key).Convert(kt)
- case reflect.PtrTo(kt).Implements(textUnmarshalerType):
- kv = reflect.New(kt)
- if err := d.literalStore(item, kv, true); err != nil {
- return err
- }
- kv = kv.Elem()
- default:
- switch kt.Kind() {
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- s := string(key)
- n, err := strconv.ParseInt(s, 10, 64)
- if err != nil || reflect.Zero(kt).OverflowInt(n) {
- d.saveError(&UnmarshalTypeError{Value: "number " + s, Type: kt, Offset: int64(start + 1)})
- break
- }
- kv = reflect.ValueOf(n).Convert(kt)
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- s := string(key)
- n, err := strconv.ParseUint(s, 10, 64)
- if err != nil || reflect.Zero(kt).OverflowUint(n) {
- d.saveError(&UnmarshalTypeError{Value: "number " + s, Type: kt, Offset: int64(start + 1)})
- break
- }
- kv = reflect.ValueOf(n).Convert(kt)
- default:
- panic("json: Unexpected key type") // should never occur
- }
- }
- if kv.IsValid() {
- v.SetMapIndex(kv, subv)
- }
- }
-
- // Next token must be , or }.
- if d.opcode == scanSkipSpace {
- d.scanWhile(scanSkipSpace)
- }
- if d.opcode == scanEndObject {
- break
- }
- if d.opcode != scanObjectValue {
- panic(phasePanicMsg)
- }
-
- d.errorContext = originalErrorContext
- }
- return nil
-}
-
-// convertNumber converts the number literal s to a float64 or a Number
-// depending on the setting of d.useNumber.
-func (d *decodeState) convertNumber(s string) (interface{}, error) {
- if d.useNumber {
- return Number(s), nil
- }
- f, err := strconv.ParseFloat(s, 64)
- if err != nil {
- return nil, &UnmarshalTypeError{Value: "number " + s, Type: reflect.TypeOf(0.0), Offset: int64(d.off)}
- }
- return f, nil
-}
-
-var numberType = reflect.TypeOf(Number(""))
-
-// literalStore decodes a literal stored in item into v.
-//
-// fromQuoted indicates whether this literal came from unwrapping a
-// string from the ",string" struct tag option. this is used only to
-// produce more helpful error messages.
-func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool) error {
- // Check for unmarshaler.
- if len(item) == 0 {
- //Empty string given
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
- return nil
- }
- isNull := item[0] == 'n' // null
- u, ut, pv := indirect(v, isNull)
- if u != nil {
- return u.UnmarshalJSON(item)
- }
- if ut != nil {
- if item[0] != '"' {
- if fromQuoted {
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
- return nil
- }
- val := "number"
- switch item[0] {
- case 'n':
- val = "null"
- case 't', 'f':
- val = "bool"
- }
- d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())})
- return nil
- }
- s, ok := unquoteBytes(item)
- if !ok {
- if fromQuoted {
- return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())
- }
- panic(phasePanicMsg)
- }
- return ut.UnmarshalText(s)
- }
-
- v = pv
-
- switch c := item[0]; c {
- case 'n': // null
- // The main parser checks that only true and false can reach here,
- // but if this was a quoted string input, it could be anything.
- if fromQuoted && string(item) != "null" {
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
- break
- }
- switch v.Kind() {
- case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
- v.Set(reflect.Zero(v.Type()))
- // otherwise, ignore null for primitives/string
- }
- case 't', 'f': // true, false
- value := item[0] == 't'
- // The main parser checks that only true and false can reach here,
- // but if this was a quoted string input, it could be anything.
- if fromQuoted && string(item) != "true" && string(item) != "false" {
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
- break
- }
- switch v.Kind() {
- default:
- if fromQuoted {
- d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()))
- } else {
- d.saveError(&UnmarshalTypeError{Value: "bool", Type: v.Type(), Offset: int64(d.readIndex())})
- }
- case reflect.Bool:
- v.SetBool(value)
- case reflect.Interface:
- if v.NumMethod() == 0 {
- v.Set(reflect.ValueOf(value))
- } else {
- d.saveError(&UnmarshalTypeError{Value: "bool", Type: v.Type(), Offset: int64(d.readIndex())})
- }
- }
-
- case '"': // string
- s, ok := unquoteBytes(item)
- if !ok {
- if fromQuoted {
- return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())
- }
- panic(phasePanicMsg)
- }
- switch v.Kind() {
- default:
- d.saveError(&UnmarshalTypeError{Value: "string", Type: v.Type(), Offset: int64(d.readIndex())})
- case reflect.Slice:
- if v.Type().Elem().Kind() != reflect.Uint8 {
- d.saveError(&UnmarshalTypeError{Value: "string", Type: v.Type(), Offset: int64(d.readIndex())})
- break
- }
- b := make([]byte, base64.StdEncoding.DecodedLen(len(s)))
- n, err := base64.StdEncoding.Decode(b, s)
- if err != nil {
- d.saveError(err)
- break
- }
- v.SetBytes(b[:n])
- case reflect.String:
- v.SetString(string(s))
- case reflect.Interface:
- if v.NumMethod() == 0 {
- v.Set(reflect.ValueOf(string(s)))
- } else {
- d.saveError(&UnmarshalTypeError{Value: "string", Type: v.Type(), Offset: int64(d.readIndex())})
- }
- }
-
- default: // number
- if c != '-' && (c < '0' || c > '9') {
- if fromQuoted {
- return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())
- }
- panic(phasePanicMsg)
- }
- s := string(item)
- switch v.Kind() {
- default:
- if v.Kind() == reflect.String && v.Type() == numberType {
- v.SetString(s)
- if !isValidNumber(s) {
- return fmt.Errorf("json: invalid number literal, trying to unmarshal %q into Number", item)
- }
- break
- }
- if fromQuoted {
- return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())
- }
- d.saveError(&UnmarshalTypeError{Value: "number", Type: v.Type(), Offset: int64(d.readIndex())})
- case reflect.Interface:
- n, err := d.convertNumber(s)
- if err != nil {
- d.saveError(err)
- break
- }
- if v.NumMethod() != 0 {
- d.saveError(&UnmarshalTypeError{Value: "number", Type: v.Type(), Offset: int64(d.readIndex())})
- break
- }
- v.Set(reflect.ValueOf(n))
-
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- n, err := strconv.ParseInt(s, 10, 64)
- if err != nil || v.OverflowInt(n) {
- d.saveError(&UnmarshalTypeError{Value: "number " + s, Type: v.Type(), Offset: int64(d.readIndex())})
- break
- }
- v.SetInt(n)
-
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- n, err := strconv.ParseUint(s, 10, 64)
- if err != nil || v.OverflowUint(n) {
- d.saveError(&UnmarshalTypeError{Value: "number " + s, Type: v.Type(), Offset: int64(d.readIndex())})
- break
- }
- v.SetUint(n)
-
- case reflect.Float32, reflect.Float64:
- n, err := strconv.ParseFloat(s, v.Type().Bits())
- if err != nil || v.OverflowFloat(n) {
- d.saveError(&UnmarshalTypeError{Value: "number " + s, Type: v.Type(), Offset: int64(d.readIndex())})
- break
- }
- v.SetFloat(n)
- }
- }
- return nil
-}
-
-// The xxxInterface routines build up a value to be stored
-// in an empty interface. They are not strictly necessary,
-// but they avoid the weight of reflection in this common case.
-
-// valueInterface is like value but returns interface{}
-func (d *decodeState) valueInterface() (val interface{}) {
- switch d.opcode {
- default:
- panic(phasePanicMsg)
- case scanBeginArray:
- val = d.arrayInterface()
- d.scanNext()
- case scanBeginObject:
- val = d.objectInterface()
- d.scanNext()
- case scanBeginLiteral:
- val = d.literalInterface()
- }
- return
-}
-
-// arrayInterface is like array but returns []interface{}.
-func (d *decodeState) arrayInterface() []interface{} {
- var v = make([]interface{}, 0)
- for {
- // Look ahead for ] - can only happen on first iteration.
- d.scanWhile(scanSkipSpace)
- if d.opcode == scanEndArray {
- break
- }
-
- v = append(v, d.valueInterface())
-
- // Next token must be , or ].
- if d.opcode == scanSkipSpace {
- d.scanWhile(scanSkipSpace)
- }
- if d.opcode == scanEndArray {
- break
- }
- if d.opcode != scanArrayValue {
- panic(phasePanicMsg)
- }
- }
- return v
-}
-
-// objectInterface is like object but returns map[string]interface{}.
-func (d *decodeState) objectInterface() map[string]interface{} {
- m := make(map[string]interface{})
- for {
- // Read opening " of string key or closing }.
- d.scanWhile(scanSkipSpace)
- if d.opcode == scanEndObject {
- // closing } - can only happen on first iteration.
- break
- }
- if d.opcode != scanBeginLiteral {
- panic(phasePanicMsg)
- }
-
- // Read string key.
- start := d.readIndex()
- d.scanWhile(scanContinue)
- item := d.data[start:d.readIndex()]
- key, ok := unquote(item)
- if !ok {
- panic(phasePanicMsg)
- }
-
- // Read : before value.
- if d.opcode == scanSkipSpace {
- d.scanWhile(scanSkipSpace)
- }
- if d.opcode != scanObjectKey {
- panic(phasePanicMsg)
- }
- d.scanWhile(scanSkipSpace)
-
- // Read value.
- m[key] = d.valueInterface()
-
- // Next token must be , or }.
- if d.opcode == scanSkipSpace {
- d.scanWhile(scanSkipSpace)
- }
- if d.opcode == scanEndObject {
- break
- }
- if d.opcode != scanObjectValue {
- panic(phasePanicMsg)
- }
- }
- return m
-}
-
-// literalInterface consumes and returns a literal from d.data[d.off-1:] and
-// it reads the following byte ahead. The first byte of the literal has been
-// read already (that's how the caller knows it's a literal).
-func (d *decodeState) literalInterface() interface{} {
- // All bytes inside literal return scanContinue op code.
- start := d.readIndex()
- d.scanWhile(scanContinue)
-
- item := d.data[start:d.readIndex()]
-
- switch c := item[0]; c {
- case 'n': // null
- return nil
-
- case 't', 'f': // true, false
- return c == 't'
-
- case '"': // string
- s, ok := unquote(item)
- if !ok {
- panic(phasePanicMsg)
- }
- return s
-
- default: // number
- if c != '-' && (c < '0' || c > '9') {
- panic(phasePanicMsg)
- }
- n, err := d.convertNumber(string(item))
- if err != nil {
- d.saveError(err)
- }
- return n
- }
-}
-
-// getu4 decodes \uXXXX from the beginning of s, returning the hex value,
-// or it returns -1.
-func getu4(s []byte) rune {
- if len(s) < 6 || s[0] != '\\' || s[1] != 'u' {
- return -1
- }
- var r rune
- for _, c := range s[2:6] {
- switch {
- case '0' <= c && c <= '9':
- c = c - '0'
- case 'a' <= c && c <= 'f':
- c = c - 'a' + 10
- case 'A' <= c && c <= 'F':
- c = c - 'A' + 10
- default:
- return -1
- }
- r = r*16 + rune(c)
- }
- return r
-}
-
-// unquote converts a quoted JSON string literal s into an actual string t.
-// The rules are different than for Go, so cannot use strconv.Unquote.
-func unquote(s []byte) (t string, ok bool) {
- s, ok = unquoteBytes(s)
- t = string(s)
- return
-}
-
-func unquoteBytes(s []byte) (t []byte, ok bool) {
- if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' {
- return
- }
- s = s[1 : len(s)-1]
-
- // Check for unusual characters. If there are none,
- // then no unquoting is needed, so return a slice of the
- // original bytes.
- r := 0
- for r < len(s) {
- c := s[r]
- if c == '\\' || c == '"' || c < ' ' {
- break
- }
- if c < utf8.RuneSelf {
- r++
- continue
- }
- rr, size := utf8.DecodeRune(s[r:])
- if rr == utf8.RuneError && size == 1 {
- break
- }
- r += size
- }
- if r == len(s) {
- return s, true
- }
-
- b := make([]byte, len(s)+2*utf8.UTFMax)
- w := copy(b, s[0:r])
- for r < len(s) {
- // Out of room? Can only happen if s is full of
- // malformed UTF-8 and we're replacing each
- // byte with RuneError.
- if w >= len(b)-2*utf8.UTFMax {
- nb := make([]byte, (len(b)+utf8.UTFMax)*2)
- copy(nb, b[0:w])
- b = nb
- }
- switch c := s[r]; {
- case c == '\\':
- r++
- if r >= len(s) {
- return
- }
- switch s[r] {
- default:
- return
- case '"', '\\', '/', '\'':
- b[w] = s[r]
- r++
- w++
- case 'b':
- b[w] = '\b'
- r++
- w++
- case 'f':
- b[w] = '\f'
- r++
- w++
- case 'n':
- b[w] = '\n'
- r++
- w++
- case 'r':
- b[w] = '\r'
- r++
- w++
- case 't':
- b[w] = '\t'
- r++
- w++
- case 'u':
- r--
- rr := getu4(s[r:])
- if rr < 0 {
- return
- }
- r += 6
- if utf16.IsSurrogate(rr) {
- rr1 := getu4(s[r:])
- if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar {
- // A valid pair; consume.
- r += 6
- w += utf8.EncodeRune(b[w:], dec)
- break
- }
- // Invalid surrogate; fall back to replacement rune.
- rr = unicode.ReplacementChar
- }
- w += utf8.EncodeRune(b[w:], rr)
- }
-
- // Quote, control characters are invalid.
- case c == '"', c < ' ':
- return
-
- // ASCII
- case c < utf8.RuneSelf:
- b[w] = c
- r++
- w++
-
- // Coerce to well-formed UTF-8.
- default:
- rr, size := utf8.DecodeRune(s[r:])
- r += size
- w += utf8.EncodeRune(b[w:], rr)
- }
- }
- return b[0:w], true
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/decode_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/decode_test.go
deleted file mode 100644
index 5443260..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/decode_test.go
+++ /dev/null
@@ -1,2294 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "encoding"
- "errors"
- "fmt"
- "image"
- "math"
- "math/big"
- "net"
- "reflect"
- "strconv"
- "strings"
- "testing"
- "time"
-)
-
-type T struct {
- X string
- Y int
- Z int `json:"-"`
-}
-
-type U struct {
- Alphabet string `json:"alpha"`
-}
-
-type V struct {
- F1 interface{}
- F2 int32
- F3 Number
- F4 *VOuter
-}
-
-type VOuter struct {
- V V
-}
-
-type W struct {
- S SS
-}
-
-type SS string
-
-func (*SS) UnmarshalJSON(data []byte) error {
- return &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(SS(""))}
-}
-
-// ifaceNumAsFloat64/ifaceNumAsNumber are used to test unmarshaling with and
-// without UseNumber
-var ifaceNumAsFloat64 = map[string]interface{}{
- "k1": float64(1),
- "k2": "s",
- "k3": []interface{}{float64(1), float64(2.0), float64(3e-3)},
- "k4": map[string]interface{}{"kk1": "s", "kk2": float64(2)},
-}
-
-var ifaceNumAsNumber = map[string]interface{}{
- "k1": Number("1"),
- "k2": "s",
- "k3": []interface{}{Number("1"), Number("2.0"), Number("3e-3")},
- "k4": map[string]interface{}{"kk1": "s", "kk2": Number("2")},
-}
-
-type tx struct {
- x int
-}
-
-type u8 uint8
-
-// A type that can unmarshal itself.
-
-type unmarshaler struct {
- T bool
-}
-
-func (u *unmarshaler) UnmarshalJSON(b []byte) error {
- *u = unmarshaler{true} // All we need to see that UnmarshalJSON is called.
- return nil
-}
-
-type ustruct struct {
- M unmarshaler
-}
-
-type unmarshalerText struct {
- A, B string
-}
-
-// needed for re-marshaling tests
-func (u unmarshalerText) MarshalText() ([]byte, error) {
- return []byte(u.A + ":" + u.B), nil
-}
-
-func (u *unmarshalerText) UnmarshalText(b []byte) error {
- pos := bytes.IndexByte(b, ':')
- if pos == -1 {
- return errors.New("missing separator")
- }
- u.A, u.B = string(b[:pos]), string(b[pos+1:])
- return nil
-}
-
-var _ encoding.TextUnmarshaler = (*unmarshalerText)(nil)
-
-type ustructText struct {
- M unmarshalerText
-}
-
-// u8marshal is an integer type that can marshal/unmarshal itself.
-type u8marshal uint8
-
-func (u8 u8marshal) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf("u%d", u8)), nil
-}
-
-var errMissingU8Prefix = errors.New("missing 'u' prefix")
-
-func (u8 *u8marshal) UnmarshalText(b []byte) error {
- if !bytes.HasPrefix(b, []byte{'u'}) {
- return errMissingU8Prefix
- }
- n, err := strconv.Atoi(string(b[1:]))
- if err != nil {
- return err
- }
- *u8 = u8marshal(n)
- return nil
-}
-
-var _ encoding.TextUnmarshaler = (*u8marshal)(nil)
-
-var (
- um0, um1 unmarshaler // target2 of unmarshaling
- ump = &um1
- umtrue = unmarshaler{true}
- umslice = []unmarshaler{{true}}
- umslicep = new([]unmarshaler)
- umstruct = ustruct{unmarshaler{true}}
-
- um0T, um1T unmarshalerText // target2 of unmarshaling
- umpType = &um1T
- umtrueXY = unmarshalerText{"x", "y"}
- umsliceXY = []unmarshalerText{{"x", "y"}}
- umslicepType = new([]unmarshalerText)
- umstructType = new(ustructText)
- umstructXY = ustructText{unmarshalerText{"x", "y"}}
-
- ummapType = map[unmarshalerText]bool{}
- ummapXY = map[unmarshalerText]bool{{"x", "y"}: true}
-)
-
-// Test data structures for anonymous fields.
-
-type Point struct {
- Z int
-}
-
-type Top struct {
- Level0 int
- Embed0
- *Embed0a
- *Embed0b `json:"e,omitempty"` // treated as named
- Embed0c `json:"-"` // ignored
- Loop
- Embed0p // has Point with X, Y, used
- Embed0q // has Point with Z, used
- embed // contains exported field
-}
-
-type Embed0 struct {
- Level1a int // overridden by Embed0a's Level1a with json tag
- Level1b int // used because Embed0a's Level1b is renamed
- Level1c int // used because Embed0a's Level1c is ignored
- Level1d int // annihilated by Embed0a's Level1d
- Level1e int `json:"x"` // annihilated by Embed0a.Level1e
-}
-
-type Embed0a struct {
- Level1a int `json:"Level1a,omitempty"`
- Level1b int `json:"LEVEL1B,omitempty"`
- Level1c int `json:"-"`
- Level1d int // annihilated by Embed0's Level1d
- Level1f int `json:"x"` // annihilated by Embed0's Level1e
-}
-
-type Embed0b Embed0
-
-type Embed0c Embed0
-
-type Embed0p struct {
- image.Point
-}
-
-type Embed0q struct {
- Point
-}
-
-type embed struct {
- Q int
-}
-
-type Loop struct {
- Loop1 int `json:",omitempty"`
- Loop2 int `json:",omitempty"`
- *Loop
-}
-
-// From reflect test:
-// The X in S6 and S7 annihilate, but they also block the X in S8.S9.
-type S5 struct {
- S6
- S7
- S8
-}
-
-type S6 struct {
- X int
-}
-
-type S7 S6
-
-type S8 struct {
- S9
-}
-
-type S9 struct {
- X int
- Y int
-}
-
-// From reflect test:
-// The X in S11.S6 and S12.S6 annihilate, but they also block the X in S13.S8.S9.
-type S10 struct {
- S11
- S12
- S13
-}
-
-type S11 struct {
- S6
-}
-
-type S12 struct {
- S6
-}
-
-type S13 struct {
- S8
-}
-
-type Ambig struct {
- // Given "hello", the first match should win.
- First int `json:"HELLO"`
- Second int `json:"Hello"`
-}
-
-type XYZ struct {
- X interface{}
- Y interface{}
- Z interface{}
-}
-
-type unexportedWithMethods struct{}
-
-func (unexportedWithMethods) F() {}
-
-func sliceAddr(x []int) *[]int { return &x }
-func mapAddr(x map[string]int) *map[string]int { return &x }
-
-type byteWithMarshalJSON byte
-
-func (b byteWithMarshalJSON) MarshalJSON() ([]byte, error) {
- return []byte(fmt.Sprintf(`"Z%.2x"`, byte(b))), nil
-}
-
-func (b *byteWithMarshalJSON) UnmarshalJSON(data []byte) error {
- if len(data) != 5 || data[0] != '"' || data[1] != 'Z' || data[4] != '"' {
- return fmt.Errorf("bad quoted string")
- }
- i, err := strconv.ParseInt(string(data[2:4]), 16, 8)
- if err != nil {
- return fmt.Errorf("bad hex")
- }
- *b = byteWithMarshalJSON(i)
- return nil
-}
-
-type byteWithPtrMarshalJSON byte
-
-func (b *byteWithPtrMarshalJSON) MarshalJSON() ([]byte, error) {
- return byteWithMarshalJSON(*b).MarshalJSON()
-}
-
-func (b *byteWithPtrMarshalJSON) UnmarshalJSON(data []byte) error {
- return (*byteWithMarshalJSON)(b).UnmarshalJSON(data)
-}
-
-type byteWithMarshalText byte
-
-func (b byteWithMarshalText) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf(`Z%.2x`, byte(b))), nil
-}
-
-func (b *byteWithMarshalText) UnmarshalText(data []byte) error {
- if len(data) != 3 || data[0] != 'Z' {
- return fmt.Errorf("bad quoted string")
- }
- i, err := strconv.ParseInt(string(data[1:3]), 16, 8)
- if err != nil {
- return fmt.Errorf("bad hex")
- }
- *b = byteWithMarshalText(i)
- return nil
-}
-
-type byteWithPtrMarshalText byte
-
-func (b *byteWithPtrMarshalText) MarshalText() ([]byte, error) {
- return byteWithMarshalText(*b).MarshalText()
-}
-
-func (b *byteWithPtrMarshalText) UnmarshalText(data []byte) error {
- return (*byteWithMarshalText)(b).UnmarshalText(data)
-}
-
-type intWithMarshalJSON int
-
-func (b intWithMarshalJSON) MarshalJSON() ([]byte, error) {
- return []byte(fmt.Sprintf(`"Z%.2x"`, int(b))), nil
-}
-
-func (b *intWithMarshalJSON) UnmarshalJSON(data []byte) error {
- if len(data) != 5 || data[0] != '"' || data[1] != 'Z' || data[4] != '"' {
- return fmt.Errorf("bad quoted string")
- }
- i, err := strconv.ParseInt(string(data[2:4]), 16, 8)
- if err != nil {
- return fmt.Errorf("bad hex")
- }
- *b = intWithMarshalJSON(i)
- return nil
-}
-
-type intWithPtrMarshalJSON int
-
-func (b *intWithPtrMarshalJSON) MarshalJSON() ([]byte, error) {
- return intWithMarshalJSON(*b).MarshalJSON()
-}
-
-func (b *intWithPtrMarshalJSON) UnmarshalJSON(data []byte) error {
- return (*intWithMarshalJSON)(b).UnmarshalJSON(data)
-}
-
-type intWithMarshalText int
-
-func (b intWithMarshalText) MarshalText() ([]byte, error) {
- return []byte(fmt.Sprintf(`Z%.2x`, int(b))), nil
-}
-
-func (b *intWithMarshalText) UnmarshalText(data []byte) error {
- if len(data) != 3 || data[0] != 'Z' {
- return fmt.Errorf("bad quoted string")
- }
- i, err := strconv.ParseInt(string(data[1:3]), 16, 8)
- if err != nil {
- return fmt.Errorf("bad hex")
- }
- *b = intWithMarshalText(i)
- return nil
-}
-
-type intWithPtrMarshalText int
-
-func (b *intWithPtrMarshalText) MarshalText() ([]byte, error) {
- return intWithMarshalText(*b).MarshalText()
-}
-
-func (b *intWithPtrMarshalText) UnmarshalText(data []byte) error {
- return (*intWithMarshalText)(b).UnmarshalText(data)
-}
-
-type mapStringToStringData struct {
- Data map[string]string `json:"data"`
-}
-
-type unmarshalTest struct {
- in string
- ptr interface{}
- out interface{}
- err error
- useNumber bool
- golden bool
- disallowUnknownFields bool
-}
-
-type B struct {
- B bool `json:",string"`
-}
-
-var unmarshalTests = []unmarshalTest{
- // basic types
- {in: `true`, ptr: new(bool), out: true},
- {in: `1`, ptr: new(int), out: 1},
- {in: `1.2`, ptr: new(float64), out: 1.2},
- {in: `-5`, ptr: new(int16), out: int16(-5)},
- {in: `2`, ptr: new(Number), out: Number("2"), useNumber: true},
- {in: `2`, ptr: new(Number), out: Number("2")},
- {in: `2`, ptr: new(interface{}), out: float64(2.0)},
- {in: `2`, ptr: new(interface{}), out: Number("2"), useNumber: true},
- {in: `"a\u1234"`, ptr: new(string), out: "a\u1234"},
- {in: `"http:\/\/"`, ptr: new(string), out: "http://"},
- {in: `"g-clef: \uD834\uDD1E"`, ptr: new(string), out: "g-clef: \U0001D11E"},
- {in: `"invalid: \uD834x\uDD1E"`, ptr: new(string), out: "invalid: \uFFFDx\uFFFD"},
- {in: "null", ptr: new(interface{}), out: nil},
- {in: `{"X": [1,2,3], "Y": 4}`, ptr: new(T), out: T{Y: 4}, err: &UnmarshalTypeError{"array", reflect.TypeOf(""), 7, "T", "X"}},
- {in: `{"X": 23}`, ptr: new(T), out: T{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(""), 8, "T", "X"}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}},
- {in: `{"x": 1}`, ptr: new(tx), out: tx{}},
- {in: `{"x": 1}`, ptr: new(tx), err: fmt.Errorf("json: unknown field \"x\""), disallowUnknownFields: true},
- {in: `{"S": 23}`, ptr: new(W), out: W{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(SS("")), 0, "W", "S"}},
- {in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: float64(1), F2: int32(2), F3: Number("3")}},
- {in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: Number("1"), F2: int32(2), F3: Number("3")}, useNumber: true},
- {in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(interface{}), out: ifaceNumAsFloat64},
- {in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(interface{}), out: ifaceNumAsNumber, useNumber: true},
-
- // raw values with whitespace
- {in: "\n true ", ptr: new(bool), out: true},
- {in: "\t 1 ", ptr: new(int), out: 1},
- {in: "\r 1.2 ", ptr: new(float64), out: 1.2},
- {in: "\t -5 \n", ptr: new(int16), out: int16(-5)},
- {in: "\t \"a\\u1234\" \n", ptr: new(string), out: "a\u1234"},
-
- // Z has a "-" tag.
- {in: `{"Y": 1, "Z": 2}`, ptr: new(T), out: T{Y: 1}},
- {in: `{"Y": 1, "Z": 2}`, ptr: new(T), err: fmt.Errorf("json: unknown field \"Z\""), disallowUnknownFields: true},
-
- {in: `{"alpha": "abc", "alphabet": "xyz"}`, ptr: new(U), out: U{Alphabet: "abc"}},
- {in: `{"alpha": "abc", "alphabet": "xyz"}`, ptr: new(U), err: fmt.Errorf("json: unknown field \"alphabet\""), disallowUnknownFields: true},
- {in: `{"alpha": "abc"}`, ptr: new(U), out: U{Alphabet: "abc"}},
- {in: `{"alphabet": "xyz"}`, ptr: new(U), out: U{}},
- {in: `{"alphabet": "xyz"}`, ptr: new(U), err: fmt.Errorf("json: unknown field \"alphabet\""), disallowUnknownFields: true},
-
- // syntax errors
- {in: `{"X": "foo", "Y"}`, err: &SyntaxError{"invalid character '}' after object key", 17}},
- {in: `[1, 2, 3+]`, err: &SyntaxError{"invalid character '+' after array element", 9}},
- {in: `{"X":12x}`, err: &SyntaxError{"invalid character 'x' after object key:value pair", 8}, useNumber: true},
- {in: `[2, 3`, err: &SyntaxError{msg: "unexpected end of JSON input", Offset: 5}},
-
- // raw value errors
- {in: "\x01 42", err: &SyntaxError{"invalid character '\\x01' looking for beginning of value", 1}},
- {in: " 42 \x01", err: &SyntaxError{"invalid character '\\x01' after top-level value", 5}},
- {in: "\x01 true", err: &SyntaxError{"invalid character '\\x01' looking for beginning of value", 1}},
- {in: " false \x01", err: &SyntaxError{"invalid character '\\x01' after top-level value", 8}},
- {in: "\x01 1.2", err: &SyntaxError{"invalid character '\\x01' looking for beginning of value", 1}},
- {in: " 3.4 \x01", err: &SyntaxError{"invalid character '\\x01' after top-level value", 6}},
- {in: "\x01 \"string\"", err: &SyntaxError{"invalid character '\\x01' looking for beginning of value", 1}},
- {in: " \"string\" \x01", err: &SyntaxError{"invalid character '\\x01' after top-level value", 11}},
-
- // array tests
- {in: `[1, 2, 3]`, ptr: new([3]int), out: [3]int{1, 2, 3}},
- {in: `[1, 2, 3]`, ptr: new([1]int), out: [1]int{1}},
- {in: `[1, 2, 3]`, ptr: new([5]int), out: [5]int{1, 2, 3, 0, 0}},
- {in: `[1, 2, 3]`, ptr: new(MustNotUnmarshalJSON), err: errors.New("MustNotUnmarshalJSON was used")},
-
- // empty array to interface test
- {in: `[]`, ptr: new([]interface{}), out: []interface{}{}},
- {in: `null`, ptr: new([]interface{}), out: []interface{}(nil)},
- {in: `{"T":[]}`, ptr: new(map[string]interface{}), out: map[string]interface{}{"T": []interface{}{}}},
- {in: `{"T":null}`, ptr: new(map[string]interface{}), out: map[string]interface{}{"T": interface{}(nil)}},
-
- // composite tests
- {in: allValueIndent, ptr: new(All), out: allValue},
- {in: allValueCompact, ptr: new(All), out: allValue},
- {in: allValueIndent, ptr: new(*All), out: &allValue},
- {in: allValueCompact, ptr: new(*All), out: &allValue},
- {in: pallValueIndent, ptr: new(All), out: pallValue},
- {in: pallValueCompact, ptr: new(All), out: pallValue},
- {in: pallValueIndent, ptr: new(*All), out: &pallValue},
- {in: pallValueCompact, ptr: new(*All), out: &pallValue},
-
- // unmarshal interface test
- {in: `{"T":false}`, ptr: &um0, out: umtrue}, // use "false" so test will fail if custom unmarshaler is not called
- {in: `{"T":false}`, ptr: &ump, out: &umtrue},
- {in: `[{"T":false}]`, ptr: &umslice, out: umslice},
- {in: `[{"T":false}]`, ptr: &umslicep, out: &umslice},
- {in: `{"M":{"T":"x:y"}}`, ptr: &umstruct, out: umstruct},
-
- // UnmarshalText interface test
- {in: `"x:y"`, ptr: &um0T, out: umtrueXY},
- {in: `"x:y"`, ptr: &umpType, out: &umtrueXY},
- {in: `["x:y"]`, ptr: &umsliceXY, out: umsliceXY},
- {in: `["x:y"]`, ptr: &umslicepType, out: &umsliceXY},
- {in: `{"M":"x:y"}`, ptr: umstructType, out: umstructXY},
-
- // integer-keyed map test
- {
- in: `{"-1":"a","0":"b","1":"c"}`,
- ptr: new(map[int]string),
- out: map[int]string{-1: "a", 0: "b", 1: "c"},
- },
- {
- in: `{"0":"a","10":"c","9":"b"}`,
- ptr: new(map[u8]string),
- out: map[u8]string{0: "a", 9: "b", 10: "c"},
- },
- {
- in: `{"-9223372036854775808":"min","9223372036854775807":"max"}`,
- ptr: new(map[int64]string),
- out: map[int64]string{math.MinInt64: "min", math.MaxInt64: "max"},
- },
- {
- in: `{"18446744073709551615":"max"}`,
- ptr: new(map[uint64]string),
- out: map[uint64]string{math.MaxUint64: "max"},
- },
- {
- in: `{"0":false,"10":true}`,
- ptr: new(map[uintptr]bool),
- out: map[uintptr]bool{0: false, 10: true},
- },
-
- // Check that MarshalText and UnmarshalText take precedence
- // over default integer handling in map keys.
- {
- in: `{"u2":4}`,
- ptr: new(map[u8marshal]int),
- out: map[u8marshal]int{2: 4},
- },
- {
- in: `{"2":4}`,
- ptr: new(map[u8marshal]int),
- err: errMissingU8Prefix,
- },
-
- // integer-keyed map errors
- {
- in: `{"abc":"abc"}`,
- ptr: new(map[int]string),
- err: &UnmarshalTypeError{Value: "number abc", Type: reflect.TypeOf(0), Offset: 2},
- },
- {
- in: `{"256":"abc"}`,
- ptr: new(map[uint8]string),
- err: &UnmarshalTypeError{Value: "number 256", Type: reflect.TypeOf(uint8(0)), Offset: 2},
- },
- {
- in: `{"128":"abc"}`,
- ptr: new(map[int8]string),
- err: &UnmarshalTypeError{Value: "number 128", Type: reflect.TypeOf(int8(0)), Offset: 2},
- },
- {
- in: `{"-1":"abc"}`,
- ptr: new(map[uint8]string),
- err: &UnmarshalTypeError{Value: "number -1", Type: reflect.TypeOf(uint8(0)), Offset: 2},
- },
- {
- in: `{"F":{"a":2,"3":4}}`,
- ptr: new(map[string]map[int]int),
- err: &UnmarshalTypeError{Value: "number a", Type: reflect.TypeOf(int(0)), Offset: 7},
- },
- {
- in: `{"F":{"a":2,"3":4}}`,
- ptr: new(map[string]map[uint]int),
- err: &UnmarshalTypeError{Value: "number a", Type: reflect.TypeOf(uint(0)), Offset: 7},
- },
-
- // Map keys can be encoding.TextUnmarshalers.
- {in: `{"x:y":true}`, ptr: &ummapType, out: ummapXY},
- // If multiple values for the same key exists, only the most recent value is used.
- {in: `{"x:y":false,"x:y":true}`, ptr: &ummapType, out: ummapXY},
-
- // Overwriting of data.
- // This is different from package xml, but it's what we've always done.
- // Now documented and tested.
- {in: `[2]`, ptr: sliceAddr([]int{1}), out: []int{2}},
- {in: `{"key": 2}`, ptr: mapAddr(map[string]int{"old": 0, "key": 1}), out: map[string]int{"key": 2}},
-
- {
- in: `{
- "Level0": 1,
- "Level1b": 2,
- "Level1c": 3,
- "x": 4,
- "Level1a": 5,
- "LEVEL1B": 6,
- "e": {
- "Level1a": 8,
- "Level1b": 9,
- "Level1c": 10,
- "Level1d": 11,
- "x": 12
- },
- "Loop1": 13,
- "Loop2": 14,
- "X": 15,
- "Y": 16,
- "Z": 17,
- "Q": 18
- }`,
- ptr: new(Top),
- out: Top{
- Level0: 1,
- Embed0: Embed0{
- Level1b: 2,
- Level1c: 3,
- },
- Embed0a: &Embed0a{
- Level1a: 5,
- Level1b: 6,
- },
- Embed0b: &Embed0b{
- Level1a: 8,
- Level1b: 9,
- Level1c: 10,
- Level1d: 11,
- Level1e: 12,
- },
- Loop: Loop{
- Loop1: 13,
- Loop2: 14,
- },
- Embed0p: Embed0p{
- Point: image.Point{X: 15, Y: 16},
- },
- Embed0q: Embed0q{
- Point: Point{Z: 17},
- },
- embed: embed{
- Q: 18,
- },
- },
- },
- {
- in: `{"hello": 1}`,
- ptr: new(Ambig),
- out: Ambig{First: 1},
- },
-
- {
- in: `{"X": 1,"Y":2}`,
- ptr: new(S5),
- out: S5{S8: S8{S9: S9{Y: 2}}},
- },
- {
- in: `{"X": 1,"Y":2}`,
- ptr: new(S5),
- err: fmt.Errorf("json: unknown field \"X\""),
- disallowUnknownFields: true,
- },
- {
- in: `{"X": 1,"Y":2}`,
- ptr: new(S10),
- out: S10{S13: S13{S8: S8{S9: S9{Y: 2}}}},
- },
- {
- in: `{"X": 1,"Y":2}`,
- ptr: new(S10),
- err: fmt.Errorf("json: unknown field \"X\""),
- disallowUnknownFields: true,
- },
-
- // invalid UTF-8 is coerced to valid UTF-8.
- {
- in: "\"hello\xffworld\"",
- ptr: new(string),
- out: "hello\ufffdworld",
- },
- {
- in: "\"hello\xc2\xc2world\"",
- ptr: new(string),
- out: "hello\ufffd\ufffdworld",
- },
- {
- in: "\"hello\xc2\xffworld\"",
- ptr: new(string),
- out: "hello\ufffd\ufffdworld",
- },
- {
- in: "\"hello\\ud800world\"",
- ptr: new(string),
- out: "hello\ufffdworld",
- },
- {
- in: "\"hello\\ud800\\ud800world\"",
- ptr: new(string),
- out: "hello\ufffd\ufffdworld",
- },
- {
- in: "\"hello\\ud800\\ud800world\"",
- ptr: new(string),
- out: "hello\ufffd\ufffdworld",
- },
- {
- in: "\"hello\xed\xa0\x80\xed\xb0\x80world\"",
- ptr: new(string),
- out: "hello\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdworld",
- },
-
- // Used to be issue 8305, but time.Time implements encoding.TextUnmarshaler so this works now.
- {
- in: `{"2009-11-10T23:00:00Z": "hello world"}`,
- ptr: &map[time.Time]string{},
- out: map[time.Time]string{time.Date(2009, 11, 10, 23, 0, 0, 0, time.UTC): "hello world"},
- },
-
- // issue 8305
- {
- in: `{"2009-11-10T23:00:00Z": "hello world"}`,
- ptr: &map[Point]string{},
- err: &UnmarshalTypeError{Value: "object", Type: reflect.TypeOf(map[Point]string{}), Offset: 1},
- },
- {
- in: `{"asdf": "hello world"}`,
- ptr: &map[unmarshaler]string{},
- err: &UnmarshalTypeError{Value: "object", Type: reflect.TypeOf(map[unmarshaler]string{}), Offset: 1},
- },
-
- // related to issue 13783.
- // Go 1.7 changed marshaling a slice of typed byte to use the methods on the byte type,
- // similar to marshaling a slice of typed int.
- // These tests check that, assuming the byte type also has valid decoding methods,
- // either the old base64 string encoding or the new per-element encoding can be
- // successfully unmarshaled. The custom unmarshalers were accessible in earlier
- // versions of Go, even though the custom marshaler was not.
- {
- in: `"AQID"`,
- ptr: new([]byteWithMarshalJSON),
- out: []byteWithMarshalJSON{1, 2, 3},
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]byteWithMarshalJSON),
- out: []byteWithMarshalJSON{1, 2, 3},
- golden: true,
- },
- {
- in: `"AQID"`,
- ptr: new([]byteWithMarshalText),
- out: []byteWithMarshalText{1, 2, 3},
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]byteWithMarshalText),
- out: []byteWithMarshalText{1, 2, 3},
- golden: true,
- },
- {
- in: `"AQID"`,
- ptr: new([]byteWithPtrMarshalJSON),
- out: []byteWithPtrMarshalJSON{1, 2, 3},
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]byteWithPtrMarshalJSON),
- out: []byteWithPtrMarshalJSON{1, 2, 3},
- golden: true,
- },
- {
- in: `"AQID"`,
- ptr: new([]byteWithPtrMarshalText),
- out: []byteWithPtrMarshalText{1, 2, 3},
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]byteWithPtrMarshalText),
- out: []byteWithPtrMarshalText{1, 2, 3},
- golden: true,
- },
-
- // ints work with the marshaler but not the base64 []byte case
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]intWithMarshalJSON),
- out: []intWithMarshalJSON{1, 2, 3},
- golden: true,
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]intWithMarshalText),
- out: []intWithMarshalText{1, 2, 3},
- golden: true,
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]intWithPtrMarshalJSON),
- out: []intWithPtrMarshalJSON{1, 2, 3},
- golden: true,
- },
- {
- in: `["Z01","Z02","Z03"]`,
- ptr: new([]intWithPtrMarshalText),
- out: []intWithPtrMarshalText{1, 2, 3},
- golden: true,
- },
-
- {in: `0.000001`, ptr: new(float64), out: 0.000001, golden: true},
- {in: `1e-7`, ptr: new(float64), out: 1e-7, golden: true},
- {in: `100000000000000000000`, ptr: new(float64), out: 100000000000000000000.0, golden: true},
- {in: `1e+21`, ptr: new(float64), out: 1e21, golden: true},
- {in: `-0.000001`, ptr: new(float64), out: -0.000001, golden: true},
- {in: `-1e-7`, ptr: new(float64), out: -1e-7, golden: true},
- {in: `-100000000000000000000`, ptr: new(float64), out: -100000000000000000000.0, golden: true},
- {in: `-1e+21`, ptr: new(float64), out: -1e21, golden: true},
- {in: `999999999999999900000`, ptr: new(float64), out: 999999999999999900000.0, golden: true},
- {in: `9007199254740992`, ptr: new(float64), out: 9007199254740992.0, golden: true},
- {in: `9007199254740993`, ptr: new(float64), out: 9007199254740992.0, golden: false},
-
- {
- in: `{"V": {"F2": "hello"}}`,
- ptr: new(VOuter),
- err: &UnmarshalTypeError{
- Value: "string",
- Struct: "V",
- Field: "F2",
- Type: reflect.TypeOf(int32(0)),
- Offset: 20,
- },
- },
- {
- in: `{"V": {"F4": {}, "F2": "hello"}}`,
- ptr: new(VOuter),
- err: &UnmarshalTypeError{
- Value: "string",
- Struct: "V",
- Field: "F2",
- Type: reflect.TypeOf(int32(0)),
- Offset: 30,
- },
- },
-
- // issue 15146.
- // invalid inputs in wrongStringTests below.
- {in: `{"B":"true"}`, ptr: new(B), out: B{true}, golden: true},
- {in: `{"B":"false"}`, ptr: new(B), out: B{false}, golden: true},
- {in: `{"B": "maybe"}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal "maybe" into bool`)},
- {in: `{"B": "tru"}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal "tru" into bool`)},
- {in: `{"B": "False"}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal "False" into bool`)},
- {in: `{"B": "null"}`, ptr: new(B), out: B{false}},
- {in: `{"B": "nul"}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal "nul" into bool`)},
- {in: `{"B": [2, 3]}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal unquoted value into bool`)},
-
- // additional tests for disallowUnknownFields
- {
- in: `{
- "Level0": 1,
- "Level1b": 2,
- "Level1c": 3,
- "x": 4,
- "Level1a": 5,
- "LEVEL1B": 6,
- "e": {
- "Level1a": 8,
- "Level1b": 9,
- "Level1c": 10,
- "Level1d": 11,
- "x": 12
- },
- "Loop1": 13,
- "Loop2": 14,
- "X": 15,
- "Y": 16,
- "Z": 17,
- "Q": 18,
- "extra": true
- }`,
- ptr: new(Top),
- err: fmt.Errorf("json: unknown field \"extra\""),
- disallowUnknownFields: true,
- },
- {
- in: `{
- "Level0": 1,
- "Level1b": 2,
- "Level1c": 3,
- "x": 4,
- "Level1a": 5,
- "LEVEL1B": 6,
- "e": {
- "Level1a": 8,
- "Level1b": 9,
- "Level1c": 10,
- "Level1d": 11,
- "x": 12,
- "extra": null
- },
- "Loop1": 13,
- "Loop2": 14,
- "X": 15,
- "Y": 16,
- "Z": 17,
- "Q": 18
- }`,
- ptr: new(Top),
- err: fmt.Errorf("json: unknown field \"extra\""),
- disallowUnknownFields: true,
- },
- // issue 26444
- // UnmarshalTypeError without field & struct values
- {
- in: `{"data":{"test1": "bob", "test2": 123}}`,
- ptr: new(mapStringToStringData),
- err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(""), Offset: 37, Struct: "mapStringToStringData", Field: "data"},
- },
- {
- in: `{"data":{"test1": 123, "test2": "bob"}}`,
- ptr: new(mapStringToStringData),
- err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(""), Offset: 21, Struct: "mapStringToStringData", Field: "data"},
- },
-
- // trying to decode JSON arrays or objects via TextUnmarshaler
- {
- in: `[1, 2, 3]`,
- ptr: new(MustNotUnmarshalText),
- err: &UnmarshalTypeError{Value: "array", Type: reflect.TypeOf(&MustNotUnmarshalText{}), Offset: 1},
- },
- {
- in: `{"foo": "bar"}`,
- ptr: new(MustNotUnmarshalText),
- err: &UnmarshalTypeError{Value: "object", Type: reflect.TypeOf(&MustNotUnmarshalText{}), Offset: 1},
- },
-}
-
-func TestMarshal(t *testing.T) {
- b, err := Marshal(allValue)
- if err != nil {
- t.Fatalf("Marshal allValue: %v", err)
- }
- if string(b) != allValueCompact {
- t.Errorf("Marshal allValueCompact")
- diff(t, b, []byte(allValueCompact))
- return
- }
-
- b, err = Marshal(pallValue)
- if err != nil {
- t.Fatalf("Marshal pallValue: %v", err)
- }
- if string(b) != pallValueCompact {
- t.Errorf("Marshal pallValueCompact")
- diff(t, b, []byte(pallValueCompact))
- return
- }
-}
-
-var badUTF8 = []struct {
- in, out string
-}{
- {"hello\xffworld", `"hello\ufffdworld"`},
- {"", `""`},
- {"\xff", `"\ufffd"`},
- {"\xff\xff", `"\ufffd\ufffd"`},
- {"a\xffb", `"a\ufffdb"`},
- {"\xe6\x97\xa5\xe6\x9c\xac\xff\xaa\x9e", `"日本\ufffd\ufffd\ufffd"`},
-}
-
-func TestMarshalBadUTF8(t *testing.T) {
- for _, tt := range badUTF8 {
- b, err := Marshal(tt.in)
- if string(b) != tt.out || err != nil {
- t.Errorf("Marshal(%q) = %#q, %v, want %#q, nil", tt.in, b, err, tt.out)
- }
- }
-}
-
-func TestMarshalNumberZeroVal(t *testing.T) {
- var n Number
- out, err := Marshal(n)
- if err != nil {
- t.Fatal(err)
- }
- outStr := string(out)
- if outStr != "0" {
- t.Fatalf("Invalid zero val for Number: %q", outStr)
- }
-}
-
-func TestMarshalEmbeds(t *testing.T) {
- top := &Top{
- Level0: 1,
- Embed0: Embed0{
- Level1b: 2,
- Level1c: 3,
- },
- Embed0a: &Embed0a{
- Level1a: 5,
- Level1b: 6,
- },
- Embed0b: &Embed0b{
- Level1a: 8,
- Level1b: 9,
- Level1c: 10,
- Level1d: 11,
- Level1e: 12,
- },
- Loop: Loop{
- Loop1: 13,
- Loop2: 14,
- },
- Embed0p: Embed0p{
- Point: image.Point{X: 15, Y: 16},
- },
- Embed0q: Embed0q{
- Point: Point{Z: 17},
- },
- embed: embed{
- Q: 18,
- },
- }
- b, err := Marshal(top)
- if err != nil {
- t.Fatal(err)
- }
- want := "{\"Level0\":1,\"Level1b\":2,\"Level1c\":3,\"Level1a\":5,\"LEVEL1B\":6,\"e\":{\"Level1a\":8,\"Level1b\":9,\"Level1c\":10,\"Level1d\":11,\"x\":12},\"Loop1\":13,\"Loop2\":14,\"X\":15,\"Y\":16,\"Z\":17,\"Q\":18}"
- if string(b) != want {
- t.Errorf("Wrong marshal result.\n got: %q\nwant: %q", b, want)
- }
-}
-
-func TestUnmarshal(t *testing.T) {
- for i, tt := range unmarshalTests {
- var scan scanner
- in := []byte(tt.in)
- if err := checkValid(in, &scan); err != nil {
- if !reflect.DeepEqual(err, tt.err) {
- t.Errorf("#%d: checkValid: %#v", i, err)
- continue
- }
- }
- if tt.ptr == nil {
- continue
- }
-
- // v = new(right-type)
- v := reflect.New(reflect.TypeOf(tt.ptr).Elem())
- dec := NewDecoder(bytes.NewReader(in))
- if tt.useNumber {
- dec.UseNumber()
- }
- if tt.disallowUnknownFields {
- dec.DisallowUnknownFields()
- }
- if err := dec.Decode(v.Interface()); !reflect.DeepEqual(err, tt.err) {
- t.Errorf("#%d: %v, want %v", i, err, tt.err)
- continue
- } else if err != nil {
- continue
- }
- if !reflect.DeepEqual(v.Elem().Interface(), tt.out) {
- t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), tt.out)
- data, _ := Marshal(v.Elem().Interface())
- println(string(data))
- data, _ = Marshal(tt.out)
- println(string(data))
- continue
- }
-
- // Check round trip also decodes correctly.
- if tt.err == nil {
- enc, err := Marshal(v.Interface())
- if err != nil {
- t.Errorf("#%d: error re-marshaling: %v", i, err)
- continue
- }
- if tt.golden && !bytes.Equal(enc, in) {
- t.Errorf("#%d: remarshal mismatch:\nhave: %s\nwant: %s", i, enc, in)
- }
- vv := reflect.New(reflect.TypeOf(tt.ptr).Elem())
- dec = NewDecoder(bytes.NewReader(enc))
- if tt.useNumber {
- dec.UseNumber()
- }
- if err := dec.Decode(vv.Interface()); err != nil {
- t.Errorf("#%d: error re-unmarshaling %#q: %v", i, enc, err)
- continue
- }
- if !reflect.DeepEqual(v.Elem().Interface(), vv.Elem().Interface()) {
- t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), vv.Elem().Interface())
- t.Errorf(" In: %q", strings.Map(noSpace, string(in)))
- t.Errorf("Marshal: %q", strings.Map(noSpace, string(enc)))
- continue
- }
- }
- }
-}
-
-func TestUnmarshalMarshal(t *testing.T) {
- initBig()
- var v interface{}
- if err := Unmarshal(jsonBig, &v); err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- b, err := Marshal(v)
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
- if !bytes.Equal(jsonBig, b) {
- t.Errorf("Marshal jsonBig")
- diff(t, b, jsonBig)
- return
- }
-}
-
-var numberTests = []struct {
- in string
- i int64
- intErr string
- f float64
- floatErr string
-}{
- {in: "-1.23e1", intErr: "strconv.ParseInt: parsing \"-1.23e1\": invalid syntax", f: -1.23e1},
- {in: "-12", i: -12, f: -12.0},
- {in: "1e1000", intErr: "strconv.ParseInt: parsing \"1e1000\": invalid syntax", floatErr: "strconv.ParseFloat: parsing \"1e1000\": value out of range"},
-}
-
-// Independent of Decode, basic coverage of the accessors in Number
-func TestNumberAccessors(t *testing.T) {
- for _, tt := range numberTests {
- n := Number(tt.in)
- if s := n.String(); s != tt.in {
- t.Errorf("Number(%q).String() is %q", tt.in, s)
- }
- if i, err := n.Int64(); err == nil && tt.intErr == "" && i != tt.i {
- t.Errorf("Number(%q).Int64() is %d", tt.in, i)
- } else if (err == nil && tt.intErr != "") || (err != nil && err.Error() != tt.intErr) {
- t.Errorf("Number(%q).Int64() wanted error %q but got: %v", tt.in, tt.intErr, err)
- }
- if f, err := n.Float64(); err == nil && tt.floatErr == "" && f != tt.f {
- t.Errorf("Number(%q).Float64() is %g", tt.in, f)
- } else if (err == nil && tt.floatErr != "") || (err != nil && err.Error() != tt.floatErr) {
- t.Errorf("Number(%q).Float64() wanted error %q but got: %v", tt.in, tt.floatErr, err)
- }
- }
-}
-
-func TestLargeByteSlice(t *testing.T) {
- s0 := make([]byte, 2000)
- for i := range s0 {
- s0[i] = byte(i)
- }
- b, err := Marshal(s0)
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
- var s1 []byte
- if err := Unmarshal(b, &s1); err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if !bytes.Equal(s0, s1) {
- t.Errorf("Marshal large byte slice")
- diff(t, s0, s1)
- }
-}
-
-type Xint struct {
- X int
-}
-
-func TestUnmarshalInterface(t *testing.T) {
- var xint Xint
- var i interface{} = &xint
- if err := Unmarshal([]byte(`{"X":1}`), &i); err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if xint.X != 1 {
- t.Fatalf("Did not write to xint")
- }
-}
-
-func TestUnmarshalPtrPtr(t *testing.T) {
- var xint Xint
- pxint := &xint
- if err := Unmarshal([]byte(`{"X":1}`), &pxint); err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if xint.X != 1 {
- t.Fatalf("Did not write to xint")
- }
-}
-
-func TestEscape(t *testing.T) {
- const input = `"foobar"<html>` + " [\u2028 \u2029]"
- const expected = `"\"foobar\"\u003chtml\u003e [\u2028 \u2029]"`
- b, err := Marshal(input)
- if err != nil {
- t.Fatalf("Marshal error: %v", err)
- }
- if s := string(b); s != expected {
- t.Errorf("Encoding of [%s]:\n got [%s]\nwant [%s]", input, s, expected)
- }
-}
-
-// WrongString is a struct that's misusing the ,string modifier.
-type WrongString struct {
- Message string `json:"result,string"`
-}
-
-type wrongStringTest struct {
- in, err string
-}
-
-var wrongStringTests = []wrongStringTest{
- {`{"result":"x"}`, `json: invalid use of ,string struct tag, trying to unmarshal "x" into string`},
- {`{"result":"foo"}`, `json: invalid use of ,string struct tag, trying to unmarshal "foo" into string`},
- {`{"result":"123"}`, `json: invalid use of ,string struct tag, trying to unmarshal "123" into string`},
- {`{"result":123}`, `json: invalid use of ,string struct tag, trying to unmarshal unquoted value into string`},
-}
-
-// If people misuse the ,string modifier, the error message should be
-// helpful, telling the user that they're doing it wrong.
-func TestErrorMessageFromMisusedString(t *testing.T) {
- for n, tt := range wrongStringTests {
- r := strings.NewReader(tt.in)
- var s WrongString
- err := NewDecoder(r).Decode(&s)
- got := fmt.Sprintf("%v", err)
- if got != tt.err {
- t.Errorf("%d. got err = %q, want %q", n, got, tt.err)
- }
- }
-}
-
-func noSpace(c rune) rune {
- if isSpace(byte(c)) { //only used for ascii
- return -1
- }
- return c
-}
-
-type All struct {
- Bool bool
- Int int
- Int8 int8
- Int16 int16
- Int32 int32
- Int64 int64
- Uint uint
- Uint8 uint8
- Uint16 uint16
- Uint32 uint32
- Uint64 uint64
- Uintptr uintptr
- Float32 float32
- Float64 float64
-
- Foo string `json:"bar"`
- Foo2 string `json:"bar2,dummyopt"`
-
- IntStr int64 `json:",string"`
- UintptrStr uintptr `json:",string"`
-
- PBool *bool
- PInt *int
- PInt8 *int8
- PInt16 *int16
- PInt32 *int32
- PInt64 *int64
- PUint *uint
- PUint8 *uint8
- PUint16 *uint16
- PUint32 *uint32
- PUint64 *uint64
- PUintptr *uintptr
- PFloat32 *float32
- PFloat64 *float64
-
- String string
- PString *string
-
- Map map[string]Small
- MapP map[string]*Small
- PMap *map[string]Small
- PMapP *map[string]*Small
-
- EmptyMap map[string]Small
- NilMap map[string]Small
-
- Slice []Small
- SliceP []*Small
- PSlice *[]Small
- PSliceP *[]*Small
-
- EmptySlice []Small
- NilSlice []Small
-
- StringSlice []string
- ByteSlice []byte
-
- Small Small
- PSmall *Small
- PPSmall **Small
-
- Interface interface{}
- PInterface *interface{}
-
- unexported int
-}
-
-type Small struct {
- Tag string
-}
-
-var allValue = All{
- Bool: true,
- Int: 2,
- Int8: 3,
- Int16: 4,
- Int32: 5,
- Int64: 6,
- Uint: 7,
- Uint8: 8,
- Uint16: 9,
- Uint32: 10,
- Uint64: 11,
- Uintptr: 12,
- Float32: 14.1,
- Float64: 15.1,
- Foo: "foo",
- Foo2: "foo2",
- IntStr: 42,
- UintptrStr: 44,
- String: "16",
- Map: map[string]Small{
- "17": {Tag: "tag17"},
- "18": {Tag: "tag18"},
- },
- MapP: map[string]*Small{
- "19": {Tag: "tag19"},
- "20": nil,
- },
- EmptyMap: map[string]Small{},
- Slice: []Small{{Tag: "tag20"}, {Tag: "tag21"}},
- SliceP: []*Small{{Tag: "tag22"}, nil, {Tag: "tag23"}},
- EmptySlice: []Small{},
- StringSlice: []string{"str24", "str25", "str26"},
- ByteSlice: []byte{27, 28, 29},
- Small: Small{Tag: "tag30"},
- PSmall: &Small{Tag: "tag31"},
- Interface: 5.2,
-}
-
-var pallValue = All{
- PBool: &allValue.Bool,
- PInt: &allValue.Int,
- PInt8: &allValue.Int8,
- PInt16: &allValue.Int16,
- PInt32: &allValue.Int32,
- PInt64: &allValue.Int64,
- PUint: &allValue.Uint,
- PUint8: &allValue.Uint8,
- PUint16: &allValue.Uint16,
- PUint32: &allValue.Uint32,
- PUint64: &allValue.Uint64,
- PUintptr: &allValue.Uintptr,
- PFloat32: &allValue.Float32,
- PFloat64: &allValue.Float64,
- PString: &allValue.String,
- PMap: &allValue.Map,
- PMapP: &allValue.MapP,
- PSlice: &allValue.Slice,
- PSliceP: &allValue.SliceP,
- PPSmall: &allValue.PSmall,
- PInterface: &allValue.Interface,
-}
-
-var allValueIndent = `{
- "Bool": true,
- "Int": 2,
- "Int8": 3,
- "Int16": 4,
- "Int32": 5,
- "Int64": 6,
- "Uint": 7,
- "Uint8": 8,
- "Uint16": 9,
- "Uint32": 10,
- "Uint64": 11,
- "Uintptr": 12,
- "Float32": 14.1,
- "Float64": 15.1,
- "bar": "foo",
- "bar2": "foo2",
- "IntStr": "42",
- "UintptrStr": "44",
- "PBool": null,
- "PInt": null,
- "PInt8": null,
- "PInt16": null,
- "PInt32": null,
- "PInt64": null,
- "PUint": null,
- "PUint8": null,
- "PUint16": null,
- "PUint32": null,
- "PUint64": null,
- "PUintptr": null,
- "PFloat32": null,
- "PFloat64": null,
- "String": "16",
- "PString": null,
- "Map": {
- "17": {
- "Tag": "tag17"
- },
- "18": {
- "Tag": "tag18"
- }
- },
- "MapP": {
- "19": {
- "Tag": "tag19"
- },
- "20": null
- },
- "PMap": null,
- "PMapP": null,
- "EmptyMap": {},
- "NilMap": null,
- "Slice": [
- {
- "Tag": "tag20"
- },
- {
- "Tag": "tag21"
- }
- ],
- "SliceP": [
- {
- "Tag": "tag22"
- },
- null,
- {
- "Tag": "tag23"
- }
- ],
- "PSlice": null,
- "PSliceP": null,
- "EmptySlice": [],
- "NilSlice": null,
- "StringSlice": [
- "str24",
- "str25",
- "str26"
- ],
- "ByteSlice": "Gxwd",
- "Small": {
- "Tag": "tag30"
- },
- "PSmall": {
- "Tag": "tag31"
- },
- "PPSmall": null,
- "Interface": 5.2,
- "PInterface": null
-}`
-
-var allValueCompact = strings.Map(noSpace, allValueIndent)
-
-var pallValueIndent = `{
- "Bool": false,
- "Int": 0,
- "Int8": 0,
- "Int16": 0,
- "Int32": 0,
- "Int64": 0,
- "Uint": 0,
- "Uint8": 0,
- "Uint16": 0,
- "Uint32": 0,
- "Uint64": 0,
- "Uintptr": 0,
- "Float32": 0,
- "Float64": 0,
- "bar": "",
- "bar2": "",
- "IntStr": "0",
- "UintptrStr": "0",
- "PBool": true,
- "PInt": 2,
- "PInt8": 3,
- "PInt16": 4,
- "PInt32": 5,
- "PInt64": 6,
- "PUint": 7,
- "PUint8": 8,
- "PUint16": 9,
- "PUint32": 10,
- "PUint64": 11,
- "PUintptr": 12,
- "PFloat32": 14.1,
- "PFloat64": 15.1,
- "String": "",
- "PString": "16",
- "Map": null,
- "MapP": null,
- "PMap": {
- "17": {
- "Tag": "tag17"
- },
- "18": {
- "Tag": "tag18"
- }
- },
- "PMapP": {
- "19": {
- "Tag": "tag19"
- },
- "20": null
- },
- "EmptyMap": null,
- "NilMap": null,
- "Slice": null,
- "SliceP": null,
- "PSlice": [
- {
- "Tag": "tag20"
- },
- {
- "Tag": "tag21"
- }
- ],
- "PSliceP": [
- {
- "Tag": "tag22"
- },
- null,
- {
- "Tag": "tag23"
- }
- ],
- "EmptySlice": null,
- "NilSlice": null,
- "StringSlice": null,
- "ByteSlice": null,
- "Small": {
- "Tag": ""
- },
- "PSmall": null,
- "PPSmall": {
- "Tag": "tag31"
- },
- "Interface": null,
- "PInterface": 5.2
-}`
-
-var pallValueCompact = strings.Map(noSpace, pallValueIndent)
-
-func TestRefUnmarshal(t *testing.T) {
- type S struct {
- // Ref is defined in encode_test.go.
- R0 Ref
- R1 *Ref
- R2 RefText
- R3 *RefText
- }
- want := S{
- R0: 12,
- R1: new(Ref),
- R2: 13,
- R3: new(RefText),
- }
- *want.R1 = 12
- *want.R3 = 13
-
- var got S
- if err := Unmarshal([]byte(`{"R0":"ref","R1":"ref","R2":"ref","R3":"ref"}`), &got); err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if !reflect.DeepEqual(got, want) {
- t.Errorf("got %+v, want %+v", got, want)
- }
-}
-
-// Test that the empty string doesn't panic decoding when ,string is specified
-// Issue 3450
-func TestEmptyString(t *testing.T) {
- type T2 struct {
- Number1 int `json:",string"`
- Number2 int `json:",string"`
- }
- data := `{"Number1":"1", "Number2":""}`
- dec := NewDecoder(strings.NewReader(data))
- var t2 T2
- err := dec.Decode(&t2)
- if err == nil {
- t.Fatal("Decode: did not return error")
- }
- if t2.Number1 != 1 {
- t.Fatal("Decode: did not set Number1")
- }
-}
-
-// Test that a null for ,string is not replaced with the previous quoted string (issue 7046).
-// It should also not be an error (issue 2540, issue 8587).
-func TestNullString(t *testing.T) {
- type T struct {
- A int `json:",string"`
- B int `json:",string"`
- C *int `json:",string"`
- }
- data := []byte(`{"A": "1", "B": null, "C": null}`)
- var s T
- s.B = 1
- s.C = new(int)
- *s.C = 2
- err := Unmarshal(data, &s)
- if err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if s.B != 1 || s.C != nil {
- t.Fatalf("after Unmarshal, s.B=%d, s.C=%p, want 1, nil", s.B, s.C)
- }
-}
-
-func intp(x int) *int {
- p := new(int)
- *p = x
- return p
-}
-
-func intpp(x *int) **int {
- pp := new(*int)
- *pp = x
- return pp
-}
-
-var interfaceSetTests = []struct {
- pre interface{}
- json string
- post interface{}
-}{
- {"foo", `"bar"`, "bar"},
- {"foo", `2`, 2.0},
- {"foo", `true`, true},
- {"foo", `null`, nil},
-
- {nil, `null`, nil},
- {new(int), `null`, nil},
- {(*int)(nil), `null`, nil},
- {new(*int), `null`, new(*int)},
- {(**int)(nil), `null`, nil},
- {intp(1), `null`, nil},
- {intpp(nil), `null`, intpp(nil)},
- {intpp(intp(1)), `null`, intpp(nil)},
-}
-
-func TestInterfaceSet(t *testing.T) {
- for _, tt := range interfaceSetTests {
- b := struct{ X interface{} }{tt.pre}
- blob := `{"X":` + tt.json + `}`
- if err := Unmarshal([]byte(blob), &b); err != nil {
- t.Errorf("Unmarshal %#q: %v", blob, err)
- continue
- }
- if !reflect.DeepEqual(b.X, tt.post) {
- t.Errorf("Unmarshal %#q into %#v: X=%#v, want %#v", blob, tt.pre, b.X, tt.post)
- }
- }
-}
-
-type NullTest struct {
- Bool bool
- Int int
- Int8 int8
- Int16 int16
- Int32 int32
- Int64 int64
- Uint uint
- Uint8 uint8
- Uint16 uint16
- Uint32 uint32
- Uint64 uint64
- Float32 float32
- Float64 float64
- String string
- PBool *bool
- Map map[string]string
- Slice []string
- Interface interface{}
-
- PRaw *RawMessage
- PTime *time.Time
- PBigInt *big.Int
- PText *MustNotUnmarshalText
- PBuffer *bytes.Buffer // has methods, just not relevant ones
- PStruct *struct{}
-
- Raw RawMessage
- Time time.Time
- BigInt big.Int
- Text MustNotUnmarshalText
- Buffer bytes.Buffer
- Struct struct{}
-}
-
-type NullTestStrings struct {
- Bool bool `json:",string"`
- Int int `json:",string"`
- Int8 int8 `json:",string"`
- Int16 int16 `json:",string"`
- Int32 int32 `json:",string"`
- Int64 int64 `json:",string"`
- Uint uint `json:",string"`
- Uint8 uint8 `json:",string"`
- Uint16 uint16 `json:",string"`
- Uint32 uint32 `json:",string"`
- Uint64 uint64 `json:",string"`
- Float32 float32 `json:",string"`
- Float64 float64 `json:",string"`
- String string `json:",string"`
- PBool *bool `json:",string"`
- Map map[string]string `json:",string"`
- Slice []string `json:",string"`
- Interface interface{} `json:",string"`
-
- PRaw *RawMessage `json:",string"`
- PTime *time.Time `json:",string"`
- PBigInt *big.Int `json:",string"`
- PText *MustNotUnmarshalText `json:",string"`
- PBuffer *bytes.Buffer `json:",string"`
- PStruct *struct{} `json:",string"`
-
- Raw RawMessage `json:",string"`
- Time time.Time `json:",string"`
- BigInt big.Int `json:",string"`
- Text MustNotUnmarshalText `json:",string"`
- Buffer bytes.Buffer `json:",string"`
- Struct struct{} `json:",string"`
-}
-
-// JSON null values should be ignored for primitives and string values instead of resulting in an error.
-// Issue 2540
-func TestUnmarshalNulls(t *testing.T) {
- // Unmarshal docs:
- // The JSON null value unmarshals into an interface, map, pointer, or slice
- // by setting that Go value to nil. Because null is often used in JSON to mean
- // ``not present,'' unmarshaling a JSON null into any other Go type has no effect
- // on the value and produces no error.
-
- jsonData := []byte(`{
- "Bool" : null,
- "Int" : null,
- "Int8" : null,
- "Int16" : null,
- "Int32" : null,
- "Int64" : null,
- "Uint" : null,
- "Uint8" : null,
- "Uint16" : null,
- "Uint32" : null,
- "Uint64" : null,
- "Float32" : null,
- "Float64" : null,
- "String" : null,
- "PBool": null,
- "Map": null,
- "Slice": null,
- "Interface": null,
- "PRaw": null,
- "PTime": null,
- "PBigInt": null,
- "PText": null,
- "PBuffer": null,
- "PStruct": null,
- "Raw": null,
- "Time": null,
- "BigInt": null,
- "Text": null,
- "Buffer": null,
- "Struct": null
- }`)
- nulls := NullTest{
- Bool: true,
- Int: 2,
- Int8: 3,
- Int16: 4,
- Int32: 5,
- Int64: 6,
- Uint: 7,
- Uint8: 8,
- Uint16: 9,
- Uint32: 10,
- Uint64: 11,
- Float32: 12.1,
- Float64: 13.1,
- String: "14",
- PBool: new(bool),
- Map: map[string]string{},
- Slice: []string{},
- Interface: new(MustNotUnmarshalJSON),
- PRaw: new(RawMessage),
- PTime: new(time.Time),
- PBigInt: new(big.Int),
- PText: new(MustNotUnmarshalText),
- PStruct: new(struct{}),
- PBuffer: new(bytes.Buffer),
- Raw: RawMessage("123"),
- Time: time.Unix(123456789, 0),
- BigInt: *big.NewInt(123),
- }
-
- before := nulls.Time.String()
-
- err := Unmarshal(jsonData, &nulls)
- if err != nil {
- t.Errorf("Unmarshal of null values failed: %v", err)
- }
- if !nulls.Bool || nulls.Int != 2 || nulls.Int8 != 3 || nulls.Int16 != 4 || nulls.Int32 != 5 || nulls.Int64 != 6 ||
- nulls.Uint != 7 || nulls.Uint8 != 8 || nulls.Uint16 != 9 || nulls.Uint32 != 10 || nulls.Uint64 != 11 ||
- nulls.Float32 != 12.1 || nulls.Float64 != 13.1 || nulls.String != "14" {
- t.Errorf("Unmarshal of null values affected primitives")
- }
-
- if nulls.PBool != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PBool")
- }
- if nulls.Map != nil {
- t.Errorf("Unmarshal of null did not clear nulls.Map")
- }
- if nulls.Slice != nil {
- t.Errorf("Unmarshal of null did not clear nulls.Slice")
- }
- if nulls.Interface != nil {
- t.Errorf("Unmarshal of null did not clear nulls.Interface")
- }
- if nulls.PRaw != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PRaw")
- }
- if nulls.PTime != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PTime")
- }
- if nulls.PBigInt != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PBigInt")
- }
- if nulls.PText != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PText")
- }
- if nulls.PBuffer != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PBuffer")
- }
- if nulls.PStruct != nil {
- t.Errorf("Unmarshal of null did not clear nulls.PStruct")
- }
-
- if string(nulls.Raw) != "null" {
- t.Errorf("Unmarshal of RawMessage null did not record null: %v", string(nulls.Raw))
- }
- if nulls.Time.String() != before {
- t.Errorf("Unmarshal of time.Time null set time to %v", nulls.Time.String())
- }
- if nulls.BigInt.String() != "123" {
- t.Errorf("Unmarshal of big.Int null set int to %v", nulls.BigInt.String())
- }
-}
-
-type MustNotUnmarshalJSON struct{}
-
-func (x MustNotUnmarshalJSON) UnmarshalJSON(data []byte) error {
- return errors.New("MustNotUnmarshalJSON was used")
-}
-
-type MustNotUnmarshalText struct{}
-
-func (x MustNotUnmarshalText) UnmarshalText(text []byte) error {
- return errors.New("MustNotUnmarshalText was used")
-}
-
-func TestStringKind(t *testing.T) {
- type stringKind string
-
- var m1, m2 map[stringKind]int
- m1 = map[stringKind]int{
- "foo": 42,
- }
-
- data, err := Marshal(m1)
- if err != nil {
- t.Errorf("Unexpected error marshaling: %v", err)
- }
-
- err = Unmarshal(data, &m2)
- if err != nil {
- t.Errorf("Unexpected error unmarshaling: %v", err)
- }
-
- if !reflect.DeepEqual(m1, m2) {
- t.Error("Items should be equal after encoding and then decoding")
- }
-}
-
-// Custom types with []byte as underlying type could not be marshaled
-// and then unmarshaled.
-// Issue 8962.
-func TestByteKind(t *testing.T) {
- type byteKind []byte
-
- a := byteKind("hello")
-
- data, err := Marshal(a)
- if err != nil {
- t.Error(err)
- }
- var b byteKind
- err = Unmarshal(data, &b)
- if err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(a, b) {
- t.Errorf("expected %v == %v", a, b)
- }
-}
-
-// The fix for issue 8962 introduced a regression.
-// Issue 12921.
-func TestSliceOfCustomByte(t *testing.T) {
- type Uint8 uint8
-
- a := []Uint8("hello")
-
- data, err := Marshal(a)
- if err != nil {
- t.Fatal(err)
- }
- var b []Uint8
- err = Unmarshal(data, &b)
- if err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(a, b) {
- t.Fatalf("expected %v == %v", a, b)
- }
-}
-
-var decodeTypeErrorTests = []struct {
- dest interface{}
- src string
-}{
- {new(string), `{"user": "name"}`}, // issue 4628.
- {new(error), `{}`}, // issue 4222
- {new(error), `[]`},
- {new(error), `""`},
- {new(error), `123`},
- {new(error), `true`},
-}
-
-func TestUnmarshalTypeError(t *testing.T) {
- for _, item := range decodeTypeErrorTests {
- err := Unmarshal([]byte(item.src), item.dest)
- if _, ok := err.(*UnmarshalTypeError); !ok {
- t.Errorf("expected type error for Unmarshal(%q, type %T): got %T",
- item.src, item.dest, err)
- }
- }
-}
-
-var unmarshalSyntaxTests = []string{
- "tru",
- "fals",
- "nul",
- "123e",
- `"hello`,
- `[1,2,3`,
- `{"key":1`,
- `{"key":1,`,
-}
-
-func TestUnmarshalSyntax(t *testing.T) {
- var x interface{}
- for _, src := range unmarshalSyntaxTests {
- err := Unmarshal([]byte(src), &x)
- if _, ok := err.(*SyntaxError); !ok {
- t.Errorf("expected syntax error for Unmarshal(%q): got %T", src, err)
- }
- }
-}
-
-// Test handling of unexported fields that should be ignored.
-// Issue 4660
-type unexportedFields struct {
- Name string
- m map[string]interface{} `json:"-"`
- m2 map[string]interface{} `json:"abcd"`
-
- s []int `json:"-"`
-}
-
-func TestUnmarshalUnexported(t *testing.T) {
- input := `{"Name": "Bob", "m": {"x": 123}, "m2": {"y": 456}, "abcd": {"z": 789}, "s": [2, 3]}`
- want := &unexportedFields{Name: "Bob"}
-
- out := &unexportedFields{}
- err := Unmarshal([]byte(input), out)
- if err != nil {
- t.Errorf("got error %v, expected nil", err)
- }
- if !reflect.DeepEqual(out, want) {
- t.Errorf("got %q, want %q", out, want)
- }
-}
-
-// Time3339 is a time.Time which encodes to and from JSON
-// as an RFC 3339 time in UTC.
-type Time3339 time.Time
-
-func (t *Time3339) UnmarshalJSON(b []byte) error {
- if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' {
- return fmt.Errorf("types: failed to unmarshal non-string value %q as an RFC 3339 time", b)
- }
- tm, err := time.Parse(time.RFC3339, string(b[1:len(b)-1]))
- if err != nil {
- return err
- }
- *t = Time3339(tm)
- return nil
-}
-
-func TestUnmarshalJSONLiteralError(t *testing.T) {
- var t3 Time3339
- err := Unmarshal([]byte(`"0000-00-00T00:00:00Z"`), &t3)
- if err == nil {
- t.Fatalf("expected error; got time %v", time.Time(t3))
- }
- if !strings.Contains(err.Error(), "range") {
- t.Errorf("got err = %v; want out of range error", err)
- }
-}
-
-// Test that extra object elements in an array do not result in a
-// "data changing underfoot" error.
-// Issue 3717
-func TestSkipArrayObjects(t *testing.T) {
- json := `[{}]`
- var dest [0]interface{}
-
- err := Unmarshal([]byte(json), &dest)
- if err != nil {
- t.Errorf("got error %q, want nil", err)
- }
-}
-
-// Test semantics of pre-filled struct fields and pre-filled map fields.
-// Issue 4900.
-func TestPrefilled(t *testing.T) {
- ptrToMap := func(m map[string]interface{}) *map[string]interface{} { return &m }
-
- // Values here change, cannot reuse table across runs.
- var prefillTests = []struct {
- in string
- ptr interface{}
- out interface{}
- }{
- {
- in: `{"X": 1, "Y": 2}`,
- ptr: &XYZ{X: float32(3), Y: int16(4), Z: 1.5},
- out: &XYZ{X: float64(1), Y: float64(2), Z: 1.5},
- },
- {
- in: `{"X": 1, "Y": 2}`,
- ptr: ptrToMap(map[string]interface{}{"X": float32(3), "Y": int16(4), "Z": 1.5}),
- out: ptrToMap(map[string]interface{}{"X": float64(1), "Y": float64(2), "Z": 1.5}),
- },
- }
-
- for _, tt := range prefillTests {
- ptrstr := fmt.Sprintf("%v", tt.ptr)
- err := Unmarshal([]byte(tt.in), tt.ptr) // tt.ptr edited here
- if err != nil {
- t.Errorf("Unmarshal: %v", err)
- }
- if !reflect.DeepEqual(tt.ptr, tt.out) {
- t.Errorf("Unmarshal(%#q, %s): have %v, want %v", tt.in, ptrstr, tt.ptr, tt.out)
- }
- }
-}
-
-var invalidUnmarshalTests = []struct {
- v interface{}
- want string
-}{
- {nil, "json: Unmarshal(nil)"},
- {struct{}{}, "json: Unmarshal(non-pointer struct {})"},
- {(*int)(nil), "json: Unmarshal(nil *int)"},
-}
-
-func TestInvalidUnmarshal(t *testing.T) {
- buf := []byte(`{"a":"1"}`)
- for _, tt := range invalidUnmarshalTests {
- err := Unmarshal(buf, tt.v)
- if err == nil {
- t.Errorf("Unmarshal expecting error, got nil")
- continue
- }
- if got := err.Error(); got != tt.want {
- t.Errorf("Unmarshal = %q; want %q", got, tt.want)
- }
- }
-}
-
-var invalidUnmarshalTextTests = []struct {
- v interface{}
- want string
-}{
- {nil, "json: Unmarshal(nil)"},
- {struct{}{}, "json: Unmarshal(non-pointer struct {})"},
- {(*int)(nil), "json: Unmarshal(nil *int)"},
- {new(net.IP), "json: cannot unmarshal number into Go value of type *net.IP"},
-}
-
-func TestInvalidUnmarshalText(t *testing.T) {
- buf := []byte(`123`)
- for _, tt := range invalidUnmarshalTextTests {
- err := Unmarshal(buf, tt.v)
- if err == nil {
- t.Errorf("Unmarshal expecting error, got nil")
- continue
- }
- if got := err.Error(); got != tt.want {
- t.Errorf("Unmarshal = %q; want %q", got, tt.want)
- }
- }
-}
-
-// Test that string option is ignored for invalid types.
-// Issue 9812.
-func TestInvalidStringOption(t *testing.T) {
- num := 0
- item := struct {
- T time.Time `json:",string"`
- M map[string]string `json:",string"`
- S []string `json:",string"`
- A [1]string `json:",string"`
- I interface{} `json:",string"`
- P *int `json:",string"`
- }{M: make(map[string]string), S: make([]string, 0), I: num, P: &num}
-
- data, err := Marshal(item)
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
-
- err = Unmarshal(data, &item)
- if err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
-}
-
-// Test unmarshal behavior with regards to embedded unexported structs.
-//
-// (Issue 21357) If the embedded struct is a pointer and is unallocated,
-// this returns an error because unmarshal cannot set the field.
-//
-// (Issue 24152) If the embedded struct is given an explicit name,
-// ensure that the normal unmarshal logic does not panic in reflect.
-//
-// (Issue 28145) If the embedded struct is given an explicit name and has
-// exported methods, don't cause a panic trying to get its value.
-func TestUnmarshalEmbeddedUnexported(t *testing.T) {
- type (
- embed1 struct{ Q int }
- embed2 struct{ Q int }
- embed3 struct {
- Q int64 `json:",string"`
- }
- S1 struct {
- *embed1
- R int
- }
- S2 struct {
- *embed1
- Q int
- }
- S3 struct {
- embed1
- R int
- }
- S4 struct {
- *embed1
- embed2
- }
- S5 struct {
- *embed3
- R int
- }
- S6 struct {
- embed1 `json:"embed1"`
- }
- S7 struct {
- embed1 `json:"embed1"`
- embed2
- }
- S8 struct {
- embed1 `json:"embed1"`
- embed2 `json:"embed2"`
- Q int
- }
- S9 struct {
- unexportedWithMethods `json:"embed"`
- }
- )
-
- tests := []struct {
- in string
- ptr interface{}
- out interface{}
- err error
- }{{
- // Error since we cannot set S1.embed1, but still able to set S1.R.
- in: `{"R":2,"Q":1}`,
- ptr: new(S1),
- out: &S1{R: 2},
- err: fmt.Errorf("json: cannot set embedded pointer to unexported struct: json.embed1"),
- }, {
- // The top level Q field takes precedence.
- in: `{"Q":1}`,
- ptr: new(S2),
- out: &S2{Q: 1},
- }, {
- // No issue with non-pointer variant.
- in: `{"R":2,"Q":1}`,
- ptr: new(S3),
- out: &S3{embed1: embed1{Q: 1}, R: 2},
- }, {
- // No error since both embedded structs have field R, which annihilate each other.
- // Thus, no attempt is made at setting S4.embed1.
- in: `{"R":2}`,
- ptr: new(S4),
- out: new(S4),
- }, {
- // Error since we cannot set S5.embed1, but still able to set S5.R.
- in: `{"R":2,"Q":1}`,
- ptr: new(S5),
- out: &S5{R: 2},
- err: fmt.Errorf("json: cannot set embedded pointer to unexported struct: json.embed3"),
- }, {
- // Issue 24152, ensure decodeState.indirect does not panic.
- in: `{"embed1": {"Q": 1}}`,
- ptr: new(S6),
- out: &S6{embed1{1}},
- }, {
- // Issue 24153, check that we can still set forwarded fields even in
- // the presence of a name conflict.
- //
- // This relies on obscure behavior of reflect where it is possible
- // to set a forwarded exported field on an unexported embedded struct
- // even though there is a name conflict, even when it would have been
- // impossible to do so according to Go visibility rules.
- // Go forbids this because it is ambiguous whether S7.Q refers to
- // S7.embed1.Q or S7.embed2.Q. Since embed1 and embed2 are unexported,
- // it should be impossible for an external package to set either Q.
- //
- // It is probably okay for a future reflect change to break this.
- in: `{"embed1": {"Q": 1}, "Q": 2}`,
- ptr: new(S7),
- out: &S7{embed1{1}, embed2{2}},
- }, {
- // Issue 24153, similar to the S7 case.
- in: `{"embed1": {"Q": 1}, "embed2": {"Q": 2}, "Q": 3}`,
- ptr: new(S8),
- out: &S8{embed1{1}, embed2{2}, 3},
- }, {
- // Issue 228145, similar to the cases above.
- in: `{"embed": {}}`,
- ptr: new(S9),
- out: &S9{},
- }}
-
- for i, tt := range tests {
- err := Unmarshal([]byte(tt.in), tt.ptr)
- if !reflect.DeepEqual(err, tt.err) {
- t.Errorf("#%d: %v, want %v", i, err, tt.err)
- }
- if !reflect.DeepEqual(tt.ptr, tt.out) {
- t.Errorf("#%d: mismatch\ngot: %#+v\nwant: %#+v", i, tt.ptr, tt.out)
- }
- }
-}
-
-type unmarshalPanic struct{}
-
-func (unmarshalPanic) UnmarshalJSON([]byte) error { panic(0xdead) }
-
-func TestUnmarshalPanic(t *testing.T) {
- defer func() {
- if got := recover(); !reflect.DeepEqual(got, 0xdead) {
- t.Errorf("panic() = (%T)(%v), want 0xdead", got, got)
- }
- }()
- Unmarshal([]byte("{}"), &unmarshalPanic{})
- t.Fatalf("Unmarshal should have panicked")
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/encode.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/encode.go
deleted file mode 100644
index dea63f1..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/encode.go
+++ /dev/null
@@ -1,1273 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package json implements encoding and decoding of JSON as defined in
-// RFC 7159. The mapping between JSON and Go values is described
-// in the documentation for the Marshal and Unmarshal functions.
-//
-// See "JSON and Go" for an introduction to this package:
-// https://golang.org/doc/articles/json_and_go.html
-package json
-
-import (
- "bytes"
- "encoding"
- "encoding/base64"
- "fmt"
- "math"
- "reflect"
- "sort"
- "strconv"
- "strings"
- "sync"
- "unicode"
- "unicode/utf8"
-)
-
-// Marshal returns the JSON encoding of v.
-//
-// Marshal traverses the value v recursively.
-// If an encountered value implements the Marshaler interface
-// and is not a nil pointer, Marshal calls its MarshalJSON method
-// to produce JSON. If no MarshalJSON method is present but the
-// value implements encoding.TextMarshaler instead, Marshal calls
-// its MarshalText method and encodes the result as a JSON string.
-// The nil pointer exception is not strictly necessary
-// but mimics a similar, necessary exception in the behavior of
-// UnmarshalJSON.
-//
-// Otherwise, Marshal uses the following type-dependent default encodings:
-//
-// Boolean values encode as JSON booleans.
-//
-// Floating point, integer, and Number values encode as JSON numbers.
-//
-// String values encode as JSON strings coerced to valid UTF-8,
-// replacing invalid bytes with the Unicode replacement rune.
-// The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e"
-// to keep some browsers from misinterpreting JSON output as HTML.
-// Ampersand "&" is also escaped to "\u0026" for the same reason.
-// This escaping can be disabled using an Encoder that had SetEscapeHTML(false)
-// called on it.
-//
-// Array and slice values encode as JSON arrays, except that
-// []byte encodes as a base64-encoded string, and a nil slice
-// encodes as the null JSON value.
-//
-// Struct values encode as JSON objects.
-// Each exported struct field becomes a member of the object, using the
-// field name as the object key, unless the field is omitted for one of the
-// reasons given below.
-//
-// The encoding of each struct field can be customized by the format string
-// stored under the "json" key in the struct field's tag.
-// The format string gives the name of the field, possibly followed by a
-// comma-separated list of options. The name may be empty in order to
-// specify options without overriding the default field name.
-//
-// The "omitempty" option specifies that the field should be omitted
-// from the encoding if the field has an empty value, defined as
-// false, 0, a nil pointer, a nil interface value, and any empty array,
-// slice, map, or string.
-//
-// As a special case, if the field tag is "-", the field is always omitted.
-// Note that a field with name "-" can still be generated using the tag "-,".
-//
-// Examples of struct field tags and their meanings:
-//
-// // Field appears in JSON as key "myName".
-// Field int `json:"myName"`
-//
-// // Field appears in JSON as key "myName" and
-// // the field is omitted from the object if its value is empty,
-// // as defined above.
-// Field int `json:"myName,omitempty"`
-//
-// // Field appears in JSON as key "Field" (the default), but
-// // the field is skipped if empty.
-// // Note the leading comma.
-// Field int `json:",omitempty"`
-//
-// // Field is ignored by this package.
-// Field int `json:"-"`
-//
-// // Field appears in JSON as key "-".
-// Field int `json:"-,"`
-//
-// The "string" option signals that a field is stored as JSON inside a
-// JSON-encoded string. It applies only to fields of string, floating point,
-// integer, or boolean types. This extra level of encoding is sometimes used
-// when communicating with JavaScript programs:
-//
-// Int64String int64 `json:",string"`
-//
-// The key name will be used if it's a non-empty string consisting of
-// only Unicode letters, digits, and ASCII punctuation except quotation
-// marks, backslash, and comma.
-//
-// Anonymous struct fields are usually marshaled as if their inner exported fields
-// were fields in the outer struct, subject to the usual Go visibility rules amended
-// as described in the next paragraph.
-// An anonymous struct field with a name given in its JSON tag is treated as
-// having that name, rather than being anonymous.
-// An anonymous struct field of interface type is treated the same as having
-// that type as its name, rather than being anonymous.
-//
-// The Go visibility rules for struct fields are amended for JSON when
-// deciding which field to marshal or unmarshal. If there are
-// multiple fields at the same level, and that level is the least
-// nested (and would therefore be the nesting level selected by the
-// usual Go rules), the following extra rules apply:
-//
-// 1) Of those fields, if any are JSON-tagged, only tagged fields are considered,
-// even if there are multiple untagged fields that would otherwise conflict.
-//
-// 2) If there is exactly one field (tagged or not according to the first rule), that is selected.
-//
-// 3) Otherwise there are multiple fields, and all are ignored; no error occurs.
-//
-// Handling of anonymous struct fields is new in Go 1.1.
-// Prior to Go 1.1, anonymous struct fields were ignored. To force ignoring of
-// an anonymous struct field in both current and earlier versions, give the field
-// a JSON tag of "-".
-//
-// Map values encode as JSON objects. The map's key type must either be a
-// string, an integer type, or implement encoding.TextMarshaler. The map keys
-// are sorted and used as JSON object keys by applying the following rules,
-// subject to the UTF-8 coercion described for string values above:
-// - string keys are used directly
-// - encoding.TextMarshalers are marshaled
-// - integer keys are converted to strings
-//
-// Pointer values encode as the value pointed to.
-// A nil pointer encodes as the null JSON value.
-//
-// Interface values encode as the value contained in the interface.
-// A nil interface value encodes as the null JSON value.
-//
-// Channel, complex, and function values cannot be encoded in JSON.
-// Attempting to encode such a value causes Marshal to return
-// an UnsupportedTypeError.
-//
-// JSON cannot represent cyclic data structures and Marshal does not
-// handle them. Passing cyclic structures to Marshal will result in
-// an infinite recursion.
-//
-func Marshal(v interface{}) ([]byte, error) {
- e := newEncodeState()
-
- err := e.marshal(v, encOpts{escapeHTML: true})
- if err != nil {
- return nil, err
- }
- buf := append([]byte(nil), e.Bytes()...)
-
- e.Reset()
- encodeStatePool.Put(e)
-
- return buf, nil
-}
-
-// MarshalIndent is like Marshal but applies Indent to format the output.
-// Each JSON element in the output will begin on a new line beginning with prefix
-// followed by one or more copies of indent according to the indentation nesting.
-func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
- b, err := Marshal(v)
- if err != nil {
- return nil, err
- }
- var buf bytes.Buffer
- err = Indent(&buf, b, prefix, indent)
- if err != nil {
- return nil, err
- }
- return buf.Bytes(), nil
-}
-
-// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029
-// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029
-// so that the JSON will be safe to embed inside HTML <script> tags.
-// For historical reasons, web browsers don't honor standard HTML
-// escaping within <script> tags, so an alternative JSON encoding must
-// be used.
-func HTMLEscape(dst *bytes.Buffer, src []byte) {
- // The characters can only appear in string literals,
- // so just scan the string one byte at a time.
- start := 0
- for i, c := range src {
- if c == '<' || c == '>' || c == '&' {
- if start < i {
- dst.Write(src[start:i])
- }
- dst.WriteString(`\u00`)
- dst.WriteByte(hex[c>>4])
- dst.WriteByte(hex[c&0xF])
- start = i + 1
- }
- // Convert U+2028 and U+2029 (E2 80 A8 and E2 80 A9).
- if c == 0xE2 && i+2 < len(src) && src[i+1] == 0x80 && src[i+2]&^1 == 0xA8 {
- if start < i {
- dst.Write(src[start:i])
- }
- dst.WriteString(`\u202`)
- dst.WriteByte(hex[src[i+2]&0xF])
- start = i + 3
- }
- }
- if start < len(src) {
- dst.Write(src[start:])
- }
-}
-
-// Marshaler is the interface implemented by types that
-// can marshal themselves into valid JSON.
-type Marshaler interface {
- MarshalJSON() ([]byte, error)
-}
-
-// An UnsupportedTypeError is returned by Marshal when attempting
-// to encode an unsupported value type.
-type UnsupportedTypeError struct {
- Type reflect.Type
-}
-
-func (e *UnsupportedTypeError) Error() string {
- return "json: unsupported type: " + e.Type.String()
-}
-
-type UnsupportedValueError struct {
- Value reflect.Value
- Str string
-}
-
-func (e *UnsupportedValueError) Error() string {
- return "json: unsupported value: " + e.Str
-}
-
-// Before Go 1.2, an InvalidUTF8Error was returned by Marshal when
-// attempting to encode a string value with invalid UTF-8 sequences.
-// As of Go 1.2, Marshal instead coerces the string to valid UTF-8 by
-// replacing invalid bytes with the Unicode replacement rune U+FFFD.
-//
-// Deprecated: No longer used; kept for compatibility.
-type InvalidUTF8Error struct {
- S string // the whole string value that caused the error
-}
-
-func (e *InvalidUTF8Error) Error() string {
- return "json: invalid UTF-8 in string: " + strconv.Quote(e.S)
-}
-
-// A MarshalerError represents an error from calling a MarshalJSON or MarshalText method.
-type MarshalerError struct {
- Type reflect.Type
- Err error
-}
-
-func (e *MarshalerError) Error() string {
- return "json: error calling MarshalJSON for type " + e.Type.String() + ": " + e.Err.Error()
-}
-
-var hex = "0123456789abcdef"
-
-// An encodeState encodes JSON into a bytes.Buffer.
-type encodeState struct {
- bytes.Buffer // accumulated output
- scratch [64]byte
-}
-
-var encodeStatePool sync.Pool
-
-func newEncodeState() *encodeState {
- if v := encodeStatePool.Get(); v != nil {
- e := v.(*encodeState)
- e.Reset()
- return e
- }
- return new(encodeState)
-}
-
-// jsonError is an error wrapper type for internal use only.
-// Panics with errors are wrapped in jsonError so that the top-level recover
-// can distinguish intentional panics from this package.
-type jsonError struct{ error }
-
-func (e *encodeState) marshal(v interface{}, opts encOpts) (err error) {
- defer func() {
- if r := recover(); r != nil {
- if je, ok := r.(jsonError); ok {
- err = je.error
- } else {
- panic(r)
- }
- }
- }()
- e.reflectValue(reflect.ValueOf(v), opts)
- return nil
-}
-
-// error aborts the encoding by panicking with err wrapped in jsonError.
-func (e *encodeState) error(err error) {
- panic(jsonError{err})
-}
-
-func isEmptyValue(v reflect.Value) bool {
- switch v.Kind() {
- case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
- return v.Len() == 0
- case reflect.Bool:
- return !v.Bool()
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- return v.Int() == 0
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- return v.Uint() == 0
- case reflect.Float32, reflect.Float64:
- return v.Float() == 0
- case reflect.Interface, reflect.Ptr:
- return v.IsNil()
- }
- return false
-}
-
-func (e *encodeState) reflectValue(v reflect.Value, opts encOpts) {
- valueEncoder(v)(e, v, opts)
-}
-
-type encOpts struct {
- // quoted causes primitive fields to be encoded inside JSON strings.
- quoted bool
- // escapeHTML causes '<', '>', and '&' to be escaped in JSON strings.
- escapeHTML bool
-}
-
-type encoderFunc func(e *encodeState, v reflect.Value, opts encOpts)
-
-var encoderCache sync.Map // map[reflect.Type]encoderFunc
-
-func valueEncoder(v reflect.Value) encoderFunc {
- if !v.IsValid() {
- return invalidValueEncoder
- }
- return typeEncoder(v.Type())
-}
-
-func typeEncoder(t reflect.Type) encoderFunc {
- if fi, ok := encoderCache.Load(t); ok {
- return fi.(encoderFunc)
- }
-
- // To deal with recursive types, populate the map with an
- // indirect func before we build it. This type waits on the
- // real func (f) to be ready and then calls it. This indirect
- // func is only used for recursive types.
- var (
- wg sync.WaitGroup
- f encoderFunc
- )
- wg.Add(1)
- fi, loaded := encoderCache.LoadOrStore(t, encoderFunc(func(e *encodeState, v reflect.Value, opts encOpts) {
- wg.Wait()
- f(e, v, opts)
- }))
- if loaded {
- return fi.(encoderFunc)
- }
-
- // Compute the real encoder and replace the indirect func with it.
- f = newTypeEncoder(t, true)
- wg.Done()
- encoderCache.Store(t, f)
- return f
-}
-
-var (
- marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
- textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
-)
-
-// newTypeEncoder constructs an encoderFunc for a type.
-// The returned encoder only checks CanAddr when allowAddr is true.
-func newTypeEncoder(t reflect.Type, allowAddr bool) encoderFunc {
- if t.Implements(marshalerType) {
- return marshalerEncoder
- }
- if t.Kind() != reflect.Ptr && allowAddr {
- if reflect.PtrTo(t).Implements(marshalerType) {
- return newCondAddrEncoder(addrMarshalerEncoder, newTypeEncoder(t, false))
- }
- }
-
- if t.Implements(textMarshalerType) {
- return textMarshalerEncoder
- }
- if t.Kind() != reflect.Ptr && allowAddr {
- if reflect.PtrTo(t).Implements(textMarshalerType) {
- return newCondAddrEncoder(addrTextMarshalerEncoder, newTypeEncoder(t, false))
- }
- }
-
- switch t.Kind() {
- case reflect.Bool:
- return boolEncoder
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- return intEncoder
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- return uintEncoder
- case reflect.Float32:
- return float32Encoder
- case reflect.Float64:
- return float64Encoder
- case reflect.String:
- return stringEncoder
- case reflect.Interface:
- return interfaceEncoder
- case reflect.Struct:
- return newStructEncoder(t)
- case reflect.Map:
- return newMapEncoder(t)
- case reflect.Slice:
- return newSliceEncoder(t)
- case reflect.Array:
- return newArrayEncoder(t)
- case reflect.Ptr:
- return newPtrEncoder(t)
- default:
- return unsupportedTypeEncoder
- }
-}
-
-func invalidValueEncoder(e *encodeState, v reflect.Value, _ encOpts) {
- e.WriteString("null")
-}
-
-func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- if v.Kind() == reflect.Ptr && v.IsNil() {
- e.WriteString("null")
- return
- }
- m, ok := v.Interface().(Marshaler)
- if !ok {
- e.WriteString("null")
- return
- }
- b, err := m.MarshalJSON()
- if err == nil {
- // copy JSON into buffer, checking validity.
- err = compact(&e.Buffer, b, opts.escapeHTML)
- }
- if err != nil {
- e.error(&MarshalerError{v.Type(), err})
- }
-}
-
-func addrMarshalerEncoder(e *encodeState, v reflect.Value, _ encOpts) {
- va := v.Addr()
- if va.IsNil() {
- e.WriteString("null")
- return
- }
- m := va.Interface().(Marshaler)
- b, err := m.MarshalJSON()
- if err == nil {
- // copy JSON into buffer, checking validity.
- err = compact(&e.Buffer, b, true)
- }
- if err != nil {
- e.error(&MarshalerError{v.Type(), err})
- }
-}
-
-func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- if v.Kind() == reflect.Ptr && v.IsNil() {
- e.WriteString("null")
- return
- }
- m := v.Interface().(encoding.TextMarshaler)
- b, err := m.MarshalText()
- if err != nil {
- e.error(&MarshalerError{v.Type(), err})
- }
- e.stringBytes(b, opts.escapeHTML)
-}
-
-func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- va := v.Addr()
- if va.IsNil() {
- e.WriteString("null")
- return
- }
- m := va.Interface().(encoding.TextMarshaler)
- b, err := m.MarshalText()
- if err != nil {
- e.error(&MarshalerError{v.Type(), err})
- }
- e.stringBytes(b, opts.escapeHTML)
-}
-
-func boolEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- if opts.quoted {
- e.WriteByte('"')
- }
- if v.Bool() {
- e.WriteString("true")
- } else {
- e.WriteString("false")
- }
- if opts.quoted {
- e.WriteByte('"')
- }
-}
-
-func intEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- b := strconv.AppendInt(e.scratch[:0], v.Int(), 10)
- if opts.quoted {
- e.WriteByte('"')
- }
- e.Write(b)
- if opts.quoted {
- e.WriteByte('"')
- }
-}
-
-func uintEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- b := strconv.AppendUint(e.scratch[:0], v.Uint(), 10)
- if opts.quoted {
- e.WriteByte('"')
- }
- e.Write(b)
- if opts.quoted {
- e.WriteByte('"')
- }
-}
-
-type floatEncoder int // number of bits
-
-func (bits floatEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- f := v.Float()
- if math.IsInf(f, 0) || math.IsNaN(f) {
- e.error(&UnsupportedValueError{v, strconv.FormatFloat(f, 'g', -1, int(bits))})
- }
-
- // Convert as if by ES6 number to string conversion.
- // This matches most other JSON generators.
- // See golang.org/issue/6384 and golang.org/issue/14135.
- // Like fmt %g, but the exponent cutoffs are different
- // and exponents themselves are not padded to two digits.
- b := e.scratch[:0]
- abs := math.Abs(f)
- fmt := byte('f')
- // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
- if abs != 0 {
- if bits == 64 && (abs < 1e-6 || abs >= 1e21) || bits == 32 && (float32(abs) < 1e-6 || float32(abs) >= 1e21) {
- fmt = 'e'
- }
- }
- b = strconv.AppendFloat(b, f, fmt, -1, int(bits))
- if fmt == 'e' {
- // clean up e-09 to e-9
- n := len(b)
- if n >= 4 && b[n-4] == 'e' && b[n-3] == '-' && b[n-2] == '0' {
- b[n-2] = b[n-1]
- b = b[:n-1]
- }
- }
-
- if opts.quoted {
- e.WriteByte('"')
- }
- e.Write(b)
- if opts.quoted {
- e.WriteByte('"')
- }
-}
-
-var (
- float32Encoder = (floatEncoder(32)).encode
- float64Encoder = (floatEncoder(64)).encode
-)
-
-func stringEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- if v.Type() == numberType {
- numStr := v.String()
- // In Go1.5 the empty string encodes to "0", while this is not a valid number literal
- // we keep compatibility so check validity after this.
- if numStr == "" {
- numStr = "0" // Number's zero-val
- }
- if !isValidNumber(numStr) {
- e.error(fmt.Errorf("json: invalid number literal %q", numStr))
- }
- e.WriteString(numStr)
- return
- }
- if opts.quoted {
- sb, err := Marshal(v.String())
- if err != nil {
- e.error(err)
- }
- e.string(string(sb), opts.escapeHTML)
- } else {
- e.string(v.String(), opts.escapeHTML)
- }
-}
-
-func interfaceEncoder(e *encodeState, v reflect.Value, opts encOpts) {
- if v.IsNil() {
- e.WriteString("null")
- return
- }
- e.reflectValue(v.Elem(), opts)
-}
-
-func unsupportedTypeEncoder(e *encodeState, v reflect.Value, _ encOpts) {
- e.error(&UnsupportedTypeError{v.Type()})
-}
-
-type structEncoder struct {
- fields []field
-}
-
-func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- next := byte('{')
-FieldLoop:
- for i := range se.fields {
- f := &se.fields[i]
-
- // Find the nested struct field by following f.index.
- fv := v
- for _, i := range f.index {
- if fv.Kind() == reflect.Ptr {
- if fv.IsNil() {
- continue FieldLoop
- }
- fv = fv.Elem()
- }
- fv = fv.Field(i)
- }
-
- if f.omitEmpty && isEmptyValue(fv) {
- continue
- }
- e.WriteByte(next)
- next = ','
- if opts.escapeHTML {
- e.WriteString(f.nameEscHTML)
- } else {
- e.WriteString(f.nameNonEsc)
- }
- opts.quoted = f.quoted
- f.encoder(e, fv, opts)
- }
- if next == '{' {
- e.WriteString("{}")
- } else {
- e.WriteByte('}')
- }
-}
-
-func newStructEncoder(t reflect.Type) encoderFunc {
- se := structEncoder{fields: cachedTypeFields(t)}
- return se.encode
-}
-
-type mapEncoder struct {
- elemEnc encoderFunc
-}
-
-func (me mapEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- if v.IsNil() {
- e.WriteString("null")
- return
- }
- e.WriteByte('{')
-
- // Extract and sort the keys.
- keys := v.MapKeys()
- sv := make([]reflectWithString, len(keys))
- for i, v := range keys {
- sv[i].v = v
- if err := sv[i].resolve(); err != nil {
- e.error(&MarshalerError{v.Type(), err})
- }
- }
- sort.Slice(sv, func(i, j int) bool { return sv[i].s < sv[j].s })
-
- for i, kv := range sv {
- if i > 0 {
- e.WriteByte(',')
- }
- e.string(kv.s, opts.escapeHTML)
- e.WriteByte(':')
- me.elemEnc(e, v.MapIndex(kv.v), opts)
- }
- e.WriteByte('}')
-}
-
-func newMapEncoder(t reflect.Type) encoderFunc {
- switch t.Key().Kind() {
- case reflect.String,
- reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
- reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- default:
- if !t.Key().Implements(textMarshalerType) {
- return unsupportedTypeEncoder
- }
- }
- me := mapEncoder{typeEncoder(t.Elem())}
- return me.encode
-}
-
-func encodeByteSlice(e *encodeState, v reflect.Value, _ encOpts) {
- if v.IsNil() {
- e.WriteString("null")
- return
- }
- s := v.Bytes()
- e.WriteByte('"')
- encodedLen := base64.StdEncoding.EncodedLen(len(s))
- if encodedLen <= len(e.scratch) {
- // If the encoded bytes fit in e.scratch, avoid an extra
- // allocation and use the cheaper Encoding.Encode.
- dst := e.scratch[:encodedLen]
- base64.StdEncoding.Encode(dst, s)
- e.Write(dst)
- } else if encodedLen <= 1024 {
- // The encoded bytes are short enough to allocate for, and
- // Encoding.Encode is still cheaper.
- dst := make([]byte, encodedLen)
- base64.StdEncoding.Encode(dst, s)
- e.Write(dst)
- } else {
- // The encoded bytes are too long to cheaply allocate, and
- // Encoding.Encode is no longer noticeably cheaper.
- enc := base64.NewEncoder(base64.StdEncoding, e)
- enc.Write(s)
- enc.Close()
- }
- e.WriteByte('"')
-}
-
-// sliceEncoder just wraps an arrayEncoder, checking to make sure the value isn't nil.
-type sliceEncoder struct {
- arrayEnc encoderFunc
-}
-
-func (se sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- if v.IsNil() {
- e.WriteString("null")
- return
- }
- se.arrayEnc(e, v, opts)
-}
-
-func newSliceEncoder(t reflect.Type) encoderFunc {
- // Byte slices get special treatment; arrays don't.
- if t.Elem().Kind() == reflect.Uint8 {
- p := reflect.PtrTo(t.Elem())
- if !p.Implements(marshalerType) && !p.Implements(textMarshalerType) {
- return encodeByteSlice
- }
- }
- enc := sliceEncoder{newArrayEncoder(t)}
- return enc.encode
-}
-
-type arrayEncoder struct {
- elemEnc encoderFunc
-}
-
-func (ae arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- e.WriteByte('[')
- n := v.Len()
- for i := 0; i < n; i++ {
- if i > 0 {
- e.WriteByte(',')
- }
- ae.elemEnc(e, v.Index(i), opts)
- }
- e.WriteByte(']')
-}
-
-func newArrayEncoder(t reflect.Type) encoderFunc {
- enc := arrayEncoder{typeEncoder(t.Elem())}
- return enc.encode
-}
-
-type ptrEncoder struct {
- elemEnc encoderFunc
-}
-
-func (pe ptrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- if v.IsNil() {
- e.WriteString("null")
- return
- }
- pe.elemEnc(e, v.Elem(), opts)
-}
-
-func newPtrEncoder(t reflect.Type) encoderFunc {
- enc := ptrEncoder{typeEncoder(t.Elem())}
- return enc.encode
-}
-
-type condAddrEncoder struct {
- canAddrEnc, elseEnc encoderFunc
-}
-
-func (ce condAddrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
- if v.CanAddr() {
- ce.canAddrEnc(e, v, opts)
- } else {
- ce.elseEnc(e, v, opts)
- }
-}
-
-// newCondAddrEncoder returns an encoder that checks whether its value
-// CanAddr and delegates to canAddrEnc if so, else to elseEnc.
-func newCondAddrEncoder(canAddrEnc, elseEnc encoderFunc) encoderFunc {
- enc := condAddrEncoder{canAddrEnc: canAddrEnc, elseEnc: elseEnc}
- return enc.encode
-}
-
-func isValidTag(s string) bool {
- if s == "" {
- return false
- }
- for _, c := range s {
- switch {
- case strings.ContainsRune("!#$%&()*+-./:<=>?@[]^_{|}~ ", c):
- // Backslash and quote chars are reserved, but
- // otherwise any punctuation chars are allowed
- // in a tag name.
- case !unicode.IsLetter(c) && !unicode.IsDigit(c):
- return false
- }
- }
- return true
-}
-
-func typeByIndex(t reflect.Type, index []int) reflect.Type {
- for _, i := range index {
- if t.Kind() == reflect.Ptr {
- t = t.Elem()
- }
- t = t.Field(i).Type
- }
- return t
-}
-
-type reflectWithString struct {
- v reflect.Value
- s string
-}
-
-func (w *reflectWithString) resolve() error {
- if w.v.Kind() == reflect.String {
- w.s = w.v.String()
- return nil
- }
- if tm, ok := w.v.Interface().(encoding.TextMarshaler); ok {
- buf, err := tm.MarshalText()
- w.s = string(buf)
- return err
- }
- switch w.v.Kind() {
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- w.s = strconv.FormatInt(w.v.Int(), 10)
- return nil
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- w.s = strconv.FormatUint(w.v.Uint(), 10)
- return nil
- }
- panic("unexpected map key type")
-}
-
-// NOTE: keep in sync with stringBytes below.
-func (e *encodeState) string(s string, escapeHTML bool) {
- e.WriteByte('"')
- start := 0
- for i := 0; i < len(s); {
- if b := s[i]; b < utf8.RuneSelf {
- if htmlSafeSet[b] || (!escapeHTML && safeSet[b]) {
- i++
- continue
- }
- if start < i {
- e.WriteString(s[start:i])
- }
- e.WriteByte('\\')
- switch b {
- case '\\', '"':
- e.WriteByte(b)
- case '\n':
- e.WriteByte('n')
- case '\r':
- e.WriteByte('r')
- case '\t':
- e.WriteByte('t')
- default:
- // This encodes bytes < 0x20 except for \t, \n and \r.
- // If escapeHTML is set, it also escapes <, >, and &
- // because they can lead to security holes when
- // user-controlled strings are rendered into JSON
- // and served to some browsers.
- e.WriteString(`u00`)
- e.WriteByte(hex[b>>4])
- e.WriteByte(hex[b&0xF])
- }
- i++
- start = i
- continue
- }
- c, size := utf8.DecodeRuneInString(s[i:])
- if c == utf8.RuneError && size == 1 {
- if start < i {
- e.WriteString(s[start:i])
- }
- e.WriteString(`\ufffd`)
- i += size
- start = i
- continue
- }
- // U+2028 is LINE SEPARATOR.
- // U+2029 is PARAGRAPH SEPARATOR.
- // They are both technically valid characters in JSON strings,
- // but don't work in JSONP, which has to be evaluated as JavaScript,
- // and can lead to security holes there. It is valid JSON to
- // escape them, so we do so unconditionally.
- // See http://timelessrepo.com/json-isnt-a-javascript-subset for discussion.
- if c == '\u2028' || c == '\u2029' {
- if start < i {
- e.WriteString(s[start:i])
- }
- e.WriteString(`\u202`)
- e.WriteByte(hex[c&0xF])
- i += size
- start = i
- continue
- }
- i += size
- }
- if start < len(s) {
- e.WriteString(s[start:])
- }
- e.WriteByte('"')
-}
-
-// NOTE: keep in sync with string above.
-func (e *encodeState) stringBytes(s []byte, escapeHTML bool) {
- e.WriteByte('"')
- start := 0
- for i := 0; i < len(s); {
- if b := s[i]; b < utf8.RuneSelf {
- if htmlSafeSet[b] || (!escapeHTML && safeSet[b]) {
- i++
- continue
- }
- if start < i {
- e.Write(s[start:i])
- }
- e.WriteByte('\\')
- switch b {
- case '\\', '"':
- e.WriteByte(b)
- case '\n':
- e.WriteByte('n')
- case '\r':
- e.WriteByte('r')
- case '\t':
- e.WriteByte('t')
- default:
- // This encodes bytes < 0x20 except for \t, \n and \r.
- // If escapeHTML is set, it also escapes <, >, and &
- // because they can lead to security holes when
- // user-controlled strings are rendered into JSON
- // and served to some browsers.
- e.WriteString(`u00`)
- e.WriteByte(hex[b>>4])
- e.WriteByte(hex[b&0xF])
- }
- i++
- start = i
- continue
- }
- c, size := utf8.DecodeRune(s[i:])
- if c == utf8.RuneError && size == 1 {
- if start < i {
- e.Write(s[start:i])
- }
- e.WriteString(`\ufffd`)
- i += size
- start = i
- continue
- }
- // U+2028 is LINE SEPARATOR.
- // U+2029 is PARAGRAPH SEPARATOR.
- // They are both technically valid characters in JSON strings,
- // but don't work in JSONP, which has to be evaluated as JavaScript,
- // and can lead to security holes there. It is valid JSON to
- // escape them, so we do so unconditionally.
- // See http://timelessrepo.com/json-isnt-a-javascript-subset for discussion.
- if c == '\u2028' || c == '\u2029' {
- if start < i {
- e.Write(s[start:i])
- }
- e.WriteString(`\u202`)
- e.WriteByte(hex[c&0xF])
- i += size
- start = i
- continue
- }
- i += size
- }
- if start < len(s) {
- e.Write(s[start:])
- }
- e.WriteByte('"')
-}
-
-// A field represents a single field found in a struct.
-type field struct {
- name string
- nameBytes []byte // []byte(name)
- equalFold func(s, t []byte) bool // bytes.EqualFold or equivalent
-
- nameNonEsc string // `"` + name + `":`
- nameEscHTML string // `"` + HTMLEscape(name) + `":`
-
- tag bool
- index []int
- typ reflect.Type
- omitEmpty bool
- quoted bool
-
- encoder encoderFunc
-}
-
-// byIndex sorts field by index sequence.
-type byIndex []field
-
-func (x byIndex) Len() int { return len(x) }
-
-func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
-
-func (x byIndex) Less(i, j int) bool {
- for k, xik := range x[i].index {
- if k >= len(x[j].index) {
- return false
- }
- if xik != x[j].index[k] {
- return xik < x[j].index[k]
- }
- }
- return len(x[i].index) < len(x[j].index)
-}
-
-// typeFields returns a list of fields that JSON should recognize for the given type.
-// The algorithm is breadth-first search over the set of structs to include - the top struct
-// and then any reachable anonymous structs.
-func typeFields(t reflect.Type) []field {
- // Anonymous fields to explore at the current level and the next.
- current := []field{}
- next := []field{{typ: t}}
-
- // Count of queued names for current level and the next.
- count := map[reflect.Type]int{}
- nextCount := map[reflect.Type]int{}
-
- // Types already visited at an earlier level.
- visited := map[reflect.Type]bool{}
-
- // Fields found.
- var fields []field
-
- // Buffer to run HTMLEscape on field names.
- var nameEscBuf bytes.Buffer
-
- for len(next) > 0 {
- current, next = next, current[:0]
- count, nextCount = nextCount, map[reflect.Type]int{}
-
- for _, f := range current {
- if visited[f.typ] {
- continue
- }
- visited[f.typ] = true
-
- // Scan f.typ for fields to include.
- for i := 0; i < f.typ.NumField(); i++ {
- sf := f.typ.Field(i)
- isUnexported := sf.PkgPath != ""
- if sf.Anonymous {
- t := sf.Type
- if t.Kind() == reflect.Ptr {
- t = t.Elem()
- }
- if isUnexported && t.Kind() != reflect.Struct {
- // Ignore embedded fields of unexported non-struct types.
- continue
- }
- // Do not ignore embedded fields of unexported struct types
- // since they may have exported fields.
- } else if isUnexported {
- // Ignore unexported non-embedded fields.
- continue
- }
- tag := sf.Tag.Get("json")
- if tag == "-" {
- continue
- }
- name, opts := parseTag(tag)
- if !isValidTag(name) {
- name = ""
- }
- index := make([]int, len(f.index)+1)
- copy(index, f.index)
- index[len(f.index)] = i
-
- ft := sf.Type
- if ft.Name() == "" && ft.Kind() == reflect.Ptr {
- // Follow pointer.
- ft = ft.Elem()
- }
-
- // Only strings, floats, integers, and booleans can be quoted.
- quoted := false
- if opts.Contains("string") {
- switch ft.Kind() {
- case reflect.Bool,
- reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
- reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
- reflect.Float32, reflect.Float64,
- reflect.String:
- quoted = true
- }
- }
-
- // Record found field and index sequence.
- if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct {
- tagged := name != ""
- if name == "" {
- name = sf.Name
- }
- field := field{
- name: name,
- tag: tagged,
- index: index,
- typ: ft,
- omitEmpty: opts.Contains("omitempty"),
- quoted: quoted,
- }
- field.nameBytes = []byte(field.name)
- field.equalFold = foldFunc(field.nameBytes)
-
- // Build nameEscHTML and nameNonEsc ahead of time.
- nameEscBuf.Reset()
- nameEscBuf.WriteString(`"`)
- HTMLEscape(&nameEscBuf, field.nameBytes)
- nameEscBuf.WriteString(`":`)
- field.nameEscHTML = nameEscBuf.String()
- field.nameNonEsc = `"` + field.name + `":`
-
- fields = append(fields, field)
- if count[f.typ] > 1 {
- // If there were multiple instances, add a second,
- // so that the annihilation code will see a duplicate.
- // It only cares about the distinction between 1 or 2,
- // so don't bother generating any more copies.
- fields = append(fields, fields[len(fields)-1])
- }
- continue
- }
-
- // Record new anonymous struct to explore in next round.
- nextCount[ft]++
- if nextCount[ft] == 1 {
- next = append(next, field{name: ft.Name(), index: index, typ: ft})
- }
- }
- }
- }
-
- sort.Slice(fields, func(i, j int) bool {
- x := fields
- // sort field by name, breaking ties with depth, then
- // breaking ties with "name came from json tag", then
- // breaking ties with index sequence.
- if x[i].name != x[j].name {
- return x[i].name < x[j].name
- }
- if len(x[i].index) != len(x[j].index) {
- return len(x[i].index) < len(x[j].index)
- }
- if x[i].tag != x[j].tag {
- return x[i].tag
- }
- return byIndex(x).Less(i, j)
- })
-
- // Delete all fields that are hidden by the Go rules for embedded fields,
- // except that fields with JSON tags are promoted.
-
- // The fields are sorted in primary order of name, secondary order
- // of field index length. Loop over names; for each name, delete
- // hidden fields by choosing the one dominant field that survives.
- out := fields[:0]
- for advance, i := 0, 0; i < len(fields); i += advance {
- // One iteration per name.
- // Find the sequence of fields with the name of this first field.
- fi := fields[i]
- name := fi.name
- for advance = 1; i+advance < len(fields); advance++ {
- fj := fields[i+advance]
- if fj.name != name {
- break
- }
- }
- if advance == 1 { // Only one field with this name
- out = append(out, fi)
- continue
- }
- dominant, ok := dominantField(fields[i : i+advance])
- if ok {
- out = append(out, dominant)
- }
- }
-
- fields = out
- sort.Sort(byIndex(fields))
-
- for i := range fields {
- f := &fields[i]
- f.encoder = typeEncoder(typeByIndex(t, f.index))
- }
- return fields
-}
-
-// dominantField looks through the fields, all of which are known to
-// have the same name, to find the single field that dominates the
-// others using Go's embedding rules, modified by the presence of
-// JSON tags. If there are multiple top-level fields, the boolean
-// will be false: This condition is an error in Go and we skip all
-// the fields.
-func dominantField(fields []field) (field, bool) {
- // The fields are sorted in increasing index-length order, then by presence of tag.
- // That means that the first field is the dominant one. We need only check
- // for error cases: two fields at top level, either both tagged or neither tagged.
- if len(fields) > 1 && len(fields[0].index) == len(fields[1].index) && fields[0].tag == fields[1].tag {
- return field{}, false
- }
- return fields[0], true
-}
-
-var fieldCache sync.Map // map[reflect.Type][]field
-
-// cachedTypeFields is like typeFields but uses a cache to avoid repeated work.
-func cachedTypeFields(t reflect.Type) []field {
- if f, ok := fieldCache.Load(t); ok {
- return f.([]field)
- }
- f, _ := fieldCache.LoadOrStore(t, typeFields(t))
- return f.([]field)
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/encode_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/encode_test.go
deleted file mode 100644
index cd5eadf..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/encode_test.go
+++ /dev/null
@@ -1,1025 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "fmt"
- "log"
- "math"
- "reflect"
- "regexp"
- "strconv"
- "testing"
- "unicode"
-)
-
-type Optionals struct {
- Sr string `json:"sr"`
- So string `json:"so,omitempty"`
- Sw string `json:"-"`
-
- Ir int `json:"omitempty"` // actually named omitempty, not an option
- Io int `json:"io,omitempty"`
-
- Slr []string `json:"slr,random"`
- Slo []string `json:"slo,omitempty"`
-
- Mr map[string]interface{} `json:"mr"`
- Mo map[string]interface{} `json:",omitempty"`
-
- Fr float64 `json:"fr"`
- Fo float64 `json:"fo,omitempty"`
-
- Br bool `json:"br"`
- Bo bool `json:"bo,omitempty"`
-
- Ur uint `json:"ur"`
- Uo uint `json:"uo,omitempty"`
-
- Str struct{} `json:"str"`
- Sto struct{} `json:"sto,omitempty"`
-}
-
-var optionalsExpected = `{
- "sr": "",
- "omitempty": 0,
- "slr": null,
- "mr": {},
- "fr": 0,
- "br": false,
- "ur": 0,
- "str": {},
- "sto": {}
-}`
-
-func TestOmitEmpty(t *testing.T) {
- var o Optionals
- o.Sw = "something"
- o.Mr = map[string]interface{}{}
- o.Mo = map[string]interface{}{}
-
- got, err := MarshalIndent(&o, "", " ")
- if err != nil {
- t.Fatal(err)
- }
- if got := string(got); got != optionalsExpected {
- t.Errorf(" got: %s\nwant: %s\n", got, optionalsExpected)
- }
-}
-
-type StringTag struct {
- BoolStr bool `json:",string"`
- IntStr int64 `json:",string"`
- UintptrStr uintptr `json:",string"`
- StrStr string `json:",string"`
-}
-
-var stringTagExpected = `{
- "BoolStr": "true",
- "IntStr": "42",
- "UintptrStr": "44",
- "StrStr": "\"xzbit\""
-}`
-
-func TestStringTag(t *testing.T) {
- var s StringTag
- s.BoolStr = true
- s.IntStr = 42
- s.UintptrStr = 44
- s.StrStr = "xzbit"
- got, err := MarshalIndent(&s, "", " ")
- if err != nil {
- t.Fatal(err)
- }
- if got := string(got); got != stringTagExpected {
- t.Fatalf(" got: %s\nwant: %s\n", got, stringTagExpected)
- }
-
- // Verify that it round-trips.
- var s2 StringTag
- err = NewDecoder(bytes.NewReader(got)).Decode(&s2)
- if err != nil {
- t.Fatalf("Decode: %v", err)
- }
- if !reflect.DeepEqual(s, s2) {
- t.Fatalf("decode didn't match.\nsource: %#v\nEncoded as:\n%s\ndecode: %#v", s, string(got), s2)
- }
-}
-
-// byte slices are special even if they're renamed types.
-type renamedByte byte
-type renamedByteSlice []byte
-type renamedRenamedByteSlice []renamedByte
-
-func TestEncodeRenamedByteSlice(t *testing.T) {
- s := renamedByteSlice("abc")
- result, err := Marshal(s)
- if err != nil {
- t.Fatal(err)
- }
- expect := `"YWJj"`
- if string(result) != expect {
- t.Errorf(" got %s want %s", result, expect)
- }
- r := renamedRenamedByteSlice("abc")
- result, err = Marshal(r)
- if err != nil {
- t.Fatal(err)
- }
- if string(result) != expect {
- t.Errorf(" got %s want %s", result, expect)
- }
-}
-
-var unsupportedValues = []interface{}{
- math.NaN(),
- math.Inf(-1),
- math.Inf(1),
-}
-
-func TestUnsupportedValues(t *testing.T) {
- for _, v := range unsupportedValues {
- if _, err := Marshal(v); err != nil {
- if _, ok := err.(*UnsupportedValueError); !ok {
- t.Errorf("for %v, got %T want UnsupportedValueError", v, err)
- }
- } else {
- t.Errorf("for %v, expected error", v)
- }
- }
-}
-
-// Ref has Marshaler and Unmarshaler methods with pointer receiver.
-type Ref int
-
-func (*Ref) MarshalJSON() ([]byte, error) {
- return []byte(`"ref"`), nil
-}
-
-func (r *Ref) UnmarshalJSON([]byte) error {
- *r = 12
- return nil
-}
-
-// Val has Marshaler methods with value receiver.
-type Val int
-
-func (Val) MarshalJSON() ([]byte, error) {
- return []byte(`"val"`), nil
-}
-
-// RefText has Marshaler and Unmarshaler methods with pointer receiver.
-type RefText int
-
-func (*RefText) MarshalText() ([]byte, error) {
- return []byte(`"ref"`), nil
-}
-
-func (r *RefText) UnmarshalText([]byte) error {
- *r = 13
- return nil
-}
-
-// ValText has Marshaler methods with value receiver.
-type ValText int
-
-func (ValText) MarshalText() ([]byte, error) {
- return []byte(`"val"`), nil
-}
-
-func TestRefValMarshal(t *testing.T) {
- var s = struct {
- R0 Ref
- R1 *Ref
- R2 RefText
- R3 *RefText
- V0 Val
- V1 *Val
- V2 ValText
- V3 *ValText
- }{
- R0: 12,
- R1: new(Ref),
- R2: 14,
- R3: new(RefText),
- V0: 13,
- V1: new(Val),
- V2: 15,
- V3: new(ValText),
- }
- const want = `{"R0":"ref","R1":"ref","R2":"\"ref\"","R3":"\"ref\"","V0":"val","V1":"val","V2":"\"val\"","V3":"\"val\""}`
- b, err := Marshal(&s)
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
- if got := string(b); got != want {
- t.Errorf("got %q, want %q", got, want)
- }
-}
-
-// C implements Marshaler and returns unescaped JSON.
-type C int
-
-func (C) MarshalJSON() ([]byte, error) {
- return []byte(`"<&>"`), nil
-}
-
-// CText implements Marshaler and returns unescaped text.
-type CText int
-
-func (CText) MarshalText() ([]byte, error) {
- return []byte(`"<&>"`), nil
-}
-
-func TestMarshalerEscaping(t *testing.T) {
- var c C
- want := `"\u003c\u0026\u003e"`
- b, err := Marshal(c)
- if err != nil {
- t.Fatalf("Marshal(c): %v", err)
- }
- if got := string(b); got != want {
- t.Errorf("Marshal(c) = %#q, want %#q", got, want)
- }
-
- var ct CText
- want = `"\"\u003c\u0026\u003e\""`
- b, err = Marshal(ct)
- if err != nil {
- t.Fatalf("Marshal(ct): %v", err)
- }
- if got := string(b); got != want {
- t.Errorf("Marshal(ct) = %#q, want %#q", got, want)
- }
-}
-
-func TestAnonymousFields(t *testing.T) {
- tests := []struct {
- label string // Test name
- makeInput func() interface{} // Function to create input value
- want string // Expected JSON output
- }{{
- // Both S1 and S2 have a field named X. From the perspective of S,
- // it is ambiguous which one X refers to.
- // This should not serialize either field.
- label: "AmbiguousField",
- makeInput: func() interface{} {
- type (
- S1 struct{ x, X int }
- S2 struct{ x, X int }
- S struct {
- S1
- S2
- }
- )
- return S{S1{1, 2}, S2{3, 4}}
- },
- want: `{}`,
- }, {
- label: "DominantField",
- // Both S1 and S2 have a field named X, but since S has an X field as
- // well, it takes precedence over S1.X and S2.X.
- makeInput: func() interface{} {
- type (
- S1 struct{ x, X int }
- S2 struct{ x, X int }
- S struct {
- S1
- S2
- x, X int
- }
- )
- return S{S1{1, 2}, S2{3, 4}, 5, 6}
- },
- want: `{"X":6}`,
- }, {
- // Unexported embedded field of non-struct type should not be serialized.
- label: "UnexportedEmbeddedInt",
- makeInput: func() interface{} {
- type (
- myInt int
- S struct{ myInt }
- )
- return S{5}
- },
- want: `{}`,
- }, {
- // Exported embedded field of non-struct type should be serialized.
- label: "ExportedEmbeddedInt",
- makeInput: func() interface{} {
- type (
- MyInt int
- S struct{ MyInt }
- )
- return S{5}
- },
- want: `{"MyInt":5}`,
- }, {
- // Unexported embedded field of pointer to non-struct type
- // should not be serialized.
- label: "UnexportedEmbeddedIntPointer",
- makeInput: func() interface{} {
- type (
- myInt int
- S struct{ *myInt }
- )
- s := S{new(myInt)}
- *s.myInt = 5
- return s
- },
- want: `{}`,
- }, {
- // Exported embedded field of pointer to non-struct type
- // should be serialized.
- label: "ExportedEmbeddedIntPointer",
- makeInput: func() interface{} {
- type (
- MyInt int
- S struct{ *MyInt }
- )
- s := S{new(MyInt)}
- *s.MyInt = 5
- return s
- },
- want: `{"MyInt":5}`,
- }, {
- // Exported fields of embedded structs should have their
- // exported fields be serialized regardless of whether the struct types
- // themselves are exported.
- label: "EmbeddedStruct",
- makeInput: func() interface{} {
- type (
- s1 struct{ x, X int }
- S2 struct{ y, Y int }
- S struct {
- s1
- S2
- }
- )
- return S{s1{1, 2}, S2{3, 4}}
- },
- want: `{"X":2,"Y":4}`,
- }, {
- // Exported fields of pointers to embedded structs should have their
- // exported fields be serialized regardless of whether the struct types
- // themselves are exported.
- label: "EmbeddedStructPointer",
- makeInput: func() interface{} {
- type (
- s1 struct{ x, X int }
- S2 struct{ y, Y int }
- S struct {
- *s1
- *S2
- }
- )
- return S{&s1{1, 2}, &S2{3, 4}}
- },
- want: `{"X":2,"Y":4}`,
- }, {
- // Exported fields on embedded unexported structs at multiple levels
- // of nesting should still be serialized.
- label: "NestedStructAndInts",
- makeInput: func() interface{} {
- type (
- MyInt1 int
- MyInt2 int
- myInt int
- s2 struct {
- MyInt2
- myInt
- }
- s1 struct {
- MyInt1
- myInt
- s2
- }
- S struct {
- s1
- myInt
- }
- )
- return S{s1{1, 2, s2{3, 4}}, 6}
- },
- want: `{"MyInt1":1,"MyInt2":3}`,
- }, {
- // If an anonymous struct pointer field is nil, we should ignore
- // the embedded fields behind it. Not properly doing so may
- // result in the wrong output or reflect panics.
- label: "EmbeddedFieldBehindNilPointer",
- makeInput: func() interface{} {
- type (
- S2 struct{ Field string }
- S struct{ *S2 }
- )
- return S{}
- },
- want: `{}`,
- }}
-
- for _, tt := range tests {
- t.Run(tt.label, func(t *testing.T) {
- b, err := Marshal(tt.makeInput())
- if err != nil {
- t.Fatalf("Marshal() = %v, want nil error", err)
- }
- if string(b) != tt.want {
- t.Fatalf("Marshal() = %q, want %q", b, tt.want)
- }
- })
- }
-}
-
-type BugA struct {
- S string
-}
-
-type BugB struct {
- BugA
- S string
-}
-
-type BugC struct {
- S string
-}
-
-// Legal Go: We never use the repeated embedded field (S).
-type BugX struct {
- A int
- BugA
- BugB
-}
-
-// Issue 16042. Even if a nil interface value is passed in
-// as long as it implements MarshalJSON, it should be marshaled.
-type nilMarshaler string
-
-func (nm *nilMarshaler) MarshalJSON() ([]byte, error) {
- if nm == nil {
- return Marshal("0zenil0")
- }
- return Marshal("zenil:" + string(*nm))
-}
-
-// Issue 16042.
-func TestNilMarshal(t *testing.T) {
- testCases := []struct {
- v interface{}
- want string
- }{
- {v: nil, want: `null`},
- {v: new(float64), want: `0`},
- {v: []interface{}(nil), want: `null`},
- {v: []string(nil), want: `null`},
- {v: map[string]string(nil), want: `null`},
- {v: []byte(nil), want: `null`},
- {v: struct{ M string }{"gopher"}, want: `{"M":"gopher"}`},
- {v: struct{ M Marshaler }{}, want: `{"M":null}`},
- {v: struct{ M Marshaler }{(*nilMarshaler)(nil)}, want: `{"M":"0zenil0"}`},
- {v: struct{ M interface{} }{(*nilMarshaler)(nil)}, want: `{"M":null}`},
- }
-
- for _, tt := range testCases {
- out, err := Marshal(tt.v)
- if err != nil || string(out) != tt.want {
- t.Errorf("Marshal(%#v) = %#q, %#v, want %#q, nil", tt.v, out, err, tt.want)
- continue
- }
- }
-}
-
-// Issue 5245.
-func TestEmbeddedBug(t *testing.T) {
- v := BugB{
- BugA{"A"},
- "B",
- }
- b, err := Marshal(v)
- if err != nil {
- t.Fatal("Marshal:", err)
- }
- want := `{"S":"B"}`
- got := string(b)
- if got != want {
- t.Fatalf("Marshal: got %s want %s", got, want)
- }
- // Now check that the duplicate field, S, does not appear.
- x := BugX{
- A: 23,
- }
- b, err = Marshal(x)
- if err != nil {
- t.Fatal("Marshal:", err)
- }
- want = `{"A":23}`
- got = string(b)
- if got != want {
- t.Fatalf("Marshal: got %s want %s", got, want)
- }
-}
-
-type BugD struct { // Same as BugA after tagging.
- XXX string `json:"S"`
-}
-
-// BugD's tagged S field should dominate BugA's.
-type BugY struct {
- BugA
- BugD
-}
-
-// Test that a field with a tag dominates untagged fields.
-func TestTaggedFieldDominates(t *testing.T) {
- v := BugY{
- BugA{"BugA"},
- BugD{"BugD"},
- }
- b, err := Marshal(v)
- if err != nil {
- t.Fatal("Marshal:", err)
- }
- want := `{"S":"BugD"}`
- got := string(b)
- if got != want {
- t.Fatalf("Marshal: got %s want %s", got, want)
- }
-}
-
-// There are no tags here, so S should not appear.
-type BugZ struct {
- BugA
- BugC
- BugY // Contains a tagged S field through BugD; should not dominate.
-}
-
-func TestDuplicatedFieldDisappears(t *testing.T) {
- v := BugZ{
- BugA{"BugA"},
- BugC{"BugC"},
- BugY{
- BugA{"nested BugA"},
- BugD{"nested BugD"},
- },
- }
- b, err := Marshal(v)
- if err != nil {
- t.Fatal("Marshal:", err)
- }
- want := `{}`
- got := string(b)
- if got != want {
- t.Fatalf("Marshal: got %s want %s", got, want)
- }
-}
-
-func TestStringBytes(t *testing.T) {
- t.Parallel()
- // Test that encodeState.stringBytes and encodeState.string use the same encoding.
- var r []rune
- for i := '\u0000'; i <= unicode.MaxRune; i++ {
- r = append(r, i)
- }
- s := string(r) + "\xff\xff\xffhello" // some invalid UTF-8 too
-
- for _, escapeHTML := range []bool{true, false} {
- es := &encodeState{}
- es.string(s, escapeHTML)
-
- esBytes := &encodeState{}
- esBytes.stringBytes([]byte(s), escapeHTML)
-
- enc := es.Buffer.String()
- encBytes := esBytes.Buffer.String()
- if enc != encBytes {
- i := 0
- for i < len(enc) && i < len(encBytes) && enc[i] == encBytes[i] {
- i++
- }
- enc = enc[i:]
- encBytes = encBytes[i:]
- i = 0
- for i < len(enc) && i < len(encBytes) && enc[len(enc)-i-1] == encBytes[len(encBytes)-i-1] {
- i++
- }
- enc = enc[:len(enc)-i]
- encBytes = encBytes[:len(encBytes)-i]
-
- if len(enc) > 20 {
- enc = enc[:20] + "..."
- }
- if len(encBytes) > 20 {
- encBytes = encBytes[:20] + "..."
- }
-
- t.Errorf("with escapeHTML=%t, encodings differ at %#q vs %#q",
- escapeHTML, enc, encBytes)
- }
- }
-}
-
-func TestIssue10281(t *testing.T) {
- type Foo struct {
- N Number
- }
- x := Foo{Number(`invalid`)}
-
- b, err := Marshal(&x)
- if err == nil {
- t.Errorf("Marshal(&x) = %#q; want error", b)
- }
-}
-
-func TestHTMLEscape(t *testing.T) {
- var b, want bytes.Buffer
- m := `{"M":"<html>foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `</html>"}`
- want.Write([]byte(`{"M":"\u003chtml\u003efoo \u0026\u2028 \u2029\u003c/html\u003e"}`))
- HTMLEscape(&b, []byte(m))
- if !bytes.Equal(b.Bytes(), want.Bytes()) {
- t.Errorf("HTMLEscape(&b, []byte(m)) = %s; want %s", b.Bytes(), want.Bytes())
- }
-}
-
-// golang.org/issue/8582
-func TestEncodePointerString(t *testing.T) {
- type stringPointer struct {
- N *int64 `json:"n,string"`
- }
- var n int64 = 42
- b, err := Marshal(stringPointer{N: &n})
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
- if got, want := string(b), `{"n":"42"}`; got != want {
- t.Errorf("Marshal = %s, want %s", got, want)
- }
- var back stringPointer
- err = Unmarshal(b, &back)
- if err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if back.N == nil {
- t.Fatalf("Unmarshaled nil N field")
- }
- if *back.N != 42 {
- t.Fatalf("*N = %d; want 42", *back.N)
- }
-}
-
-var encodeStringTests = []struct {
- in string
- out string
-}{
- {"\x00", `"\u0000"`},
- {"\x01", `"\u0001"`},
- {"\x02", `"\u0002"`},
- {"\x03", `"\u0003"`},
- {"\x04", `"\u0004"`},
- {"\x05", `"\u0005"`},
- {"\x06", `"\u0006"`},
- {"\x07", `"\u0007"`},
- {"\x08", `"\u0008"`},
- {"\x09", `"\t"`},
- {"\x0a", `"\n"`},
- {"\x0b", `"\u000b"`},
- {"\x0c", `"\u000c"`},
- {"\x0d", `"\r"`},
- {"\x0e", `"\u000e"`},
- {"\x0f", `"\u000f"`},
- {"\x10", `"\u0010"`},
- {"\x11", `"\u0011"`},
- {"\x12", `"\u0012"`},
- {"\x13", `"\u0013"`},
- {"\x14", `"\u0014"`},
- {"\x15", `"\u0015"`},
- {"\x16", `"\u0016"`},
- {"\x17", `"\u0017"`},
- {"\x18", `"\u0018"`},
- {"\x19", `"\u0019"`},
- {"\x1a", `"\u001a"`},
- {"\x1b", `"\u001b"`},
- {"\x1c", `"\u001c"`},
- {"\x1d", `"\u001d"`},
- {"\x1e", `"\u001e"`},
- {"\x1f", `"\u001f"`},
-}
-
-func TestEncodeString(t *testing.T) {
- for _, tt := range encodeStringTests {
- b, err := Marshal(tt.in)
- if err != nil {
- t.Errorf("Marshal(%q): %v", tt.in, err)
- continue
- }
- out := string(b)
- if out != tt.out {
- t.Errorf("Marshal(%q) = %#q, want %#q", tt.in, out, tt.out)
- }
- }
-}
-
-type jsonbyte byte
-
-func (b jsonbyte) MarshalJSON() ([]byte, error) { return tenc(`{"JB":%d}`, b) }
-
-type textbyte byte
-
-func (b textbyte) MarshalText() ([]byte, error) { return tenc(`TB:%d`, b) }
-
-type jsonint int
-
-func (i jsonint) MarshalJSON() ([]byte, error) { return tenc(`{"JI":%d}`, i) }
-
-type textint int
-
-func (i textint) MarshalText() ([]byte, error) { return tenc(`TI:%d`, i) }
-
-func tenc(format string, a ...interface{}) ([]byte, error) {
- var buf bytes.Buffer
- fmt.Fprintf(&buf, format, a...)
- return buf.Bytes(), nil
-}
-
-// Issue 13783
-func TestEncodeBytekind(t *testing.T) {
- testdata := []struct {
- data interface{}
- want string
- }{
- {byte(7), "7"},
- {jsonbyte(7), `{"JB":7}`},
- {textbyte(4), `"TB:4"`},
- {jsonint(5), `{"JI":5}`},
- {textint(1), `"TI:1"`},
- {[]byte{0, 1}, `"AAE="`},
- {[]jsonbyte{0, 1}, `[{"JB":0},{"JB":1}]`},
- {[][]jsonbyte{{0, 1}, {3}}, `[[{"JB":0},{"JB":1}],[{"JB":3}]]`},
- {[]textbyte{2, 3}, `["TB:2","TB:3"]`},
- {[]jsonint{5, 4}, `[{"JI":5},{"JI":4}]`},
- {[]textint{9, 3}, `["TI:9","TI:3"]`},
- {[]int{9, 3}, `[9,3]`},
- }
- for _, d := range testdata {
- js, err := Marshal(d.data)
- if err != nil {
- t.Error(err)
- continue
- }
- got, want := string(js), d.want
- if got != want {
- t.Errorf("got %s, want %s", got, want)
- }
- }
-}
-
-func TestTextMarshalerMapKeysAreSorted(t *testing.T) {
- b, err := Marshal(map[unmarshalerText]int{
- {"x", "y"}: 1,
- {"y", "x"}: 2,
- {"a", "z"}: 3,
- {"z", "a"}: 4,
- })
- if err != nil {
- t.Fatalf("Failed to Marshal text.Marshaler: %v", err)
- }
- const want = `{"a:z":3,"x:y":1,"y:x":2,"z:a":4}`
- if string(b) != want {
- t.Errorf("Marshal map with text.Marshaler keys: got %#q, want %#q", b, want)
- }
-}
-
-var re = regexp.MustCompile
-
-// syntactic checks on form of marshaled floating point numbers.
-var badFloatREs = []*regexp.Regexp{
- re(`p`), // no binary exponential notation
- re(`^\+`), // no leading + sign
- re(`^-?0[^.]`), // no unnecessary leading zeros
- re(`^-?\.`), // leading zero required before decimal point
- re(`\.(e|$)`), // no trailing decimal
- re(`\.[0-9]+0(e|$)`), // no trailing zero in fraction
- re(`^-?(0|[0-9]{2,})\..*e`), // exponential notation must have normalized mantissa
- re(`e[0-9]`), // positive exponent must be signed
- re(`e[+-]0`), // exponent must not have leading zeros
- re(`e-[1-6]$`), // not tiny enough for exponential notation
- re(`e+(.|1.|20)$`), // not big enough for exponential notation
- re(`^-?0\.0000000`), // too tiny, should use exponential notation
- re(`^-?[0-9]{22}`), // too big, should use exponential notation
- re(`[1-9][0-9]{16}[1-9]`), // too many significant digits in integer
- re(`[1-9][0-9.]{17}[1-9]`), // too many significant digits in decimal
- // below here for float32 only
- re(`[1-9][0-9]{8}[1-9]`), // too many significant digits in integer
- re(`[1-9][0-9.]{9}[1-9]`), // too many significant digits in decimal
-}
-
-func TestMarshalFloat(t *testing.T) {
- t.Parallel()
- nfail := 0
- test := func(f float64, bits int) {
- vf := interface{}(f)
- if bits == 32 {
- f = float64(float32(f)) // round
- vf = float32(f)
- }
- bout, err := Marshal(vf)
- if err != nil {
- t.Errorf("Marshal(%T(%g)): %v", vf, vf, err)
- nfail++
- return
- }
- out := string(bout)
-
- // result must convert back to the same float
- g, err := strconv.ParseFloat(out, bits)
- if err != nil {
- t.Errorf("Marshal(%T(%g)) = %q, cannot parse back: %v", vf, vf, out, err)
- nfail++
- return
- }
- if f != g || fmt.Sprint(f) != fmt.Sprint(g) { // fmt.Sprint handles ±0
- t.Errorf("Marshal(%T(%g)) = %q (is %g, not %g)", vf, vf, out, float32(g), vf)
- nfail++
- return
- }
-
- bad := badFloatREs
- if bits == 64 {
- bad = bad[:len(bad)-2]
- }
- for _, re := range bad {
- if re.MatchString(out) {
- t.Errorf("Marshal(%T(%g)) = %q, must not match /%s/", vf, vf, out, re)
- nfail++
- return
- }
- }
- }
-
- var (
- bigger = math.Inf(+1)
- smaller = math.Inf(-1)
- )
-
- var digits = "1.2345678901234567890123"
- for i := len(digits); i >= 2; i-- {
- for exp := -30; exp <= 30; exp++ {
- for _, sign := range "+-" {
- for bits := 32; bits <= 64; bits += 32 {
- s := fmt.Sprintf("%c%se%d", sign, digits[:i], exp)
- f, err := strconv.ParseFloat(s, bits)
- if err != nil {
- log.Fatal(err)
- }
- next := math.Nextafter
- if bits == 32 {
- next = func(g, h float64) float64 {
- return float64(math.Nextafter32(float32(g), float32(h)))
- }
- }
- test(f, bits)
- test(next(f, bigger), bits)
- test(next(f, smaller), bits)
- if nfail > 50 {
- t.Fatalf("stopping test early")
- }
- }
- }
- }
- }
- test(0, 64)
- test(math.Copysign(0, -1), 64)
- test(0, 32)
- test(math.Copysign(0, -1), 32)
-}
-
-func TestMarshalRawMessageValue(t *testing.T) {
- type (
- T1 struct {
- M RawMessage `json:",omitempty"`
- }
- T2 struct {
- M *RawMessage `json:",omitempty"`
- }
- )
-
- var (
- rawNil = RawMessage(nil)
- rawEmpty = RawMessage([]byte{})
- rawText = RawMessage([]byte(`"foo"`))
- )
-
- tests := []struct {
- in interface{}
- want string
- ok bool
- }{
- // Test with nil RawMessage.
- {rawNil, "null", true},
- {&rawNil, "null", true},
- {[]interface{}{rawNil}, "[null]", true},
- {&[]interface{}{rawNil}, "[null]", true},
- {[]interface{}{&rawNil}, "[null]", true},
- {&[]interface{}{&rawNil}, "[null]", true},
- {struct{ M RawMessage }{rawNil}, `{"M":null}`, true},
- {&struct{ M RawMessage }{rawNil}, `{"M":null}`, true},
- {struct{ M *RawMessage }{&rawNil}, `{"M":null}`, true},
- {&struct{ M *RawMessage }{&rawNil}, `{"M":null}`, true},
- {map[string]interface{}{"M": rawNil}, `{"M":null}`, true},
- {&map[string]interface{}{"M": rawNil}, `{"M":null}`, true},
- {map[string]interface{}{"M": &rawNil}, `{"M":null}`, true},
- {&map[string]interface{}{"M": &rawNil}, `{"M":null}`, true},
- {T1{rawNil}, "{}", true},
- {T2{&rawNil}, `{"M":null}`, true},
- {&T1{rawNil}, "{}", true},
- {&T2{&rawNil}, `{"M":null}`, true},
-
- // Test with empty, but non-nil, RawMessage.
- {rawEmpty, "", false},
- {&rawEmpty, "", false},
- {[]interface{}{rawEmpty}, "", false},
- {&[]interface{}{rawEmpty}, "", false},
- {[]interface{}{&rawEmpty}, "", false},
- {&[]interface{}{&rawEmpty}, "", false},
- {struct{ X RawMessage }{rawEmpty}, "", false},
- {&struct{ X RawMessage }{rawEmpty}, "", false},
- {struct{ X *RawMessage }{&rawEmpty}, "", false},
- {&struct{ X *RawMessage }{&rawEmpty}, "", false},
- {map[string]interface{}{"nil": rawEmpty}, "", false},
- {&map[string]interface{}{"nil": rawEmpty}, "", false},
- {map[string]interface{}{"nil": &rawEmpty}, "", false},
- {&map[string]interface{}{"nil": &rawEmpty}, "", false},
- {T1{rawEmpty}, "{}", true},
- {T2{&rawEmpty}, "", false},
- {&T1{rawEmpty}, "{}", true},
- {&T2{&rawEmpty}, "", false},
-
- // Test with RawMessage with some text.
- //
- // The tests below marked with Issue6458 used to generate "ImZvbyI=" instead "foo".
- // This behavior was intentionally changed in Go 1.8.
- // See https://golang.org/issues/14493#issuecomment-255857318
- {rawText, `"foo"`, true}, // Issue6458
- {&rawText, `"foo"`, true},
- {[]interface{}{rawText}, `["foo"]`, true}, // Issue6458
- {&[]interface{}{rawText}, `["foo"]`, true}, // Issue6458
- {[]interface{}{&rawText}, `["foo"]`, true},
- {&[]interface{}{&rawText}, `["foo"]`, true},
- {struct{ M RawMessage }{rawText}, `{"M":"foo"}`, true}, // Issue6458
- {&struct{ M RawMessage }{rawText}, `{"M":"foo"}`, true},
- {struct{ M *RawMessage }{&rawText}, `{"M":"foo"}`, true},
- {&struct{ M *RawMessage }{&rawText}, `{"M":"foo"}`, true},
- {map[string]interface{}{"M": rawText}, `{"M":"foo"}`, true}, // Issue6458
- {&map[string]interface{}{"M": rawText}, `{"M":"foo"}`, true}, // Issue6458
- {map[string]interface{}{"M": &rawText}, `{"M":"foo"}`, true},
- {&map[string]interface{}{"M": &rawText}, `{"M":"foo"}`, true},
- {T1{rawText}, `{"M":"foo"}`, true}, // Issue6458
- {T2{&rawText}, `{"M":"foo"}`, true},
- {&T1{rawText}, `{"M":"foo"}`, true},
- {&T2{&rawText}, `{"M":"foo"}`, true},
- }
-
- for i, tt := range tests {
- b, err := Marshal(tt.in)
- if ok := (err == nil); ok != tt.ok {
- if err != nil {
- t.Errorf("test %d, unexpected failure: %v", i, err)
- } else {
- t.Errorf("test %d, unexpected success", i)
- }
- }
- if got := string(b); got != tt.want {
- t.Errorf("test %d, Marshal(%#v) = %q, want %q", i, tt.in, got, tt.want)
- }
- }
-}
-
-type marshalPanic struct{}
-
-func (marshalPanic) MarshalJSON() ([]byte, error) { panic(0xdead) }
-
-func TestMarshalPanic(t *testing.T) {
- defer func() {
- if got := recover(); !reflect.DeepEqual(got, 0xdead) {
- t.Errorf("panic() = (%T)(%v), want 0xdead", got, got)
- }
- }()
- Marshal(&marshalPanic{})
- t.Error("Marshal should have panicked")
-}
-
-func TestMarshalUncommonFieldNames(t *testing.T) {
- v := struct {
- A0, À, Aβ int
- }{}
- b, err := Marshal(v)
- if err != nil {
- t.Fatal("Marshal:", err)
- }
- want := `{"A0":0,"À":0,"Aβ":0}`
- got := string(b)
- if got != want {
- t.Fatalf("Marshal: got %s want %s", got, want)
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_marshaling_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_marshaling_test.go
deleted file mode 100644
index 7f15c74..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_marshaling_test.go
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json_test
-
-import (
- "encoding/json"
- "fmt"
- "log"
- "strings"
-)
-
-type Animal int
-
-const (
- Unknown Animal = iota
- Gopher
- Zebra
-)
-
-func (a *Animal) UnmarshalJSON(b []byte) error {
- var s string
- if err := json.Unmarshal(b, &s); err != nil {
- return err
- }
- switch strings.ToLower(s) {
- default:
- *a = Unknown
- case "gopher":
- *a = Gopher
- case "zebra":
- *a = Zebra
- }
-
- return nil
-}
-
-func (a Animal) MarshalJSON() ([]byte, error) {
- var s string
- switch a {
- default:
- s = "unknown"
- case Gopher:
- s = "gopher"
- case Zebra:
- s = "zebra"
- }
-
- return json.Marshal(s)
-}
-
-func Example_customMarshalJSON() {
- blob := `["gopher","armadillo","zebra","unknown","gopher","bee","gopher","zebra"]`
- var zoo []Animal
- if err := json.Unmarshal([]byte(blob), &zoo); err != nil {
- log.Fatal(err)
- }
-
- census := make(map[Animal]int)
- for _, animal := range zoo {
- census[animal] += 1
- }
-
- fmt.Printf("Zoo Census:\n* Gophers: %d\n* Zebras: %d\n* Unknown: %d\n",
- census[Gopher], census[Zebra], census[Unknown])
-
- // Output:
- // Zoo Census:
- // * Gophers: 3
- // * Zebras: 2
- // * Unknown: 3
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_test.go
deleted file mode 100644
index 2031cba..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_test.go
+++ /dev/null
@@ -1,303 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json_test
-
-import (
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "log"
- "os"
- "strings"
-)
-
-func ExampleMarshal() {
- type ColorGroup struct {
- ID int
- Name string
- Colors []string
- }
- group := ColorGroup{
- ID: 1,
- Name: "Reds",
- Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
- }
- b, err := json.Marshal(group)
- if err != nil {
- fmt.Println("error:", err)
- }
- os.Stdout.Write(b)
- // Output:
- // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}
-}
-
-func ExampleUnmarshal() {
- var jsonBlob = []byte(`[
- {"Name": "Platypus", "Order": "Monotremata"},
- {"Name": "Quoll", "Order": "Dasyuromorphia"}
-]`)
- type Animal struct {
- Name string
- Order string
- }
- var animals []Animal
- err := json.Unmarshal(jsonBlob, &animals)
- if err != nil {
- fmt.Println("error:", err)
- }
- fmt.Printf("%+v", animals)
- // Output:
- // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
-}
-
-// This example uses a Decoder to decode a stream of distinct JSON values.
-func ExampleDecoder() {
- const jsonStream = `
- {"Name": "Ed", "Text": "Knock knock."}
- {"Name": "Sam", "Text": "Who's there?"}
- {"Name": "Ed", "Text": "Go fmt."}
- {"Name": "Sam", "Text": "Go fmt who?"}
- {"Name": "Ed", "Text": "Go fmt yourself!"}
-`
- type Message struct {
- Name, Text string
- }
- dec := json.NewDecoder(strings.NewReader(jsonStream))
- for {
- var m Message
- if err := dec.Decode(&m); err == io.EOF {
- break
- } else if err != nil {
- log.Fatal(err)
- }
- fmt.Printf("%s: %s\n", m.Name, m.Text)
- }
- // Output:
- // Ed: Knock knock.
- // Sam: Who's there?
- // Ed: Go fmt.
- // Sam: Go fmt who?
- // Ed: Go fmt yourself!
-}
-
-// This example uses a Decoder to decode a stream of distinct JSON values.
-func ExampleDecoder_Token() {
- const jsonStream = `
- {"Message": "Hello", "Array": [1, 2, 3], "Null": null, "Number": 1.234}
-`
- dec := json.NewDecoder(strings.NewReader(jsonStream))
- for {
- t, err := dec.Token()
- if err == io.EOF {
- break
- }
- if err != nil {
- log.Fatal(err)
- }
- fmt.Printf("%T: %v", t, t)
- if dec.More() {
- fmt.Printf(" (more)")
- }
- fmt.Printf("\n")
- }
- // Output:
- // json.Delim: { (more)
- // string: Message (more)
- // string: Hello (more)
- // string: Array (more)
- // json.Delim: [ (more)
- // float64: 1 (more)
- // float64: 2 (more)
- // float64: 3
- // json.Delim: ] (more)
- // string: Null (more)
- // <nil>: <nil> (more)
- // string: Number (more)
- // float64: 1.234
- // json.Delim: }
-}
-
-// This example uses a Decoder to decode a streaming array of JSON objects.
-func ExampleDecoder_Decode_stream() {
- const jsonStream = `
- [
- {"Name": "Ed", "Text": "Knock knock."},
- {"Name": "Sam", "Text": "Who's there?"},
- {"Name": "Ed", "Text": "Go fmt."},
- {"Name": "Sam", "Text": "Go fmt who?"},
- {"Name": "Ed", "Text": "Go fmt yourself!"}
- ]
-`
- type Message struct {
- Name, Text string
- }
- dec := json.NewDecoder(strings.NewReader(jsonStream))
-
- // read open bracket
- t, err := dec.Token()
- if err != nil {
- log.Fatal(err)
- }
- fmt.Printf("%T: %v\n", t, t)
-
- // while the array contains values
- for dec.More() {
- var m Message
- // decode an array value (Message)
- err := dec.Decode(&m)
- if err != nil {
- log.Fatal(err)
- }
-
- fmt.Printf("%v: %v\n", m.Name, m.Text)
- }
-
- // read closing bracket
- t, err = dec.Token()
- if err != nil {
- log.Fatal(err)
- }
- fmt.Printf("%T: %v\n", t, t)
-
- // Output:
- // json.Delim: [
- // Ed: Knock knock.
- // Sam: Who's there?
- // Ed: Go fmt.
- // Sam: Go fmt who?
- // Ed: Go fmt yourself!
- // json.Delim: ]
-
-}
-
-// This example uses RawMessage to delay parsing part of a JSON message.
-func ExampleRawMessage_unmarshal() {
- type Color struct {
- Space string
- Point json.RawMessage // delay parsing until we know the color space
- }
- type RGB struct {
- R uint8
- G uint8
- B uint8
- }
- type YCbCr struct {
- Y uint8
- Cb int8
- Cr int8
- }
-
- var j = []byte(`[
- {"Space": "YCbCr", "Point": {"Y": 255, "Cb": 0, "Cr": -10}},
- {"Space": "RGB", "Point": {"R": 98, "G": 218, "B": 255}}
-]`)
- var colors []Color
- err := json.Unmarshal(j, &colors)
- if err != nil {
- log.Fatalln("error:", err)
- }
-
- for _, c := range colors {
- var dst interface{}
- switch c.Space {
- case "RGB":
- dst = new(RGB)
- case "YCbCr":
- dst = new(YCbCr)
- }
- err := json.Unmarshal(c.Point, dst)
- if err != nil {
- log.Fatalln("error:", err)
- }
- fmt.Println(c.Space, dst)
- }
- // Output:
- // YCbCr &{255 0 -10}
- // RGB &{98 218 255}
-}
-
-// This example uses RawMessage to use a precomputed JSON during marshal.
-func ExampleRawMessage_marshal() {
- h := json.RawMessage(`{"precomputed": true}`)
-
- c := struct {
- Header *json.RawMessage `json:"header"`
- Body string `json:"body"`
- }{Header: &h, Body: "Hello Gophers!"}
-
- b, err := json.MarshalIndent(&c, "", "\t")
- if err != nil {
- fmt.Println("error:", err)
- }
- os.Stdout.Write(b)
-
- // Output:
- // {
- // "header": {
- // "precomputed": true
- // },
- // "body": "Hello Gophers!"
- // }
-}
-
-func ExampleIndent() {
- type Road struct {
- Name string
- Number int
- }
- roads := []Road{
- {"Diamond Fork", 29},
- {"Sheep Creek", 51},
- }
-
- b, err := json.Marshal(roads)
- if err != nil {
- log.Fatal(err)
- }
-
- var out bytes.Buffer
- json.Indent(&out, b, "=", "\t")
- out.WriteTo(os.Stdout)
- // Output:
- // [
- // = {
- // = "Name": "Diamond Fork",
- // = "Number": 29
- // = },
- // = {
- // = "Name": "Sheep Creek",
- // = "Number": 51
- // = }
- // =]
-}
-
-func ExampleMarshalIndent() {
- data := map[string]int{
- "a": 1,
- "b": 2,
- }
-
- json, err := json.MarshalIndent(data, "<prefix>", "<indent>")
- if err != nil {
- log.Fatal(err)
- }
-
- fmt.Println(string(json))
- // Output:
- // {
- // <prefix><indent>"a": 1,
- // <prefix><indent>"b": 2
- // <prefix>}
-}
-
-func ExampleValid() {
- goodJSON := `{"example": 1}`
- badJSON := `{"example":2:]}}`
-
- fmt.Println(json.Valid([]byte(goodJSON)), json.Valid([]byte(badJSON)))
- // Output:
- // true false
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_text_marshaling_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_text_marshaling_test.go
deleted file mode 100644
index 04c7813..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/example_text_marshaling_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json_test
-
-import (
- "encoding/json"
- "fmt"
- "log"
- "strings"
-)
-
-type Size int
-
-const (
- Unrecognized Size = iota
- Small
- Large
-)
-
-func (s *Size) UnmarshalText(text []byte) error {
- switch strings.ToLower(string(text)) {
- default:
- *s = Unrecognized
- case "small":
- *s = Small
- case "large":
- *s = Large
- }
- return nil
-}
-
-func (s Size) MarshalText() ([]byte, error) {
- var name string
- switch s {
- default:
- name = "unrecognized"
- case Small:
- name = "small"
- case Large:
- name = "large"
- }
- return []byte(name), nil
-}
-
-func Example_textMarshalJSON() {
- blob := `["small","regular","large","unrecognized","small","normal","small","large"]`
- var inventory []Size
- if err := json.Unmarshal([]byte(blob), &inventory); err != nil {
- log.Fatal(err)
- }
-
- counts := make(map[Size]int)
- for _, size := range inventory {
- counts[size] += 1
- }
-
- fmt.Printf("Inventory Counts:\n* Small: %d\n* Large: %d\n* Unrecognized: %d\n",
- counts[Small], counts[Large], counts[Unrecognized])
-
- // Output:
- // Inventory Counts:
- // * Small: 3
- // * Large: 2
- // * Unrecognized: 3
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/fold.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/fold.go
deleted file mode 100644
index 9e17012..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/fold.go
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "unicode/utf8"
-)
-
-const (
- caseMask = ^byte(0x20) // Mask to ignore case in ASCII.
- kelvin = '\u212a'
- smallLongEss = '\u017f'
-)
-
-// foldFunc returns one of four different case folding equivalence
-// functions, from most general (and slow) to fastest:
-//
-// 1) bytes.EqualFold, if the key s contains any non-ASCII UTF-8
-// 2) equalFoldRight, if s contains special folding ASCII ('k', 'K', 's', 'S')
-// 3) asciiEqualFold, no special, but includes non-letters (including _)
-// 4) simpleLetterEqualFold, no specials, no non-letters.
-//
-// The letters S and K are special because they map to 3 runes, not just 2:
-// * S maps to s and to U+017F 'ſ' Latin small letter long s
-// * k maps to K and to U+212A 'K' Kelvin sign
-// See https://play.golang.org/p/tTxjOc0OGo
-//
-// The returned function is specialized for matching against s and
-// should only be given s. It's not curried for performance reasons.
-func foldFunc(s []byte) func(s, t []byte) bool {
- nonLetter := false
- special := false // special letter
- for _, b := range s {
- if b >= utf8.RuneSelf {
- return bytes.EqualFold
- }
- upper := b & caseMask
- if upper < 'A' || upper > 'Z' {
- nonLetter = true
- } else if upper == 'K' || upper == 'S' {
- // See above for why these letters are special.
- special = true
- }
- }
- if special {
- return equalFoldRight
- }
- if nonLetter {
- return asciiEqualFold
- }
- return simpleLetterEqualFold
-}
-
-// equalFoldRight is a specialization of bytes.EqualFold when s is
-// known to be all ASCII (including punctuation), but contains an 's',
-// 'S', 'k', or 'K', requiring a Unicode fold on the bytes in t.
-// See comments on foldFunc.
-func equalFoldRight(s, t []byte) bool {
- for _, sb := range s {
- if len(t) == 0 {
- return false
- }
- tb := t[0]
- if tb < utf8.RuneSelf {
- if sb != tb {
- sbUpper := sb & caseMask
- if 'A' <= sbUpper && sbUpper <= 'Z' {
- if sbUpper != tb&caseMask {
- return false
- }
- } else {
- return false
- }
- }
- t = t[1:]
- continue
- }
- // sb is ASCII and t is not. t must be either kelvin
- // sign or long s; sb must be s, S, k, or K.
- tr, size := utf8.DecodeRune(t)
- switch sb {
- case 's', 'S':
- if tr != smallLongEss {
- return false
- }
- case 'k', 'K':
- if tr != kelvin {
- return false
- }
- default:
- return false
- }
- t = t[size:]
-
- }
- if len(t) > 0 {
- return false
- }
- return true
-}
-
-// asciiEqualFold is a specialization of bytes.EqualFold for use when
-// s is all ASCII (but may contain non-letters) and contains no
-// special-folding letters.
-// See comments on foldFunc.
-func asciiEqualFold(s, t []byte) bool {
- if len(s) != len(t) {
- return false
- }
- for i, sb := range s {
- tb := t[i]
- if sb == tb {
- continue
- }
- if ('a' <= sb && sb <= 'z') || ('A' <= sb && sb <= 'Z') {
- if sb&caseMask != tb&caseMask {
- return false
- }
- } else {
- return false
- }
- }
- return true
-}
-
-// simpleLetterEqualFold is a specialization of bytes.EqualFold for
-// use when s is all ASCII letters (no underscores, etc) and also
-// doesn't contain 'k', 'K', 's', or 'S'.
-// See comments on foldFunc.
-func simpleLetterEqualFold(s, t []byte) bool {
- if len(s) != len(t) {
- return false
- }
- for i, b := range s {
- if b&caseMask != t[i]&caseMask {
- return false
- }
- }
- return true
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/fold_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/fold_test.go
deleted file mode 100644
index 9fb9464..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/fold_test.go
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2013 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "strings"
- "testing"
- "unicode/utf8"
-)
-
-var foldTests = []struct {
- fn func(s, t []byte) bool
- s, t string
- want bool
-}{
- {equalFoldRight, "", "", true},
- {equalFoldRight, "a", "a", true},
- {equalFoldRight, "", "a", false},
- {equalFoldRight, "a", "", false},
- {equalFoldRight, "a", "A", true},
- {equalFoldRight, "AB", "ab", true},
- {equalFoldRight, "AB", "ac", false},
- {equalFoldRight, "sbkKc", "ſbKKc", true},
- {equalFoldRight, "SbKkc", "ſbKKc", true},
- {equalFoldRight, "SbKkc", "ſbKK", false},
- {equalFoldRight, "e", "é", false},
- {equalFoldRight, "s", "S", true},
-
- {simpleLetterEqualFold, "", "", true},
- {simpleLetterEqualFold, "abc", "abc", true},
- {simpleLetterEqualFold, "abc", "ABC", true},
- {simpleLetterEqualFold, "abc", "ABCD", false},
- {simpleLetterEqualFold, "abc", "xxx", false},
-
- {asciiEqualFold, "a_B", "A_b", true},
- {asciiEqualFold, "aa@", "aa`", false}, // verify 0x40 and 0x60 aren't case-equivalent
-}
-
-func TestFold(t *testing.T) {
- for i, tt := range foldTests {
- if got := tt.fn([]byte(tt.s), []byte(tt.t)); got != tt.want {
- t.Errorf("%d. %q, %q = %v; want %v", i, tt.s, tt.t, got, tt.want)
- }
- truth := strings.EqualFold(tt.s, tt.t)
- if truth != tt.want {
- t.Errorf("strings.EqualFold doesn't agree with case %d", i)
- }
- }
-}
-
-func TestFoldAgainstUnicode(t *testing.T) {
- const bufSize = 5
- buf1 := make([]byte, 0, bufSize)
- buf2 := make([]byte, 0, bufSize)
- var runes []rune
- for i := 0x20; i <= 0x7f; i++ {
- runes = append(runes, rune(i))
- }
- runes = append(runes, kelvin, smallLongEss)
-
- funcs := []struct {
- name string
- fold func(s, t []byte) bool
- letter bool // must be ASCII letter
- simple bool // must be simple ASCII letter (not 'S' or 'K')
- }{
- {
- name: "equalFoldRight",
- fold: equalFoldRight,
- },
- {
- name: "asciiEqualFold",
- fold: asciiEqualFold,
- simple: true,
- },
- {
- name: "simpleLetterEqualFold",
- fold: simpleLetterEqualFold,
- simple: true,
- letter: true,
- },
- }
-
- for _, ff := range funcs {
- for _, r := range runes {
- if r >= utf8.RuneSelf {
- continue
- }
- if ff.letter && !isASCIILetter(byte(r)) {
- continue
- }
- if ff.simple && (r == 's' || r == 'S' || r == 'k' || r == 'K') {
- continue
- }
- for _, r2 := range runes {
- buf1 := append(buf1[:0], 'x')
- buf2 := append(buf2[:0], 'x')
- buf1 = buf1[:1+utf8.EncodeRune(buf1[1:bufSize], r)]
- buf2 = buf2[:1+utf8.EncodeRune(buf2[1:bufSize], r2)]
- buf1 = append(buf1, 'x')
- buf2 = append(buf2, 'x')
- want := bytes.EqualFold(buf1, buf2)
- if got := ff.fold(buf1, buf2); got != want {
- t.Errorf("%s(%q, %q) = %v; want %v", ff.name, buf1, buf2, got, want)
- }
- }
- }
- }
-}
-
-func isASCIILetter(b byte) bool {
- return ('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z')
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/indent.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/indent.go
deleted file mode 100644
index fba1954..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/indent.go
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import "bytes"
-
-// Compact appends to dst the JSON-encoded src with
-// insignificant space characters elided.
-func Compact(dst *bytes.Buffer, src []byte) error {
- return compact(dst, src, false)
-}
-
-func compact(dst *bytes.Buffer, src []byte, escape bool) error {
- origLen := dst.Len()
- var scan scanner
- scan.reset()
- start := 0
- for i, c := range src {
- if escape && (c == '<' || c == '>' || c == '&') {
- if start < i {
- dst.Write(src[start:i])
- }
- dst.WriteString(`\u00`)
- dst.WriteByte(hex[c>>4])
- dst.WriteByte(hex[c&0xF])
- start = i + 1
- }
- // Convert U+2028 and U+2029 (E2 80 A8 and E2 80 A9).
- if c == 0xE2 && i+2 < len(src) && src[i+1] == 0x80 && src[i+2]&^1 == 0xA8 {
- if start < i {
- dst.Write(src[start:i])
- }
- dst.WriteString(`\u202`)
- dst.WriteByte(hex[src[i+2]&0xF])
- start = i + 3
- }
- v := scan.step(&scan, c)
- if v >= scanSkipSpace {
- if v == scanError {
- break
- }
- if start < i {
- dst.Write(src[start:i])
- }
- start = i + 1
- }
- }
- if scan.eof() == scanError {
- dst.Truncate(origLen)
- return scan.err
- }
- if start < len(src) {
- dst.Write(src[start:])
- }
- return nil
-}
-
-func newline(dst *bytes.Buffer, prefix, indent string, depth int) {
- dst.WriteByte('\n')
- dst.WriteString(prefix)
- for i := 0; i < depth; i++ {
- dst.WriteString(indent)
- }
-}
-
-// Indent appends to dst an indented form of the JSON-encoded src.
-// Each element in a JSON object or array begins on a new,
-// indented line beginning with prefix followed by one or more
-// copies of indent according to the indentation nesting.
-// The data appended to dst does not begin with the prefix nor
-// any indentation, to make it easier to embed inside other formatted JSON data.
-// Although leading space characters (space, tab, carriage return, newline)
-// at the beginning of src are dropped, trailing space characters
-// at the end of src are preserved and copied to dst.
-// For example, if src has no trailing spaces, neither will dst;
-// if src ends in a trailing newline, so will dst.
-func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
- origLen := dst.Len()
- var scan scanner
- scan.reset()
- needIndent := false
- depth := 0
- for _, c := range src {
- scan.bytes++
- v := scan.step(&scan, c)
- if v == scanSkipSpace {
- continue
- }
- if v == scanError {
- break
- }
- if needIndent && v != scanEndObject && v != scanEndArray {
- needIndent = false
- depth++
- newline(dst, prefix, indent, depth)
- }
-
- // Emit semantically uninteresting bytes
- // (in particular, punctuation in strings) unmodified.
- if v == scanContinue {
- dst.WriteByte(c)
- continue
- }
-
- // Add spacing around real punctuation.
- switch c {
- case '{', '[':
- // delay indent so that empty object and array are formatted as {} and [].
- needIndent = true
- dst.WriteByte(c)
-
- case ',':
- dst.WriteByte(c)
- newline(dst, prefix, indent, depth)
-
- case ':':
- dst.WriteByte(c)
- dst.WriteByte(' ')
-
- case '}', ']':
- if needIndent {
- // suppress indent in empty object/array
- needIndent = false
- } else {
- depth--
- newline(dst, prefix, indent, depth)
- }
- dst.WriteByte(c)
-
- default:
- dst.WriteByte(c)
- }
- }
- if scan.eof() == scanError {
- dst.Truncate(origLen)
- return scan.err
- }
- return nil
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/number_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/number_test.go
deleted file mode 100644
index cc67018..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/number_test.go
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "regexp"
- "testing"
-)
-
-func TestNumberIsValid(t *testing.T) {
- // From: https://stackoverflow.com/a/13340826
- var jsonNumberRegexp = regexp.MustCompile(`^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$`)
-
- validTests := []string{
- "0",
- "-0",
- "1",
- "-1",
- "0.1",
- "-0.1",
- "1234",
- "-1234",
- "12.34",
- "-12.34",
- "12E0",
- "12E1",
- "12e34",
- "12E-0",
- "12e+1",
- "12e-34",
- "-12E0",
- "-12E1",
- "-12e34",
- "-12E-0",
- "-12e+1",
- "-12e-34",
- "1.2E0",
- "1.2E1",
- "1.2e34",
- "1.2E-0",
- "1.2e+1",
- "1.2e-34",
- "-1.2E0",
- "-1.2E1",
- "-1.2e34",
- "-1.2E-0",
- "-1.2e+1",
- "-1.2e-34",
- "0E0",
- "0E1",
- "0e34",
- "0E-0",
- "0e+1",
- "0e-34",
- "-0E0",
- "-0E1",
- "-0e34",
- "-0E-0",
- "-0e+1",
- "-0e-34",
- }
-
- for _, test := range validTests {
- if !isValidNumber(test) {
- t.Errorf("%s should be valid", test)
- }
-
- var f float64
- if err := Unmarshal([]byte(test), &f); err != nil {
- t.Errorf("%s should be valid but Unmarshal failed: %v", test, err)
- }
-
- if !jsonNumberRegexp.MatchString(test) {
- t.Errorf("%s should be valid but regexp does not match", test)
- }
- }
-
- invalidTests := []string{
- "",
- "invalid",
- "1.0.1",
- "1..1",
- "-1-2",
- "012a42",
- "01.2",
- "012",
- "12E12.12",
- "1e2e3",
- "1e+-2",
- "1e--23",
- "1e",
- "e1",
- "1e+",
- "1ea",
- "1a",
- "1.a",
- "1.",
- "01",
- "1.e1",
- }
-
- for _, test := range invalidTests {
- if isValidNumber(test) {
- t.Errorf("%s should be invalid", test)
- }
-
- var f float64
- if err := Unmarshal([]byte(test), &f); err == nil {
- t.Errorf("%s should be invalid but unmarshal wrote %v", test, f)
- }
-
- if jsonNumberRegexp.MatchString(test) {
- t.Errorf("%s should be invalid but matches regexp", test)
- }
- }
-}
-
-func BenchmarkNumberIsValid(b *testing.B) {
- s := "-61657.61667E+61673"
- for i := 0; i < b.N; i++ {
- isValidNumber(s)
- }
-}
-
-func BenchmarkNumberIsValidRegexp(b *testing.B) {
- var jsonNumberRegexp = regexp.MustCompile(`^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$`)
- s := "-61657.61667E+61673"
- for i := 0; i < b.N; i++ {
- jsonNumberRegexp.MatchString(s)
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/scanner.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/scanner.go
deleted file mode 100644
index 8857224..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/scanner.go
+++ /dev/null
@@ -1,573 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-// JSON value parser state machine.
-// Just about at the limit of what is reasonable to write by hand.
-// Some parts are a bit tedious, but overall it nicely factors out the
-// otherwise common code from the multiple scanning functions
-// in this package (Compact, Indent, checkValid, etc).
-//
-// This file starts with two simple examples using the scanner
-// before diving into the scanner itself.
-
-import "strconv"
-
-// Valid reports whether data is a valid JSON encoding.
-func Valid(data []byte) bool {
- return checkValid(data, &scanner{}) == nil
-}
-
-// checkValid verifies that data is valid JSON-encoded data.
-// scan is passed in for use by checkValid to avoid an allocation.
-func checkValid(data []byte, scan *scanner) error {
- scan.reset()
- for _, c := range data {
- scan.bytes++
- if scan.step(scan, c) == scanError {
- return scan.err
- }
- }
- if scan.eof() == scanError {
- return scan.err
- }
- return nil
-}
-
-// A SyntaxError is a description of a JSON syntax error.
-type SyntaxError struct {
- msg string // description of error
- Offset int64 // error occurred after reading Offset bytes
-}
-
-func (e *SyntaxError) Error() string { return e.msg }
-
-// A scanner is a JSON scanning state machine.
-// Callers call scan.reset() and then pass bytes in one at a time
-// by calling scan.step(&scan, c) for each byte.
-// The return value, referred to as an opcode, tells the
-// caller about significant parsing events like beginning
-// and ending literals, objects, and arrays, so that the
-// caller can follow along if it wishes.
-// The return value scanEnd indicates that a single top-level
-// JSON value has been completed, *before* the byte that
-// just got passed in. (The indication must be delayed in order
-// to recognize the end of numbers: is 123 a whole value or
-// the beginning of 12345e+6?).
-type scanner struct {
- // The step is a func to be called to execute the next transition.
- // Also tried using an integer constant and a single func
- // with a switch, but using the func directly was 10% faster
- // on a 64-bit Mac Mini, and it's nicer to read.
- step func(*scanner, byte) int
-
- // Reached end of top-level value.
- endTop bool
-
- // Stack of what we're in the middle of - array values, object keys, object values.
- parseState []int
-
- // Error that happened, if any.
- err error
-
- // total bytes consumed, updated by decoder.Decode
- bytes int64
-}
-
-// These values are returned by the state transition functions
-// assigned to scanner.state and the method scanner.eof.
-// They give details about the current state of the scan that
-// callers might be interested to know about.
-// It is okay to ignore the return value of any particular
-// call to scanner.state: if one call returns scanError,
-// every subsequent call will return scanError too.
-const (
- // Continue.
- scanContinue = iota // uninteresting byte
- scanBeginLiteral // end implied by next result != scanContinue
- scanBeginObject // begin object
- scanObjectKey // just finished object key (string)
- scanObjectValue // just finished non-last object value
- scanEndObject // end object (implies scanObjectValue if possible)
- scanBeginArray // begin array
- scanArrayValue // just finished array value
- scanEndArray // end array (implies scanArrayValue if possible)
- scanSkipSpace // space byte; can skip; known to be last "continue" result
-
- // Stop.
- scanEnd // top-level value ended *before* this byte; known to be first "stop" result
- scanError // hit an error, scanner.err.
-)
-
-// These values are stored in the parseState stack.
-// They give the current state of a composite value
-// being scanned. If the parser is inside a nested value
-// the parseState describes the nested state, outermost at entry 0.
-const (
- parseObjectKey = iota // parsing object key (before colon)
- parseObjectValue // parsing object value (after colon)
- parseArrayValue // parsing array value
-)
-
-// reset prepares the scanner for use.
-// It must be called before calling s.step.
-func (s *scanner) reset() {
- s.step = stateBeginValue
- s.parseState = s.parseState[0:0]
- s.err = nil
- s.endTop = false
-}
-
-// eof tells the scanner that the end of input has been reached.
-// It returns a scan status just as s.step does.
-func (s *scanner) eof() int {
- if s.err != nil {
- return scanError
- }
- if s.endTop {
- return scanEnd
- }
- s.step(s, ' ')
- if s.endTop {
- return scanEnd
- }
- if s.err == nil {
- s.err = &SyntaxError{"unexpected end of JSON input", s.bytes}
- }
- return scanError
-}
-
-// pushParseState pushes a new parse state p onto the parse stack.
-func (s *scanner) pushParseState(p int) {
- s.parseState = append(s.parseState, p)
-}
-
-// popParseState pops a parse state (already obtained) off the stack
-// and updates s.step accordingly.
-func (s *scanner) popParseState() {
- n := len(s.parseState) - 1
- s.parseState = s.parseState[0:n]
- if n == 0 {
- s.step = stateEndTop
- s.endTop = true
- } else {
- s.step = stateEndValue
- }
-}
-
-func isSpace(c byte) bool {
- return c == ' ' || c == '\t' || c == '\r' || c == '\n'
-}
-
-// stateBeginValueOrEmpty is the state after reading `[`.
-func stateBeginValueOrEmpty(s *scanner, c byte) int {
- if c <= ' ' && isSpace(c) {
- return scanSkipSpace
- }
- if c == ']' {
- return stateEndValue(s, c)
- }
- return stateBeginValue(s, c)
-}
-
-// stateBeginValue is the state at the beginning of the input.
-func stateBeginValue(s *scanner, c byte) int {
- if c <= ' ' && isSpace(c) {
- return scanSkipSpace
- }
- switch c {
- case '{':
- s.step = stateBeginStringOrEmpty
- s.pushParseState(parseObjectKey)
- return scanBeginObject
- case '[':
- s.step = stateBeginValueOrEmpty
- s.pushParseState(parseArrayValue)
- return scanBeginArray
- case '"':
- s.step = stateInString
- return scanBeginLiteral
- case '-':
- s.step = stateNeg
- return scanBeginLiteral
- case '0': // beginning of 0.123
- s.step = state0
- return scanBeginLiteral
- case 't': // beginning of true
- s.step = stateT
- return scanBeginLiteral
- case 'f': // beginning of false
- s.step = stateF
- return scanBeginLiteral
- case 'n': // beginning of null
- s.step = stateN
- return scanBeginLiteral
- }
- if '1' <= c && c <= '9' { // beginning of 1234.5
- s.step = state1
- return scanBeginLiteral
- }
- return s.error(c, "looking for beginning of value")
-}
-
-// stateBeginStringOrEmpty is the state after reading `{`.
-func stateBeginStringOrEmpty(s *scanner, c byte) int {
- if c <= ' ' && isSpace(c) {
- return scanSkipSpace
- }
- if c == '}' {
- n := len(s.parseState)
- s.parseState[n-1] = parseObjectValue
- return stateEndValue(s, c)
- }
- return stateBeginString(s, c)
-}
-
-// stateBeginString is the state after reading `{"key": value,`.
-func stateBeginString(s *scanner, c byte) int {
- if c <= ' ' && isSpace(c) {
- return scanSkipSpace
- }
- if c == '"' {
- s.step = stateInString
- return scanBeginLiteral
- }
- return s.error(c, "looking for beginning of object key string")
-}
-
-// stateEndValue is the state after completing a value,
-// such as after reading `{}` or `true` or `["x"`.
-func stateEndValue(s *scanner, c byte) int {
- n := len(s.parseState)
- if n == 0 {
- // Completed top-level before the current byte.
- s.step = stateEndTop
- s.endTop = true
- return stateEndTop(s, c)
- }
- if c <= ' ' && isSpace(c) {
- s.step = stateEndValue
- return scanSkipSpace
- }
- ps := s.parseState[n-1]
- switch ps {
- case parseObjectKey:
- if c == ':' {
- s.parseState[n-1] = parseObjectValue
- s.step = stateBeginValue
- return scanObjectKey
- }
- return s.error(c, "after object key")
- case parseObjectValue:
- if c == ',' {
- s.parseState[n-1] = parseObjectKey
- s.step = stateBeginString
- return scanObjectValue
- }
- if c == '}' {
- s.popParseState()
- return scanEndObject
- }
- return s.error(c, "after object key:value pair")
- case parseArrayValue:
- if c == ',' {
- s.step = stateBeginValue
- return scanArrayValue
- }
- if c == ']' {
- s.popParseState()
- return scanEndArray
- }
- return s.error(c, "after array element")
- }
- return s.error(c, "")
-}
-
-// stateEndTop is the state after finishing the top-level value,
-// such as after reading `{}` or `[1,2,3]`.
-// Only space characters should be seen now.
-func stateEndTop(s *scanner, c byte) int {
- if !isSpace(c) {
- // Complain about non-space byte on next call.
- s.error(c, "after top-level value")
- }
- return scanEnd
-}
-
-// stateInString is the state after reading `"`.
-func stateInString(s *scanner, c byte) int {
- if c == '"' {
- s.step = stateEndValue
- return scanContinue
- }
- if c == '\\' {
- s.step = stateInStringEsc
- return scanContinue
- }
- if c < 0x20 {
- return s.error(c, "in string literal")
- }
- return scanContinue
-}
-
-// stateInStringEsc is the state after reading `"\` during a quoted string.
-func stateInStringEsc(s *scanner, c byte) int {
- switch c {
- case 'b', 'f', 'n', 'r', 't', '\\', '/', '"':
- s.step = stateInString
- return scanContinue
- case 'u':
- s.step = stateInStringEscU
- return scanContinue
- }
- return s.error(c, "in string escape code")
-}
-
-// stateInStringEscU is the state after reading `"\u` during a quoted string.
-func stateInStringEscU(s *scanner, c byte) int {
- if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
- s.step = stateInStringEscU1
- return scanContinue
- }
- // numbers
- return s.error(c, "in \\u hexadecimal character escape")
-}
-
-// stateInStringEscU1 is the state after reading `"\u1` during a quoted string.
-func stateInStringEscU1(s *scanner, c byte) int {
- if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
- s.step = stateInStringEscU12
- return scanContinue
- }
- // numbers
- return s.error(c, "in \\u hexadecimal character escape")
-}
-
-// stateInStringEscU12 is the state after reading `"\u12` during a quoted string.
-func stateInStringEscU12(s *scanner, c byte) int {
- if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
- s.step = stateInStringEscU123
- return scanContinue
- }
- // numbers
- return s.error(c, "in \\u hexadecimal character escape")
-}
-
-// stateInStringEscU123 is the state after reading `"\u123` during a quoted string.
-func stateInStringEscU123(s *scanner, c byte) int {
- if '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F' {
- s.step = stateInString
- return scanContinue
- }
- // numbers
- return s.error(c, "in \\u hexadecimal character escape")
-}
-
-// stateNeg is the state after reading `-` during a number.
-func stateNeg(s *scanner, c byte) int {
- if c == '0' {
- s.step = state0
- return scanContinue
- }
- if '1' <= c && c <= '9' {
- s.step = state1
- return scanContinue
- }
- return s.error(c, "in numeric literal")
-}
-
-// state1 is the state after reading a non-zero integer during a number,
-// such as after reading `1` or `100` but not `0`.
-func state1(s *scanner, c byte) int {
- if '0' <= c && c <= '9' {
- s.step = state1
- return scanContinue
- }
- return state0(s, c)
-}
-
-// state0 is the state after reading `0` during a number.
-func state0(s *scanner, c byte) int {
- if c == '.' {
- s.step = stateDot
- return scanContinue
- }
- if c == 'e' || c == 'E' {
- s.step = stateE
- return scanContinue
- }
- return stateEndValue(s, c)
-}
-
-// stateDot is the state after reading the integer and decimal point in a number,
-// such as after reading `1.`.
-func stateDot(s *scanner, c byte) int {
- if '0' <= c && c <= '9' {
- s.step = stateDot0
- return scanContinue
- }
- return s.error(c, "after decimal point in numeric literal")
-}
-
-// stateDot0 is the state after reading the integer, decimal point, and subsequent
-// digits of a number, such as after reading `3.14`.
-func stateDot0(s *scanner, c byte) int {
- if '0' <= c && c <= '9' {
- return scanContinue
- }
- if c == 'e' || c == 'E' {
- s.step = stateE
- return scanContinue
- }
- return stateEndValue(s, c)
-}
-
-// stateE is the state after reading the mantissa and e in a number,
-// such as after reading `314e` or `0.314e`.
-func stateE(s *scanner, c byte) int {
- if c == '+' || c == '-' {
- s.step = stateESign
- return scanContinue
- }
- return stateESign(s, c)
-}
-
-// stateESign is the state after reading the mantissa, e, and sign in a number,
-// such as after reading `314e-` or `0.314e+`.
-func stateESign(s *scanner, c byte) int {
- if '0' <= c && c <= '9' {
- s.step = stateE0
- return scanContinue
- }
- return s.error(c, "in exponent of numeric literal")
-}
-
-// stateE0 is the state after reading the mantissa, e, optional sign,
-// and at least one digit of the exponent in a number,
-// such as after reading `314e-2` or `0.314e+1` or `3.14e0`.
-func stateE0(s *scanner, c byte) int {
- if '0' <= c && c <= '9' {
- return scanContinue
- }
- return stateEndValue(s, c)
-}
-
-// stateT is the state after reading `t`.
-func stateT(s *scanner, c byte) int {
- if c == 'r' {
- s.step = stateTr
- return scanContinue
- }
- return s.error(c, "in literal true (expecting 'r')")
-}
-
-// stateTr is the state after reading `tr`.
-func stateTr(s *scanner, c byte) int {
- if c == 'u' {
- s.step = stateTru
- return scanContinue
- }
- return s.error(c, "in literal true (expecting 'u')")
-}
-
-// stateTru is the state after reading `tru`.
-func stateTru(s *scanner, c byte) int {
- if c == 'e' {
- s.step = stateEndValue
- return scanContinue
- }
- return s.error(c, "in literal true (expecting 'e')")
-}
-
-// stateF is the state after reading `f`.
-func stateF(s *scanner, c byte) int {
- if c == 'a' {
- s.step = stateFa
- return scanContinue
- }
- return s.error(c, "in literal false (expecting 'a')")
-}
-
-// stateFa is the state after reading `fa`.
-func stateFa(s *scanner, c byte) int {
- if c == 'l' {
- s.step = stateFal
- return scanContinue
- }
- return s.error(c, "in literal false (expecting 'l')")
-}
-
-// stateFal is the state after reading `fal`.
-func stateFal(s *scanner, c byte) int {
- if c == 's' {
- s.step = stateFals
- return scanContinue
- }
- return s.error(c, "in literal false (expecting 's')")
-}
-
-// stateFals is the state after reading `fals`.
-func stateFals(s *scanner, c byte) int {
- if c == 'e' {
- s.step = stateEndValue
- return scanContinue
- }
- return s.error(c, "in literal false (expecting 'e')")
-}
-
-// stateN is the state after reading `n`.
-func stateN(s *scanner, c byte) int {
- if c == 'u' {
- s.step = stateNu
- return scanContinue
- }
- return s.error(c, "in literal null (expecting 'u')")
-}
-
-// stateNu is the state after reading `nu`.
-func stateNu(s *scanner, c byte) int {
- if c == 'l' {
- s.step = stateNul
- return scanContinue
- }
- return s.error(c, "in literal null (expecting 'l')")
-}
-
-// stateNul is the state after reading `nul`.
-func stateNul(s *scanner, c byte) int {
- if c == 'l' {
- s.step = stateEndValue
- return scanContinue
- }
- return s.error(c, "in literal null (expecting 'l')")
-}
-
-// stateError is the state after reaching a syntax error,
-// such as after reading `[1}` or `5.1.2`.
-func stateError(s *scanner, c byte) int {
- return scanError
-}
-
-// error records an error and switches to the error state.
-func (s *scanner) error(c byte, context string) int {
- s.step = stateError
- s.err = &SyntaxError{"invalid character " + quoteChar(c) + " " + context, s.bytes}
- return scanError
-}
-
-// quoteChar formats c as a quoted character literal
-func quoteChar(c byte) string {
- // special cases - different from quoted strings
- if c == '\'' {
- return `'\''`
- }
- if c == '"' {
- return `'"'`
- }
-
- // use quoted string with different quotation marks
- s := strconv.Quote(string(c))
- return "'" + s[1:len(s)-1] + "'"
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/scanner_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/scanner_test.go
deleted file mode 100644
index 6cdbe7d..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/scanner_test.go
+++ /dev/null
@@ -1,300 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "math"
- "math/rand"
- "reflect"
- "testing"
-)
-
-var validTests = []struct {
- data string
- ok bool
-}{
- {`foo`, false},
- {`}{`, false},
- {`{]`, false},
- {`{}`, true},
- {`{"foo":"bar"}`, true},
- {`{"foo":"bar","bar":{"baz":["qux"]}}`, true},
-}
-
-func TestValid(t *testing.T) {
- for _, tt := range validTests {
- if ok := Valid([]byte(tt.data)); ok != tt.ok {
- t.Errorf("Valid(%#q) = %v, want %v", tt.data, ok, tt.ok)
- }
- }
-}
-
-// Tests of simple examples.
-
-type example struct {
- compact string
- indent string
-}
-
-var examples = []example{
- {`1`, `1`},
- {`{}`, `{}`},
- {`[]`, `[]`},
- {`{"":2}`, "{\n\t\"\": 2\n}"},
- {`[3]`, "[\n\t3\n]"},
- {`[1,2,3]`, "[\n\t1,\n\t2,\n\t3\n]"},
- {`{"x":1}`, "{\n\t\"x\": 1\n}"},
- {ex1, ex1i},
-}
-
-var ex1 = `[true,false,null,"x",1,1.5,0,-5e+2]`
-
-var ex1i = `[
- true,
- false,
- null,
- "x",
- 1,
- 1.5,
- 0,
- -5e+2
-]`
-
-func TestCompact(t *testing.T) {
- var buf bytes.Buffer
- for _, tt := range examples {
- buf.Reset()
- if err := Compact(&buf, []byte(tt.compact)); err != nil {
- t.Errorf("Compact(%#q): %v", tt.compact, err)
- } else if s := buf.String(); s != tt.compact {
- t.Errorf("Compact(%#q) = %#q, want original", tt.compact, s)
- }
-
- buf.Reset()
- if err := Compact(&buf, []byte(tt.indent)); err != nil {
- t.Errorf("Compact(%#q): %v", tt.indent, err)
- continue
- } else if s := buf.String(); s != tt.compact {
- t.Errorf("Compact(%#q) = %#q, want %#q", tt.indent, s, tt.compact)
- }
- }
-}
-
-func TestCompactSeparators(t *testing.T) {
- // U+2028 and U+2029 should be escaped inside strings.
- // They should not appear outside strings.
- tests := []struct {
- in, compact string
- }{
- {"{\"\u2028\": 1}", `{"\u2028":1}`},
- {"{\"\u2029\" :2}", `{"\u2029":2}`},
- }
- for _, tt := range tests {
- var buf bytes.Buffer
- if err := Compact(&buf, []byte(tt.in)); err != nil {
- t.Errorf("Compact(%q): %v", tt.in, err)
- } else if s := buf.String(); s != tt.compact {
- t.Errorf("Compact(%q) = %q, want %q", tt.in, s, tt.compact)
- }
- }
-}
-
-func TestIndent(t *testing.T) {
- var buf bytes.Buffer
- for _, tt := range examples {
- buf.Reset()
- if err := Indent(&buf, []byte(tt.indent), "", "\t"); err != nil {
- t.Errorf("Indent(%#q): %v", tt.indent, err)
- } else if s := buf.String(); s != tt.indent {
- t.Errorf("Indent(%#q) = %#q, want original", tt.indent, s)
- }
-
- buf.Reset()
- if err := Indent(&buf, []byte(tt.compact), "", "\t"); err != nil {
- t.Errorf("Indent(%#q): %v", tt.compact, err)
- continue
- } else if s := buf.String(); s != tt.indent {
- t.Errorf("Indent(%#q) = %#q, want %#q", tt.compact, s, tt.indent)
- }
- }
-}
-
-// Tests of a large random structure.
-
-func TestCompactBig(t *testing.T) {
- initBig()
- var buf bytes.Buffer
- if err := Compact(&buf, jsonBig); err != nil {
- t.Fatalf("Compact: %v", err)
- }
- b := buf.Bytes()
- if !bytes.Equal(b, jsonBig) {
- t.Error("Compact(jsonBig) != jsonBig")
- diff(t, b, jsonBig)
- return
- }
-}
-
-func TestIndentBig(t *testing.T) {
- t.Parallel()
- initBig()
- var buf bytes.Buffer
- if err := Indent(&buf, jsonBig, "", "\t"); err != nil {
- t.Fatalf("Indent1: %v", err)
- }
- b := buf.Bytes()
- if len(b) == len(jsonBig) {
- // jsonBig is compact (no unnecessary spaces);
- // indenting should make it bigger
- t.Fatalf("Indent(jsonBig) did not get bigger")
- }
-
- // should be idempotent
- var buf1 bytes.Buffer
- if err := Indent(&buf1, b, "", "\t"); err != nil {
- t.Fatalf("Indent2: %v", err)
- }
- b1 := buf1.Bytes()
- if !bytes.Equal(b1, b) {
- t.Error("Indent(Indent(jsonBig)) != Indent(jsonBig)")
- diff(t, b1, b)
- return
- }
-
- // should get back to original
- buf1.Reset()
- if err := Compact(&buf1, b); err != nil {
- t.Fatalf("Compact: %v", err)
- }
- b1 = buf1.Bytes()
- if !bytes.Equal(b1, jsonBig) {
- t.Error("Compact(Indent(jsonBig)) != jsonBig")
- diff(t, b1, jsonBig)
- return
- }
-}
-
-type indentErrorTest struct {
- in string
- err error
-}
-
-var indentErrorTests = []indentErrorTest{
- {`{"X": "foo", "Y"}`, &SyntaxError{"invalid character '}' after object key", 17}},
- {`{"X": "foo" "Y": "bar"}`, &SyntaxError{"invalid character '\"' after object key:value pair", 13}},
-}
-
-func TestIndentErrors(t *testing.T) {
- for i, tt := range indentErrorTests {
- slice := make([]uint8, 0)
- buf := bytes.NewBuffer(slice)
- if err := Indent(buf, []uint8(tt.in), "", ""); err != nil {
- if !reflect.DeepEqual(err, tt.err) {
- t.Errorf("#%d: Indent: %#v", i, err)
- continue
- }
- }
- }
-}
-
-func diff(t *testing.T, a, b []byte) {
- for i := 0; ; i++ {
- if i >= len(a) || i >= len(b) || a[i] != b[i] {
- j := i - 10
- if j < 0 {
- j = 0
- }
- t.Errorf("diverge at %d: «%s» vs «%s»", i, trim(a[j:]), trim(b[j:]))
- return
- }
- }
-}
-
-func trim(b []byte) []byte {
- if len(b) > 20 {
- return b[0:20]
- }
- return b
-}
-
-// Generate a random JSON object.
-
-var jsonBig []byte
-
-func initBig() {
- n := 10000
- if testing.Short() {
- n = 100
- }
- b, err := Marshal(genValue(n))
- if err != nil {
- panic(err)
- }
- jsonBig = b
-}
-
-func genValue(n int) interface{} {
- if n > 1 {
- switch rand.Intn(2) {
- case 0:
- return genArray(n)
- case 1:
- return genMap(n)
- }
- }
- switch rand.Intn(3) {
- case 0:
- return rand.Intn(2) == 0
- case 1:
- return rand.NormFloat64()
- case 2:
- return genString(30)
- }
- panic("unreachable")
-}
-
-func genString(stddev float64) string {
- n := int(math.Abs(rand.NormFloat64()*stddev + stddev/2))
- c := make([]rune, n)
- for i := range c {
- f := math.Abs(rand.NormFloat64()*64 + 32)
- if f > 0x10ffff {
- f = 0x10ffff
- }
- c[i] = rune(f)
- }
- return string(c)
-}
-
-func genArray(n int) []interface{} {
- f := int(math.Abs(rand.NormFloat64()) * math.Min(10, float64(n/2)))
- if f > n {
- f = n
- }
- if f < 1 {
- f = 1
- }
- x := make([]interface{}, f)
- for i := range x {
- x[i] = genValue(((i+1)*n)/f - (i*n)/f)
- }
- return x
-}
-
-func genMap(n int) map[string]interface{} {
- f := int(math.Abs(rand.NormFloat64()) * math.Min(10, float64(n/2)))
- if f > n {
- f = n
- }
- if n > 0 && f == 0 {
- f = 1
- }
- x := make(map[string]interface{})
- for i := 0; i < f; i++ {
- x[genString(10)] = genValue(((i+1)*n)/f - (i*n)/f)
- }
- return x
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/stream.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/stream.go
deleted file mode 100644
index 7d5137f..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/stream.go
+++ /dev/null
@@ -1,505 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "errors"
- "io"
-)
-
-// A Decoder reads and decodes JSON values from an input stream.
-type Decoder struct {
- r io.Reader
- buf []byte
- d decodeState
- scanp int // start of unread data in buf
- scanned int64 // amount of data already scanned
- scan scanner
- err error
-
- tokenState int
- tokenStack []int
-}
-
-// NewDecoder returns a new decoder that reads from r.
-//
-// The decoder introduces its own buffering and may
-// read data from r beyond the JSON values requested.
-func NewDecoder(r io.Reader) *Decoder {
- return &Decoder{r: r}
-}
-
-// UseNumber causes the Decoder to unmarshal a number into an interface{} as a
-// Number instead of as a float64.
-func (dec *Decoder) UseNumber() { dec.d.useNumber = true }
-
-// DisallowUnknownFields causes the Decoder to return an error when the destination
-// is a struct and the input contains object keys which do not match any
-// non-ignored, exported fields in the destination.
-func (dec *Decoder) DisallowUnknownFields() { dec.d.disallowUnknownFields = true }
-
-// Decode reads the next JSON-encoded value from its
-// input and stores it in the value pointed to by v.
-//
-// See the documentation for Unmarshal for details about
-// the conversion of JSON into a Go value.
-func (dec *Decoder) Decode(v interface{}) error {
- if dec.err != nil {
- return dec.err
- }
-
- if err := dec.tokenPrepareForDecode(); err != nil {
- return err
- }
-
- if !dec.tokenValueAllowed() {
- return &SyntaxError{msg: "not at beginning of value", Offset: dec.offset()}
- }
-
- // Read whole value into buffer.
- n, err := dec.readValue()
- if err != nil {
- return err
- }
- dec.d.init(dec.buf[dec.scanp : dec.scanp+n])
- dec.scanp += n
-
- // Don't save err from unmarshal into dec.err:
- // the connection is still usable since we read a complete JSON
- // object from it before the error happened.
- err = dec.d.unmarshal(v)
-
- // fixup token streaming state
- dec.tokenValueEnd()
-
- return err
-}
-
-// Buffered returns a reader of the data remaining in the Decoder's
-// buffer. The reader is valid until the next call to Decode.
-func (dec *Decoder) Buffered() io.Reader {
- return bytes.NewReader(dec.buf[dec.scanp:])
-}
-
-// readValue reads a JSON value into dec.buf.
-// It returns the length of the encoding.
-func (dec *Decoder) readValue() (int, error) {
- dec.scan.reset()
-
- scanp := dec.scanp
- var err error
-Input:
- for {
- // Look in the buffer for a new value.
- for i, c := range dec.buf[scanp:] {
- dec.scan.bytes++
- switch dec.scan.step(&dec.scan, c) {
- case scanEnd:
- scanp += i
- break Input
- case scanEndObject, scanEndArray:
- // scanEnd is delayed one byte.
- // We might block trying to get that byte from src,
- // so instead invent a space byte.
- if stateEndValue(&dec.scan, ' ') == scanEnd {
- scanp += i + 1
- break Input
- }
- case scanError:
- dec.err = dec.scan.err
- return 0, dec.scan.err
- }
- }
- scanp = len(dec.buf)
-
- // Did the last read have an error?
- // Delayed until now to allow buffer scan.
- if err != nil {
- if err == io.EOF {
- if dec.scan.step(&dec.scan, ' ') == scanEnd {
- break Input
- }
- if nonSpace(dec.buf) {
- err = io.ErrUnexpectedEOF
- }
- }
- dec.err = err
- return 0, err
- }
-
- n := scanp - dec.scanp
- err = dec.refill()
- scanp = dec.scanp + n
- }
- return scanp - dec.scanp, nil
-}
-
-func (dec *Decoder) refill() error {
- // Make room to read more into the buffer.
- // First slide down data already consumed.
- if dec.scanp > 0 {
- dec.scanned += int64(dec.scanp)
- n := copy(dec.buf, dec.buf[dec.scanp:])
- dec.buf = dec.buf[:n]
- dec.scanp = 0
- }
-
- // Grow buffer if not large enough.
- const minRead = 512
- if cap(dec.buf)-len(dec.buf) < minRead {
- newBuf := make([]byte, len(dec.buf), 2*cap(dec.buf)+minRead)
- copy(newBuf, dec.buf)
- dec.buf = newBuf
- }
-
- // Read. Delay error for next iteration (after scan).
- n, err := dec.r.Read(dec.buf[len(dec.buf):cap(dec.buf)])
- dec.buf = dec.buf[0 : len(dec.buf)+n]
-
- return err
-}
-
-func nonSpace(b []byte) bool {
- for _, c := range b {
- if !isSpace(c) {
- return true
- }
- }
- return false
-}
-
-// An Encoder writes JSON values to an output stream.
-type Encoder struct {
- w io.Writer
- err error
- escapeHTML bool
-
- indentBuf *bytes.Buffer
- indentPrefix string
- indentValue string
-}
-
-// NewEncoder returns a new encoder that writes to w.
-func NewEncoder(w io.Writer) *Encoder {
- return &Encoder{w: w, escapeHTML: true}
-}
-
-// Encode writes the JSON encoding of v to the stream,
-// followed by a newline character.
-//
-// See the documentation for Marshal for details about the
-// conversion of Go values to JSON.
-func (enc *Encoder) Encode(v interface{}) error {
- if enc.err != nil {
- return enc.err
- }
- e := newEncodeState()
- err := e.marshal(v, encOpts{escapeHTML: enc.escapeHTML})
- if err != nil {
- return err
- }
-
- // Terminate each value with a newline.
- // This makes the output look a little nicer
- // when debugging, and some kind of space
- // is required if the encoded value was a number,
- // so that the reader knows there aren't more
- // digits coming.
- e.WriteByte('\n')
-
- b := e.Bytes()
- if enc.indentPrefix != "" || enc.indentValue != "" {
- if enc.indentBuf == nil {
- enc.indentBuf = new(bytes.Buffer)
- }
- enc.indentBuf.Reset()
- err = Indent(enc.indentBuf, b, enc.indentPrefix, enc.indentValue)
- if err != nil {
- return err
- }
- b = enc.indentBuf.Bytes()
- }
- if _, err = enc.w.Write(b); err != nil {
- enc.err = err
- }
- encodeStatePool.Put(e)
- return err
-}
-
-// SetIndent instructs the encoder to format each subsequent encoded
-// value as if indented by the package-level function Indent(dst, src, prefix, indent).
-// Calling SetIndent("", "") disables indentation.
-func (enc *Encoder) SetIndent(prefix, indent string) {
- enc.indentPrefix = prefix
- enc.indentValue = indent
-}
-
-// SetEscapeHTML specifies whether problematic HTML characters
-// should be escaped inside JSON quoted strings.
-// The default behavior is to escape &, <, and > to \u0026, \u003c, and \u003e
-// to avoid certain safety problems that can arise when embedding JSON in HTML.
-//
-// In non-HTML settings where the escaping interferes with the readability
-// of the output, SetEscapeHTML(false) disables this behavior.
-func (enc *Encoder) SetEscapeHTML(on bool) {
- enc.escapeHTML = on
-}
-
-// RawMessage is a raw encoded JSON value.
-// It implements Marshaler and Unmarshaler and can
-// be used to delay JSON decoding or precompute a JSON encoding.
-type RawMessage []byte
-
-// MarshalJSON returns m as the JSON encoding of m.
-func (m RawMessage) MarshalJSON() ([]byte, error) {
- if m == nil {
- return []byte("null"), nil
- }
- return m, nil
-}
-
-// UnmarshalJSON sets *m to a copy of data.
-func (m *RawMessage) UnmarshalJSON(data []byte) error {
- if m == nil {
- return errors.New("json.RawMessage: UnmarshalJSON on nil pointer")
- }
- *m = append((*m)[0:0], data...)
- return nil
-}
-
-var _ Marshaler = (*RawMessage)(nil)
-var _ Unmarshaler = (*RawMessage)(nil)
-
-// A Token holds a value of one of these types:
-//
-// Delim, for the four JSON delimiters [ ] { }
-// bool, for JSON booleans
-// float64, for JSON numbers
-// Number, for JSON numbers
-// string, for JSON string literals
-// nil, for JSON null
-//
-type Token interface{}
-
-const (
- tokenTopValue = iota
- tokenArrayStart
- tokenArrayValue
- tokenArrayComma
- tokenObjectStart
- tokenObjectKey
- tokenObjectColon
- tokenObjectValue
- tokenObjectComma
-)
-
-// advance tokenstate from a separator state to a value state
-func (dec *Decoder) tokenPrepareForDecode() error {
- // Note: Not calling peek before switch, to avoid
- // putting peek into the standard Decode path.
- // peek is only called when using the Token API.
- switch dec.tokenState {
- case tokenArrayComma:
- c, err := dec.peek()
- if err != nil {
- return err
- }
- if c != ',' {
- return &SyntaxError{"expected comma after array element", dec.offset()}
- }
- dec.scanp++
- dec.tokenState = tokenArrayValue
- case tokenObjectColon:
- c, err := dec.peek()
- if err != nil {
- return err
- }
- if c != ':' {
- return &SyntaxError{"expected colon after object key", dec.offset()}
- }
- dec.scanp++
- dec.tokenState = tokenObjectValue
- }
- return nil
-}
-
-func (dec *Decoder) tokenValueAllowed() bool {
- switch dec.tokenState {
- case tokenTopValue, tokenArrayStart, tokenArrayValue, tokenObjectValue:
- return true
- }
- return false
-}
-
-func (dec *Decoder) tokenValueEnd() {
- switch dec.tokenState {
- case tokenArrayStart, tokenArrayValue:
- dec.tokenState = tokenArrayComma
- case tokenObjectValue:
- dec.tokenState = tokenObjectComma
- }
-}
-
-// A Delim is a JSON array or object delimiter, one of [ ] { or }.
-type Delim rune
-
-func (d Delim) String() string {
- return string(d)
-}
-
-// Token returns the next JSON token in the input stream.
-// At the end of the input stream, Token returns nil, io.EOF.
-//
-// Token guarantees that the delimiters [ ] { } it returns are
-// properly nested and matched: if Token encounters an unexpected
-// delimiter in the input, it will return an error.
-//
-// The input stream consists of basic JSON values—bool, string,
-// number, and null—along with delimiters [ ] { } of type Delim
-// to mark the start and end of arrays and objects.
-// Commas and colons are elided.
-func (dec *Decoder) Token() (Token, error) {
- for {
- c, err := dec.peek()
- if err != nil {
- return nil, err
- }
- switch c {
- case '[':
- if !dec.tokenValueAllowed() {
- return dec.tokenError(c)
- }
- dec.scanp++
- dec.tokenStack = append(dec.tokenStack, dec.tokenState)
- dec.tokenState = tokenArrayStart
- return Delim('['), nil
-
- case ']':
- if dec.tokenState != tokenArrayStart && dec.tokenState != tokenArrayComma {
- return dec.tokenError(c)
- }
- dec.scanp++
- dec.tokenState = dec.tokenStack[len(dec.tokenStack)-1]
- dec.tokenStack = dec.tokenStack[:len(dec.tokenStack)-1]
- dec.tokenValueEnd()
- return Delim(']'), nil
-
- case '{':
- if !dec.tokenValueAllowed() {
- return dec.tokenError(c)
- }
- dec.scanp++
- dec.tokenStack = append(dec.tokenStack, dec.tokenState)
- dec.tokenState = tokenObjectStart
- return Delim('{'), nil
-
- case '}':
- if dec.tokenState != tokenObjectStart && dec.tokenState != tokenObjectComma {
- return dec.tokenError(c)
- }
- dec.scanp++
- dec.tokenState = dec.tokenStack[len(dec.tokenStack)-1]
- dec.tokenStack = dec.tokenStack[:len(dec.tokenStack)-1]
- dec.tokenValueEnd()
- return Delim('}'), nil
-
- case ':':
- if dec.tokenState != tokenObjectColon {
- return dec.tokenError(c)
- }
- dec.scanp++
- dec.tokenState = tokenObjectValue
- continue
-
- case ',':
- if dec.tokenState == tokenArrayComma {
- dec.scanp++
- dec.tokenState = tokenArrayValue
- continue
- }
- if dec.tokenState == tokenObjectComma {
- dec.scanp++
- dec.tokenState = tokenObjectKey
- continue
- }
- return dec.tokenError(c)
-
- case '"':
- if dec.tokenState == tokenObjectStart || dec.tokenState == tokenObjectKey {
- var x string
- old := dec.tokenState
- dec.tokenState = tokenTopValue
- err := dec.Decode(&x)
- dec.tokenState = old
- if err != nil {
- return nil, err
- }
- dec.tokenState = tokenObjectColon
- return x, nil
- }
- fallthrough
-
- default:
- if !dec.tokenValueAllowed() {
- return dec.tokenError(c)
- }
- var x interface{}
- if err := dec.Decode(&x); err != nil {
- return nil, err
- }
- return x, nil
- }
- }
-}
-
-func (dec *Decoder) tokenError(c byte) (Token, error) {
- var context string
- switch dec.tokenState {
- case tokenTopValue:
- context = " looking for beginning of value"
- case tokenArrayStart, tokenArrayValue, tokenObjectValue:
- context = " looking for beginning of value"
- case tokenArrayComma:
- context = " after array element"
- case tokenObjectKey:
- context = " looking for beginning of object key string"
- case tokenObjectColon:
- context = " after object key"
- case tokenObjectComma:
- context = " after object key:value pair"
- }
- return nil, &SyntaxError{"invalid character " + quoteChar(c) + context, dec.offset()}
-}
-
-// More reports whether there is another element in the
-// current array or object being parsed.
-func (dec *Decoder) More() bool {
- c, err := dec.peek()
- return err == nil && c != ']' && c != '}'
-}
-
-func (dec *Decoder) peek() (byte, error) {
- var err error
- for {
- for i := dec.scanp; i < len(dec.buf); i++ {
- c := dec.buf[i]
- if isSpace(c) {
- continue
- }
- dec.scanp = i
- return c, nil
- }
- // buffer has been scanned, now report any error
- if err != nil {
- return 0, err
- }
- err = dec.refill()
- }
-}
-
-func (dec *Decoder) offset() int64 {
- return dec.scanned + int64(dec.scanp)
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/stream_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/stream_test.go
deleted file mode 100644
index 97eee72..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/stream_test.go
+++ /dev/null
@@ -1,438 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "bytes"
- "io"
- "log"
- "net"
- "net/http"
- "net/http/httptest"
- "reflect"
- "strings"
- "testing"
-)
-
-// Test values for the stream test.
-// One of each JSON kind.
-var streamTest = []interface{}{
- 0.1,
- "hello",
- nil,
- true,
- false,
- []interface{}{"a", "b", "c"},
- map[string]interface{}{"K": "Kelvin", "ß": "long s"},
- 3.14, // another value to make sure something can follow map
-}
-
-var streamEncoded = `0.1
-"hello"
-null
-true
-false
-["a","b","c"]
-{"ß":"long s","K":"Kelvin"}
-3.14
-`
-
-func TestEncoder(t *testing.T) {
- for i := 0; i <= len(streamTest); i++ {
- var buf bytes.Buffer
- enc := NewEncoder(&buf)
- // Check that enc.SetIndent("", "") turns off indentation.
- enc.SetIndent(">", ".")
- enc.SetIndent("", "")
- for j, v := range streamTest[0:i] {
- if err := enc.Encode(v); err != nil {
- t.Fatalf("encode #%d: %v", j, err)
- }
- }
- if have, want := buf.String(), nlines(streamEncoded, i); have != want {
- t.Errorf("encoding %d items: mismatch", i)
- diff(t, []byte(have), []byte(want))
- break
- }
- }
-}
-
-var streamEncodedIndent = `0.1
-"hello"
-null
-true
-false
-[
->."a",
->."b",
->."c"
->]
-{
->."ß": "long s",
->."K": "Kelvin"
->}
-3.14
-`
-
-func TestEncoderIndent(t *testing.T) {
- var buf bytes.Buffer
- enc := NewEncoder(&buf)
- enc.SetIndent(">", ".")
- for _, v := range streamTest {
- enc.Encode(v)
- }
- if have, want := buf.String(), streamEncodedIndent; have != want {
- t.Error("indented encoding mismatch")
- diff(t, []byte(have), []byte(want))
- }
-}
-
-func TestEncoderSetEscapeHTML(t *testing.T) {
- var c C
- var ct CText
- var tagStruct struct {
- Valid int `json:"<>&#! "`
- Invalid int `json:"\\"`
- }
- for _, tt := range []struct {
- name string
- v interface{}
- wantEscape string
- want string
- }{
- {"c", c, `"\u003c\u0026\u003e"`, `"<&>"`},
- {"ct", ct, `"\"\u003c\u0026\u003e\""`, `"\"<&>\""`},
- {`"<&>"`, "<&>", `"\u003c\u0026\u003e"`, `"<&>"`},
- {
- "tagStruct", tagStruct,
- `{"\u003c\u003e\u0026#! ":0,"Invalid":0}`,
- `{"<>&#! ":0,"Invalid":0}`,
- },
- } {
- var buf bytes.Buffer
- enc := NewEncoder(&buf)
- if err := enc.Encode(tt.v); err != nil {
- t.Fatalf("Encode(%s): %s", tt.name, err)
- }
- if got := strings.TrimSpace(buf.String()); got != tt.wantEscape {
- t.Errorf("Encode(%s) = %#q, want %#q", tt.name, got, tt.wantEscape)
- }
- buf.Reset()
- enc.SetEscapeHTML(false)
- if err := enc.Encode(tt.v); err != nil {
- t.Fatalf("SetEscapeHTML(false) Encode(%s): %s", tt.name, err)
- }
- if got := strings.TrimSpace(buf.String()); got != tt.want {
- t.Errorf("SetEscapeHTML(false) Encode(%s) = %#q, want %#q",
- tt.name, got, tt.want)
- }
- }
-}
-
-func TestDecoder(t *testing.T) {
- for i := 0; i <= len(streamTest); i++ {
- // Use stream without newlines as input,
- // just to stress the decoder even more.
- // Our test input does not include back-to-back numbers.
- // Otherwise stripping the newlines would
- // merge two adjacent JSON values.
- var buf bytes.Buffer
- for _, c := range nlines(streamEncoded, i) {
- if c != '\n' {
- buf.WriteRune(c)
- }
- }
- out := make([]interface{}, i)
- dec := NewDecoder(&buf)
- for j := range out {
- if err := dec.Decode(&out[j]); err != nil {
- t.Fatalf("decode #%d/%d: %v", j, i, err)
- }
- }
- if !reflect.DeepEqual(out, streamTest[0:i]) {
- t.Errorf("decoding %d items: mismatch", i)
- for j := range out {
- if !reflect.DeepEqual(out[j], streamTest[j]) {
- t.Errorf("#%d: have %v want %v", j, out[j], streamTest[j])
- }
- }
- break
- }
- }
-}
-
-func TestDecoderBuffered(t *testing.T) {
- r := strings.NewReader(`{"Name": "Gopher"} extra `)
- var m struct {
- Name string
- }
- d := NewDecoder(r)
- err := d.Decode(&m)
- if err != nil {
- t.Fatal(err)
- }
- if m.Name != "Gopher" {
- t.Errorf("Name = %q; want Gopher", m.Name)
- }
- rest, err := io.ReadAll(d.Buffered())
- if err != nil {
- t.Fatal(err)
- }
- if g, w := string(rest), " extra "; g != w {
- t.Errorf("Remaining = %q; want %q", g, w)
- }
-}
-
-func nlines(s string, n int) string {
- if n <= 0 {
- return ""
- }
- for i, c := range s {
- if c == '\n' {
- if n--; n == 0 {
- return s[0 : i+1]
- }
- }
- }
- return s
-}
-
-func TestRawMessage(t *testing.T) {
- var data struct {
- X float64
- Id RawMessage
- Y float32
- }
- const raw = `["\u0056",null]`
- const msg = `{"X":0.1,"Id":["\u0056",null],"Y":0.2}`
- err := Unmarshal([]byte(msg), &data)
- if err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if string([]byte(data.Id)) != raw {
- t.Fatalf("Raw mismatch: have %#q want %#q", []byte(data.Id), raw)
- }
- b, err := Marshal(&data)
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
- if string(b) != msg {
- t.Fatalf("Marshal: have %#q want %#q", b, msg)
- }
-}
-
-func TestNullRawMessage(t *testing.T) {
- var data struct {
- X float64
- Id RawMessage
- IdPtr *RawMessage
- Y float32
- }
- const msg = `{"X":0.1,"Id":null,"IdPtr":null,"Y":0.2}`
- err := Unmarshal([]byte(msg), &data)
- if err != nil {
- t.Fatalf("Unmarshal: %v", err)
- }
- if want, got := "null", string(data.Id); want != got {
- t.Fatalf("Raw mismatch: have %q, want %q", got, want)
- }
- if data.IdPtr != nil {
- t.Fatalf("Raw pointer mismatch: have non-nil, want nil")
- }
- b, err := Marshal(&data)
- if err != nil {
- t.Fatalf("Marshal: %v", err)
- }
- if string(b) != msg {
- t.Fatalf("Marshal: have %#q want %#q", b, msg)
- }
-}
-
-var blockingTests = []string{
- `{"x": 1}`,
- `[1, 2, 3]`,
-}
-
-func TestBlocking(t *testing.T) {
- for _, enc := range blockingTests {
- r, w := net.Pipe()
- go w.Write([]byte(enc))
- var val interface{}
-
- // If Decode reads beyond what w.Write writes above,
- // it will block, and the test will deadlock.
- if err := NewDecoder(r).Decode(&val); err != nil {
- t.Errorf("decoding %s: %v", enc, err)
- }
- r.Close()
- w.Close()
- }
-}
-
-func BenchmarkEncoderEncode(b *testing.B) {
- b.ReportAllocs()
- type T struct {
- X, Y string
- }
- v := &T{"foo", "bar"}
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- if err := NewEncoder(io.Discard).Encode(v); err != nil {
- b.Fatal(err)
- }
- }
- })
-}
-
-type tokenStreamCase struct {
- json string
- expTokens []interface{}
-}
-
-type decodeThis struct {
- v interface{}
-}
-
-var tokenStreamCases []tokenStreamCase = []tokenStreamCase{
- // streaming token cases
- {json: `10`, expTokens: []interface{}{float64(10)}},
- {json: ` [10] `, expTokens: []interface{}{
- Delim('['), float64(10), Delim(']')}},
- {json: ` [false,10,"b"] `, expTokens: []interface{}{
- Delim('['), false, float64(10), "b", Delim(']')}},
- {json: `{ "a": 1 }`, expTokens: []interface{}{
- Delim('{'), "a", float64(1), Delim('}')}},
- {json: `{"a": 1, "b":"3"}`, expTokens: []interface{}{
- Delim('{'), "a", float64(1), "b", "3", Delim('}')}},
- {json: ` [{"a": 1},{"a": 2}] `, expTokens: []interface{}{
- Delim('['),
- Delim('{'), "a", float64(1), Delim('}'),
- Delim('{'), "a", float64(2), Delim('}'),
- Delim(']')}},
- {json: `{"obj": {"a": 1}}`, expTokens: []interface{}{
- Delim('{'), "obj", Delim('{'), "a", float64(1), Delim('}'),
- Delim('}')}},
- {json: `{"obj": [{"a": 1}]}`, expTokens: []interface{}{
- Delim('{'), "obj", Delim('['),
- Delim('{'), "a", float64(1), Delim('}'),
- Delim(']'), Delim('}')}},
-
- // streaming tokens with intermittent Decode()
- {json: `{ "a": 1 }`, expTokens: []interface{}{
- Delim('{'), "a",
- decodeThis{float64(1)},
- Delim('}')}},
- {json: ` [ { "a" : 1 } ] `, expTokens: []interface{}{
- Delim('['),
- decodeThis{map[string]interface{}{"a": float64(1)}},
- Delim(']')}},
- {json: ` [{"a": 1},{"a": 2}] `, expTokens: []interface{}{
- Delim('['),
- decodeThis{map[string]interface{}{"a": float64(1)}},
- decodeThis{map[string]interface{}{"a": float64(2)}},
- Delim(']')}},
- {json: `{ "obj" : [ { "a" : 1 } ] }`, expTokens: []interface{}{
- Delim('{'), "obj", Delim('['),
- decodeThis{map[string]interface{}{"a": float64(1)}},
- Delim(']'), Delim('}')}},
-
- {json: `{"obj": {"a": 1}}`, expTokens: []interface{}{
- Delim('{'), "obj",
- decodeThis{map[string]interface{}{"a": float64(1)}},
- Delim('}')}},
- {json: `{"obj": [{"a": 1}]}`, expTokens: []interface{}{
- Delim('{'), "obj",
- decodeThis{[]interface{}{
- map[string]interface{}{"a": float64(1)},
- }},
- Delim('}')}},
- {json: ` [{"a": 1} {"a": 2}] `, expTokens: []interface{}{
- Delim('['),
- decodeThis{map[string]interface{}{"a": float64(1)}},
- decodeThis{&SyntaxError{"expected comma after array element", 11}},
- }},
- {json: `{ "` + strings.Repeat("a", 513) + `" 1 }`, expTokens: []interface{}{
- Delim('{'), strings.Repeat("a", 513),
- decodeThis{&SyntaxError{"expected colon after object key", 518}},
- }},
- {json: `{ "\a" }`, expTokens: []interface{}{
- Delim('{'),
- &SyntaxError{"invalid character 'a' in string escape code", 3},
- }},
- {json: ` \a`, expTokens: []interface{}{
- &SyntaxError{"invalid character '\\\\' looking for beginning of value", 1},
- }},
-}
-
-func TestDecodeInStream(t *testing.T) {
-
- for ci, tcase := range tokenStreamCases {
-
- dec := NewDecoder(strings.NewReader(tcase.json))
- for i, etk := range tcase.expTokens {
-
- var tk interface{}
- var err error
-
- if dt, ok := etk.(decodeThis); ok {
- etk = dt.v
- err = dec.Decode(&tk)
- } else {
- tk, err = dec.Token()
- }
- if experr, ok := etk.(error); ok {
- if err == nil || !reflect.DeepEqual(err, experr) {
- t.Errorf("case %v: Expected error %#v in %q, but was %#v", ci, experr, tcase.json, err)
- }
- break
- } else if err == io.EOF {
- t.Errorf("case %v: Unexpected EOF in %q", ci, tcase.json)
- break
- } else if err != nil {
- t.Errorf("case %v: Unexpected error '%#v' in %q", ci, err, tcase.json)
- break
- }
- if !reflect.DeepEqual(tk, etk) {
- t.Errorf(`case %v: %q @ %v expected %T(%v) was %T(%v)`, ci, tcase.json, i, etk, etk, tk, tk)
- break
- }
- }
- }
-
-}
-
-// Test from golang.org/issue/11893
-func TestHTTPDecoding(t *testing.T) {
- const raw = `{ "foo": "bar" }`
-
- ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write([]byte(raw))
- }))
- defer ts.Close()
- res, err := http.Get(ts.URL)
- if err != nil {
- log.Fatalf("GET failed: %v", err)
- }
- defer res.Body.Close()
-
- foo := struct {
- Foo string
- }{}
-
- d := NewDecoder(res.Body)
- err = d.Decode(&foo)
- if err != nil {
- t.Fatalf("Decode: %v", err)
- }
- if foo.Foo != "bar" {
- t.Errorf("decoded %q; want \"bar\"", foo.Foo)
- }
-
- // make sure we get the EOF the second time
- err = d.Decode(&foo)
- if err != io.EOF {
- t.Errorf("err = %v; want io.EOF", err)
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tables.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/tables.go
deleted file mode 100644
index 10acdc1..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tables.go
+++ /dev/null
@@ -1,218 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import "unicode/utf8"
-
-// safeSet holds the value true if the ASCII character with the given array
-// position can be represented inside a JSON string without any further
-// escaping.
-//
-// All values are true except for the ASCII control characters (0-31), the
-// double quote ("), and the backslash character ("\").
-var safeSet = [utf8.RuneSelf]bool{
- ' ': true,
- '!': true,
- '"': false,
- '#': true,
- '$': true,
- '%': true,
- '&': true,
- '\'': true,
- '(': true,
- ')': true,
- '*': true,
- '+': true,
- ',': true,
- '-': true,
- '.': true,
- '/': true,
- '0': true,
- '1': true,
- '2': true,
- '3': true,
- '4': true,
- '5': true,
- '6': true,
- '7': true,
- '8': true,
- '9': true,
- ':': true,
- ';': true,
- '<': true,
- '=': true,
- '>': true,
- '?': true,
- '@': true,
- 'A': true,
- 'B': true,
- 'C': true,
- 'D': true,
- 'E': true,
- 'F': true,
- 'G': true,
- 'H': true,
- 'I': true,
- 'J': true,
- 'K': true,
- 'L': true,
- 'M': true,
- 'N': true,
- 'O': true,
- 'P': true,
- 'Q': true,
- 'R': true,
- 'S': true,
- 'T': true,
- 'U': true,
- 'V': true,
- 'W': true,
- 'X': true,
- 'Y': true,
- 'Z': true,
- '[': true,
- '\\': false,
- ']': true,
- '^': true,
- '_': true,
- '`': true,
- 'a': true,
- 'b': true,
- 'c': true,
- 'd': true,
- 'e': true,
- 'f': true,
- 'g': true,
- 'h': true,
- 'i': true,
- 'j': true,
- 'k': true,
- 'l': true,
- 'm': true,
- 'n': true,
- 'o': true,
- 'p': true,
- 'q': true,
- 'r': true,
- 's': true,
- 't': true,
- 'u': true,
- 'v': true,
- 'w': true,
- 'x': true,
- 'y': true,
- 'z': true,
- '{': true,
- '|': true,
- '}': true,
- '~': true,
- '\u007f': true,
-}
-
-// htmlSafeSet holds the value true if the ASCII character with the given
-// array position can be safely represented inside a JSON string, embedded
-// inside of HTML <script> tags, without any additional escaping.
-//
-// All values are true except for the ASCII control characters (0-31), the
-// double quote ("), the backslash character ("\"), HTML opening and closing
-// tags ("<" and ">"), and the ampersand ("&").
-var htmlSafeSet = [utf8.RuneSelf]bool{
- ' ': true,
- '!': true,
- '"': false,
- '#': true,
- '$': true,
- '%': true,
- '&': false,
- '\'': true,
- '(': true,
- ')': true,
- '*': true,
- '+': true,
- ',': true,
- '-': true,
- '.': true,
- '/': true,
- '0': true,
- '1': true,
- '2': true,
- '3': true,
- '4': true,
- '5': true,
- '6': true,
- '7': true,
- '8': true,
- '9': true,
- ':': true,
- ';': true,
- '<': false,
- '=': true,
- '>': false,
- '?': true,
- '@': true,
- 'A': true,
- 'B': true,
- 'C': true,
- 'D': true,
- 'E': true,
- 'F': true,
- 'G': true,
- 'H': true,
- 'I': true,
- 'J': true,
- 'K': true,
- 'L': true,
- 'M': true,
- 'N': true,
- 'O': true,
- 'P': true,
- 'Q': true,
- 'R': true,
- 'S': true,
- 'T': true,
- 'U': true,
- 'V': true,
- 'W': true,
- 'X': true,
- 'Y': true,
- 'Z': true,
- '[': true,
- '\\': false,
- ']': true,
- '^': true,
- '_': true,
- '`': true,
- 'a': true,
- 'b': true,
- 'c': true,
- 'd': true,
- 'e': true,
- 'f': true,
- 'g': true,
- 'h': true,
- 'i': true,
- 'j': true,
- 'k': true,
- 'l': true,
- 'm': true,
- 'n': true,
- 'o': true,
- 'p': true,
- 'q': true,
- 'r': true,
- 's': true,
- 't': true,
- 'u': true,
- 'v': true,
- 'w': true,
- 'x': true,
- 'y': true,
- 'z': true,
- '{': true,
- '|': true,
- '}': true,
- '~': true,
- '\u007f': true,
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tagkey_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/tagkey_test.go
deleted file mode 100644
index f77c49c..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tagkey_test.go
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "testing"
-)
-
-type basicLatin2xTag struct {
- V string `json:"$%-/"`
-}
-
-type basicLatin3xTag struct {
- V string `json:"0123456789"`
-}
-
-type basicLatin4xTag struct {
- V string `json:"ABCDEFGHIJKLMO"`
-}
-
-type basicLatin5xTag struct {
- V string `json:"PQRSTUVWXYZ_"`
-}
-
-type basicLatin6xTag struct {
- V string `json:"abcdefghijklmno"`
-}
-
-type basicLatin7xTag struct {
- V string `json:"pqrstuvwxyz"`
-}
-
-type miscPlaneTag struct {
- V string `json:"色は匂へど"`
-}
-
-type percentSlashTag struct {
- V string `json:"text/html%"` // https://golang.org/issue/2718
-}
-
-type punctuationTag struct {
- V string `json:"!#$%&()*+-./:<=>?@[]^_{|}~"` // https://golang.org/issue/3546
-}
-
-type dashTag struct {
- V string `json:"-,"`
-}
-
-type emptyTag struct {
- W string
-}
-
-type misnamedTag struct {
- X string `jsom:"Misnamed"`
-}
-
-type badFormatTag struct {
- Y string `:"BadFormat"`
-}
-
-type badCodeTag struct {
- Z string `json:" !\"#&'()*+,."`
-}
-
-type spaceTag struct {
- Q string `json:"With space"`
-}
-
-type unicodeTag struct {
- W string `json:"Ελλάδα"`
-}
-
-var structTagObjectKeyTests = []struct {
- raw interface{}
- value string
- key string
-}{
- {basicLatin2xTag{"2x"}, "2x", "$%-/"},
- {basicLatin3xTag{"3x"}, "3x", "0123456789"},
- {basicLatin4xTag{"4x"}, "4x", "ABCDEFGHIJKLMO"},
- {basicLatin5xTag{"5x"}, "5x", "PQRSTUVWXYZ_"},
- {basicLatin6xTag{"6x"}, "6x", "abcdefghijklmno"},
- {basicLatin7xTag{"7x"}, "7x", "pqrstuvwxyz"},
- {miscPlaneTag{"いろはにほへと"}, "いろはにほへと", "色は匂へど"},
- {dashTag{"foo"}, "foo", "-"},
- {emptyTag{"Pour Moi"}, "Pour Moi", "W"},
- {misnamedTag{"Animal Kingdom"}, "Animal Kingdom", "X"},
- {badFormatTag{"Orfevre"}, "Orfevre", "Y"},
- {badCodeTag{"Reliable Man"}, "Reliable Man", "Z"},
- {percentSlashTag{"brut"}, "brut", "text/html%"},
- {punctuationTag{"Union Rags"}, "Union Rags", "!#$%&()*+-./:<=>?@[]^_{|}~"},
- {spaceTag{"Perreddu"}, "Perreddu", "With space"},
- {unicodeTag{"Loukanikos"}, "Loukanikos", "Ελλάδα"},
-}
-
-func TestStructTagObjectKey(t *testing.T) {
- for _, tt := range structTagObjectKeyTests {
- b, err := Marshal(tt.raw)
- if err != nil {
- t.Fatalf("Marshal(%#q) failed: %v", tt.raw, err)
- }
- var f interface{}
- err = Unmarshal(b, &f)
- if err != nil {
- t.Fatalf("Unmarshal(%#q) failed: %v", b, err)
- }
- for i, v := range f.(map[string]interface{}) {
- switch i {
- case tt.key:
- if s, ok := v.(string); !ok || s != tt.value {
- t.Fatalf("Unexpected value: %#q, want %v", s, tt.value)
- }
- default:
- t.Fatalf("Unexpected key: %#q, from %#q", i, b)
- }
- }
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tags.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/tags.go
deleted file mode 100644
index c38fd51..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tags.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "strings"
-)
-
-// tagOptions is the string following a comma in a struct field's "json"
-// tag, or the empty string. It does not include the leading comma.
-type tagOptions string
-
-// parseTag splits a struct field's json tag into its name and
-// comma-separated options.
-func parseTag(tag string) (string, tagOptions) {
- if idx := strings.Index(tag, ","); idx != -1 {
- return tag[:idx], tagOptions(tag[idx+1:])
- }
- return tag, tagOptions("")
-}
-
-// Contains reports whether a comma-separated list of options
-// contains a particular substr flag. substr must be surrounded by a
-// string boundary or commas.
-func (o tagOptions) Contains(optionName string) bool {
- if len(o) == 0 {
- return false
- }
- s := string(o)
- for s != "" {
- var next string
- i := strings.Index(s, ",")
- if i >= 0 {
- s, next = s[:i], s[i+1:]
- }
- if s == optionName {
- return true
- }
- s = next
- }
- return false
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tags_test.go b/internal/stdlib/testdata/v1.12.5/src/encoding/json/tags_test.go
deleted file mode 100644
index 8ba8ddd..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/encoding/json/tags_test.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package json
-
-import (
- "testing"
-)
-
-func TestTagParsing(t *testing.T) {
- name, opts := parseTag("field,foobar,foo")
- if name != "field" {
- t.Fatalf("name = %q, want field", name)
- }
- for _, tt := range []struct {
- opt string
- want bool
- }{
- {"foobar", true},
- {"foo", true},
- {"bar", false},
- } {
- if opts.Contains(tt.opt) != tt.want {
- t.Errorf("Contains(%q) = %v", tt.opt, !tt.want)
- }
- }
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/errors/errors.go b/internal/stdlib/testdata/v1.12.5/src/errors/errors.go
deleted file mode 100644
index b8a4692..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/errors/errors.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package errors implements functions to manipulate errors.
-package errors
-
-// New returns an error that formats as the given text.
-func New(text string) error {
- return &errorString{text}
-}
-
-// errorString is a trivial implementation of error.
-type errorString struct {
- s string
-}
-
-func (e *errorString) Error() string {
- return e.s
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/errors/errors_test.go b/internal/stdlib/testdata/v1.12.5/src/errors/errors_test.go
deleted file mode 100644
index cf4df90..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/errors/errors_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "errors"
- "fmt"
- "testing"
-)
-
-func TestNewEqual(t *testing.T) {
- // Different allocations should not be equal.
- if errors.New("abc") == errors.New("abc") {
- t.Errorf(`New("abc") == New("abc")`)
- }
- if errors.New("abc") == errors.New("xyz") {
- t.Errorf(`New("abc") == New("xyz")`)
- }
-
- // Same allocation should be equal to itself (not crash).
- err := errors.New("jkl")
- if err != err {
- t.Errorf(`err != err`)
- }
-}
-
-func TestErrorMethod(t *testing.T) {
- err := errors.New("abc")
- if err.Error() != "abc" {
- t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
- }
-}
-
-func ExampleNew() {
- err := errors.New("emit macho dwarf: elf header corrupted")
- if err != nil {
- fmt.Print(err)
- }
- // Output: emit macho dwarf: elf header corrupted
-}
-
-// The fmt package's Errorf function lets us use the package's formatting
-// features to create descriptive error messages.
-func ExampleNew_errorf() {
- const name, id = "bimmler", 17
- err := fmt.Errorf("user %q (id %d) not found", name, id)
- if err != nil {
- fmt.Print(err)
- }
- // Output: user "bimmler" (id 17) not found
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/errors/example_test.go b/internal/stdlib/testdata/v1.12.5/src/errors/example_test.go
deleted file mode 100644
index 5dc8841..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/errors/example_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "fmt"
- "time"
-)
-
-// MyError is an error implementation that includes a time and message.
-type MyError struct {
- When time.Time
- What string
-}
-
-func (e MyError) Error() string {
- return fmt.Sprintf("%v: %v", e.When, e.What)
-}
-
-func oops() error {
- return MyError{
- time.Date(1989, 3, 15, 22, 30, 0, 0, time.UTC),
- "the file system has gone away",
- }
-}
-
-func Example() {
- if err := oops(); err != nil {
- fmt.Println(err)
- }
- // Output: 1989-03-15 22:30:00 +0000 UTC: the file system has gone away
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/flag/example_test.go b/internal/stdlib/testdata/v1.12.5/src/flag/example_test.go
deleted file mode 100644
index 04a0d20..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/flag/example_test.go
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// These examples demonstrate more intricate uses of the flag package.
-package flag_test
-
-import (
- "errors"
- "flag"
- "fmt"
- "strings"
- "time"
-)
-
-// Example 1: A single string flag called "species" with default value "gopher".
-var species = flag.String("species", "gopher", "the species we are studying")
-
-// Example 2: Two flags sharing a variable, so we can have a shorthand.
-// The order of initialization is undefined, so make sure both use the
-// same default value. They must be set up with an init function.
-var gopherType string
-
-func init() {
- const (
- defaultGopher = "pocket"
- usage = "the variety of gopher"
- )
- flag.StringVar(&gopherType, "gopher_type", defaultGopher, usage)
- flag.StringVar(&gopherType, "g", defaultGopher, usage+" (shorthand)")
-}
-
-// Example 3: A user-defined flag type, a slice of durations.
-type interval []time.Duration
-
-// String is the method to format the flag's value, part of the flag.Value interface.
-// The String method's output will be used in diagnostics.
-func (i *interval) String() string {
- return fmt.Sprint(*i)
-}
-
-// Set is the method to set the flag value, part of the flag.Value interface.
-// Set's argument is a string to be parsed to set the flag.
-// It's a comma-separated list, so we split it.
-func (i *interval) Set(value string) error {
- // If we wanted to allow the flag to be set multiple times,
- // accumulating values, we would delete this if statement.
- // That would permit usages such as
- // -deltaT 10s -deltaT 15s
- // and other combinations.
- if len(*i) > 0 {
- return errors.New("interval flag already set")
- }
- for _, dt := range strings.Split(value, ",") {
- duration, err := time.ParseDuration(dt)
- if err != nil {
- return err
- }
- *i = append(*i, duration)
- }
- return nil
-}
-
-// Define a flag to accumulate durations. Because it has a special type,
-// we need to use the Var function and therefore create the flag during
-// init.
-
-var intervalFlag interval
-
-func init() {
- // Tie the command-line flag to the intervalFlag variable and
- // set a usage message.
- flag.Var(&intervalFlag, "deltaT", "comma-separated list of intervals to use between events")
-}
-
-func Example() {
- // All the interesting pieces are with the variables declared above, but
- // to enable the flag package to see the flags defined there, one must
- // execute, typically at the start of main (not init!):
- // flag.Parse()
- // We don't run it here because this is not a main function and
- // the testing suite has already parsed the flags.
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/flag/example_value_test.go b/internal/stdlib/testdata/v1.12.5/src/flag/example_value_test.go
deleted file mode 100644
index 9d464c6..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/flag/example_value_test.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package flag_test
-
-import (
- "flag"
- "fmt"
- "net/url"
-)
-
-type URLValue struct {
- URL *url.URL
-}
-
-func (v URLValue) String() string {
- if v.URL != nil {
- return v.URL.String()
- }
- return ""
-}
-
-func (v URLValue) Set(s string) error {
- if u, err := url.Parse(s); err != nil {
- return err
- } else {
- *v.URL = *u
- }
- return nil
-}
-
-var u = &url.URL{}
-
-func ExampleValue() {
- fs := flag.NewFlagSet("ExampleValue", flag.ExitOnError)
- fs.Var(&URLValue{u}, "url", "URL to parse")
-
- fs.Parse([]string{"-url", "https://golang.org/pkg/flag/"})
- fmt.Printf(`{scheme: %q, host: %q, path: %q}`, u.Scheme, u.Host, u.Path)
-
- // Output:
- // {scheme: "https", host: "golang.org", path: "/pkg/flag/"}
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/flag/export_test.go b/internal/stdlib/testdata/v1.12.5/src/flag/export_test.go
deleted file mode 100644
index 838cfaf..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/flag/export_test.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2010 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package flag
-
-import "os"
-
-// Additional routines compiled into the package only during testing.
-
-var DefaultUsage = Usage
-
-// ResetForTesting clears all flag state and sets the usage function as directed.
-// After calling ResetForTesting, parse errors in flag handling will not
-// exit the program.
-func ResetForTesting(usage func()) {
- CommandLine = NewFlagSet(os.Args[0], ContinueOnError)
- CommandLine.Usage = commandLineUsage
- Usage = usage
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/flag/flag.go b/internal/stdlib/testdata/v1.12.5/src/flag/flag.go
deleted file mode 100644
index c312c62..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/flag/flag.go
+++ /dev/null
@@ -1,1041 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-/*
- Package flag implements command-line flag parsing.
-
- Usage
-
- Define flags using flag.String(), Bool(), Int(), etc.
-
- This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
- import "flag"
- var ip = flag.Int("flagname", 1234, "help message for flagname")
- If you like, you can bind the flag to a variable using the Var() functions.
- var flagvar int
- func init() {
- flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
- }
- Or you can create custom flags that satisfy the Value interface (with
- pointer receivers) and couple them to flag parsing by
- flag.Var(&flagVal, "name", "help message for flagname")
- For such flags, the default value is just the initial value of the variable.
-
- After all flags are defined, call
- flag.Parse()
- to parse the command line into the defined flags.
-
- Flags may then be used directly. If you're using the flags themselves,
- they are all pointers; if you bind to variables, they're values.
- fmt.Println("ip has value ", *ip)
- fmt.Println("flagvar has value ", flagvar)
-
- After parsing, the arguments following the flags are available as the
- slice flag.Args() or individually as flag.Arg(i).
- The arguments are indexed from 0 through flag.NArg()-1.
-
- Command line flag syntax
-
- The following forms are permitted:
-
- -flag
- -flag=x
- -flag x // non-boolean flags only
- One or two minus signs may be used; they are equivalent.
- The last form is not permitted for boolean flags because the
- meaning of the command
- cmd -x *
- where * is a Unix shell wildcard, will change if there is a file
- called 0, false, etc. You must use the -flag=false form to turn
- off a boolean flag.
-
- Flag parsing stops just before the first non-flag argument
- ("-" is a non-flag argument) or after the terminator "--".
-
- Integer flags accept 1234, 0664, 0x1234 and may be negative.
- Boolean flags may be:
- 1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False
- Duration flags accept any input valid for time.ParseDuration.
-
- The default set of command-line flags is controlled by
- top-level functions. The FlagSet type allows one to define
- independent sets of flags, such as to implement subcommands
- in a command-line interface. The methods of FlagSet are
- analogous to the top-level functions for the command-line
- flag set.
-*/
-package flag
-
-import (
- "errors"
- "fmt"
- "io"
- "os"
- "reflect"
- "sort"
- "strconv"
- "strings"
- "time"
-)
-
-// ErrHelp is the error returned if the -help or -h flag is invoked
-// but no such flag is defined.
-var ErrHelp = errors.New("flag: help requested")
-
-// errParse is returned by Set if a flag's value fails to parse, such as with an invalid integer for Int.
-// It then gets wrapped through failf to provide more information.
-var errParse = errors.New("parse error")
-
-// errRange is returned by Set if a flag's value is out of range.
-// It then gets wrapped through failf to provide more information.
-var errRange = errors.New("value out of range")
-
-func numError(err error) error {
- ne, ok := err.(*strconv.NumError)
- if !ok {
- return err
- }
- if ne.Err == strconv.ErrSyntax {
- return errParse
- }
- if ne.Err == strconv.ErrRange {
- return errRange
- }
- return err
-}
-
-// -- bool Value
-type boolValue bool
-
-func newBoolValue(val bool, p *bool) *boolValue {
- *p = val
- return (*boolValue)(p)
-}
-
-func (b *boolValue) Set(s string) error {
- v, err := strconv.ParseBool(s)
- if err != nil {
- err = errParse
- }
- *b = boolValue(v)
- return err
-}
-
-func (b *boolValue) Get() interface{} { return bool(*b) }
-
-func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) }
-
-func (b *boolValue) IsBoolFlag() bool { return true }
-
-// optional interface to indicate boolean flags that can be
-// supplied without "=value" text
-type boolFlag interface {
- Value
- IsBoolFlag() bool
-}
-
-// -- int Value
-type intValue int
-
-func newIntValue(val int, p *int) *intValue {
- *p = val
- return (*intValue)(p)
-}
-
-func (i *intValue) Set(s string) error {
- v, err := strconv.ParseInt(s, 0, strconv.IntSize)
- if err != nil {
- err = numError(err)
- }
- *i = intValue(v)
- return err
-}
-
-func (i *intValue) Get() interface{} { return int(*i) }
-
-func (i *intValue) String() string { return strconv.Itoa(int(*i)) }
-
-// -- int64 Value
-type int64Value int64
-
-func newInt64Value(val int64, p *int64) *int64Value {
- *p = val
- return (*int64Value)(p)
-}
-
-func (i *int64Value) Set(s string) error {
- v, err := strconv.ParseInt(s, 0, 64)
- if err != nil {
- err = numError(err)
- }
- *i = int64Value(v)
- return err
-}
-
-func (i *int64Value) Get() interface{} { return int64(*i) }
-
-func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) }
-
-// -- uint Value
-type uintValue uint
-
-func newUintValue(val uint, p *uint) *uintValue {
- *p = val
- return (*uintValue)(p)
-}
-
-func (i *uintValue) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, strconv.IntSize)
- if err != nil {
- err = numError(err)
- }
- *i = uintValue(v)
- return err
-}
-
-func (i *uintValue) Get() interface{} { return uint(*i) }
-
-func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-// -- uint64 Value
-type uint64Value uint64
-
-func newUint64Value(val uint64, p *uint64) *uint64Value {
- *p = val
- return (*uint64Value)(p)
-}
-
-func (i *uint64Value) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, 64)
- if err != nil {
- err = numError(err)
- }
- *i = uint64Value(v)
- return err
-}
-
-func (i *uint64Value) Get() interface{} { return uint64(*i) }
-
-func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-// -- string Value
-type stringValue string
-
-func newStringValue(val string, p *string) *stringValue {
- *p = val
- return (*stringValue)(p)
-}
-
-func (s *stringValue) Set(val string) error {
- *s = stringValue(val)
- return nil
-}
-
-func (s *stringValue) Get() interface{} { return string(*s) }
-
-func (s *stringValue) String() string { return string(*s) }
-
-// -- float64 Value
-type float64Value float64
-
-func newFloat64Value(val float64, p *float64) *float64Value {
- *p = val
- return (*float64Value)(p)
-}
-
-func (f *float64Value) Set(s string) error {
- v, err := strconv.ParseFloat(s, 64)
- if err != nil {
- err = numError(err)
- }
- *f = float64Value(v)
- return err
-}
-
-func (f *float64Value) Get() interface{} { return float64(*f) }
-
-func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) }
-
-// -- time.Duration Value
-type durationValue time.Duration
-
-func newDurationValue(val time.Duration, p *time.Duration) *durationValue {
- *p = val
- return (*durationValue)(p)
-}
-
-func (d *durationValue) Set(s string) error {
- v, err := time.ParseDuration(s)
- if err != nil {
- err = errParse
- }
- *d = durationValue(v)
- return err
-}
-
-func (d *durationValue) Get() interface{} { return time.Duration(*d) }
-
-func (d *durationValue) String() string { return (*time.Duration)(d).String() }
-
-// Value is the interface to the dynamic value stored in a flag.
-// (The default value is represented as a string.)
-//
-// If a Value has an IsBoolFlag() bool method returning true,
-// the command-line parser makes -name equivalent to -name=true
-// rather than using the next command-line argument.
-//
-// Set is called once, in command line order, for each flag present.
-// The flag package may call the String method with a zero-valued receiver,
-// such as a nil pointer.
-type Value interface {
- String() string
- Set(string) error
-}
-
-// Getter is an interface that allows the contents of a Value to be retrieved.
-// It wraps the Value interface, rather than being part of it, because it
-// appeared after Go 1 and its compatibility rules. All Value types provided
-// by this package satisfy the Getter interface.
-type Getter interface {
- Value
- Get() interface{}
-}
-
-// ErrorHandling defines how FlagSet.Parse behaves if the parse fails.
-type ErrorHandling int
-
-// These constants cause FlagSet.Parse to behave as described if the parse fails.
-const (
- ContinueOnError ErrorHandling = iota // Return a descriptive error.
- ExitOnError // Call os.Exit(2).
- PanicOnError // Call panic with a descriptive error.
-)
-
-// A FlagSet represents a set of defined flags. The zero value of a FlagSet
-// has no name and has ContinueOnError error handling.
-type FlagSet struct {
- // Usage is the function called when an error occurs while parsing flags.
- // The field is a function (not a method) that may be changed to point to
- // a custom error handler. What happens after Usage is called depends
- // on the ErrorHandling setting; for the command line, this defaults
- // to ExitOnError, which exits the program after calling Usage.
- Usage func()
-
- name string
- parsed bool
- actual map[string]*Flag
- formal map[string]*Flag
- args []string // arguments after flags
- errorHandling ErrorHandling
- output io.Writer // nil means stderr; use out() accessor
-}
-
-// A Flag represents the state of a flag.
-type Flag struct {
- Name string // name as it appears on command line
- Usage string // help message
- Value Value // value as set
- DefValue string // default value (as text); for usage message
-}
-
-// sortFlags returns the flags as a slice in lexicographical sorted order.
-func sortFlags(flags map[string]*Flag) []*Flag {
- list := make(sort.StringSlice, len(flags))
- i := 0
- for _, f := range flags {
- list[i] = f.Name
- i++
- }
- list.Sort()
- result := make([]*Flag, len(list))
- for i, name := range list {
- result[i] = flags[name]
- }
- return result
-}
-
-// Output returns the destination for usage and error messages. os.Stderr is returned if
-// output was not set or was set to nil.
-func (f *FlagSet) Output() io.Writer {
- if f.output == nil {
- return os.Stderr
- }
- return f.output
-}
-
-// Name returns the name of the flag set.
-func (f *FlagSet) Name() string {
- return f.name
-}
-
-// ErrorHandling returns the error handling behavior of the flag set.
-func (f *FlagSet) ErrorHandling() ErrorHandling {
- return f.errorHandling
-}
-
-// SetOutput sets the destination for usage and error messages.
-// If output is nil, os.Stderr is used.
-func (f *FlagSet) SetOutput(output io.Writer) {
- f.output = output
-}
-
-// VisitAll visits the flags in lexicographical order, calling fn for each.
-// It visits all flags, even those not set.
-func (f *FlagSet) VisitAll(fn func(*Flag)) {
- for _, flag := range sortFlags(f.formal) {
- fn(flag)
- }
-}
-
-// VisitAll visits the command-line flags in lexicographical order, calling
-// fn for each. It visits all flags, even those not set.
-func VisitAll(fn func(*Flag)) {
- CommandLine.VisitAll(fn)
-}
-
-// Visit visits the flags in lexicographical order, calling fn for each.
-// It visits only those flags that have been set.
-func (f *FlagSet) Visit(fn func(*Flag)) {
- for _, flag := range sortFlags(f.actual) {
- fn(flag)
- }
-}
-
-// Visit visits the command-line flags in lexicographical order, calling fn
-// for each. It visits only those flags that have been set.
-func Visit(fn func(*Flag)) {
- CommandLine.Visit(fn)
-}
-
-// Lookup returns the Flag structure of the named flag, returning nil if none exists.
-func (f *FlagSet) Lookup(name string) *Flag {
- return f.formal[name]
-}
-
-// Lookup returns the Flag structure of the named command-line flag,
-// returning nil if none exists.
-func Lookup(name string) *Flag {
- return CommandLine.formal[name]
-}
-
-// Set sets the value of the named flag.
-func (f *FlagSet) Set(name, value string) error {
- flag, ok := f.formal[name]
- if !ok {
- return fmt.Errorf("no such flag -%v", name)
- }
- err := flag.Value.Set(value)
- if err != nil {
- return err
- }
- if f.actual == nil {
- f.actual = make(map[string]*Flag)
- }
- f.actual[name] = flag
- return nil
-}
-
-// Set sets the value of the named command-line flag.
-func Set(name, value string) error {
- return CommandLine.Set(name, value)
-}
-
-// isZeroValue determines whether the string represents the zero
-// value for a flag.
-func isZeroValue(flag *Flag, value string) bool {
- // Build a zero value of the flag's Value type, and see if the
- // result of calling its String method equals the value passed in.
- // This works unless the Value type is itself an interface type.
- typ := reflect.TypeOf(flag.Value)
- var z reflect.Value
- if typ.Kind() == reflect.Ptr {
- z = reflect.New(typ.Elem())
- } else {
- z = reflect.Zero(typ)
- }
- return value == z.Interface().(Value).String()
-}
-
-// UnquoteUsage extracts a back-quoted name from the usage
-// string for a flag and returns it and the un-quoted usage.
-// Given "a `name` to show" it returns ("name", "a name to show").
-// If there are no back quotes, the name is an educated guess of the
-// type of the flag's value, or the empty string if the flag is boolean.
-func UnquoteUsage(flag *Flag) (name string, usage string) {
- // Look for a back-quoted name, but avoid the strings package.
- usage = flag.Usage
- for i := 0; i < len(usage); i++ {
- if usage[i] == '`' {
- for j := i + 1; j < len(usage); j++ {
- if usage[j] == '`' {
- name = usage[i+1 : j]
- usage = usage[:i] + name + usage[j+1:]
- return name, usage
- }
- }
- break // Only one back quote; use type name.
- }
- }
- // No explicit name, so use type if we can find one.
- name = "value"
- switch flag.Value.(type) {
- case boolFlag:
- name = ""
- case *durationValue:
- name = "duration"
- case *float64Value:
- name = "float"
- case *intValue, *int64Value:
- name = "int"
- case *stringValue:
- name = "string"
- case *uintValue, *uint64Value:
- name = "uint"
- }
- return
-}
-
-// PrintDefaults prints, to standard error unless configured otherwise, the
-// default values of all defined command-line flags in the set. See the
-// documentation for the global function PrintDefaults for more information.
-func (f *FlagSet) PrintDefaults() {
- f.VisitAll(func(flag *Flag) {
- s := fmt.Sprintf(" -%s", flag.Name) // Two spaces before -; see next two comments.
- name, usage := UnquoteUsage(flag)
- if len(name) > 0 {
- s += " " + name
- }
- // Boolean flags of one ASCII letter are so common we
- // treat them specially, putting their usage on the same line.
- if len(s) <= 4 { // space, space, '-', 'x'.
- s += "\t"
- } else {
- // Four spaces before the tab triggers good alignment
- // for both 4- and 8-space tab stops.
- s += "\n \t"
- }
- s += strings.ReplaceAll(usage, "\n", "\n \t")
-
- if !isZeroValue(flag, flag.DefValue) {
- if _, ok := flag.Value.(*stringValue); ok {
- // put quotes on the value
- s += fmt.Sprintf(" (default %q)", flag.DefValue)
- } else {
- s += fmt.Sprintf(" (default %v)", flag.DefValue)
- }
- }
- fmt.Fprint(f.Output(), s, "\n")
- })
-}
-
-// PrintDefaults prints, to standard error unless configured otherwise,
-// a usage message showing the default settings of all defined
-// command-line flags.
-// For an integer valued flag x, the default output has the form
-// -x int
-// usage-message-for-x (default 7)
-// The usage message will appear on a separate line for anything but
-// a bool flag with a one-byte name. For bool flags, the type is
-// omitted and if the flag name is one byte the usage message appears
-// on the same line. The parenthetical default is omitted if the
-// default is the zero value for the type. The listed type, here int,
-// can be changed by placing a back-quoted name in the flag's usage
-// string; the first such item in the message is taken to be a parameter
-// name to show in the message and the back quotes are stripped from
-// the message when displayed. For instance, given
-// flag.String("I", "", "search `directory` for include files")
-// the output will be
-// -I directory
-// search directory for include files.
-//
-// To change the destination for flag messages, call CommandLine.SetOutput.
-func PrintDefaults() {
- CommandLine.PrintDefaults()
-}
-
-// defaultUsage is the default function to print a usage message.
-func (f *FlagSet) defaultUsage() {
- if f.name == "" {
- fmt.Fprintf(f.Output(), "Usage:\n")
- } else {
- fmt.Fprintf(f.Output(), "Usage of %s:\n", f.name)
- }
- f.PrintDefaults()
-}
-
-// NOTE: Usage is not just defaultUsage(CommandLine)
-// because it serves (via godoc flag Usage) as the example
-// for how to write your own usage function.
-
-// Usage prints a usage message documenting all defined command-line flags
-// to CommandLine's output, which by default is os.Stderr.
-// It is called when an error occurs while parsing flags.
-// The function is a variable that may be changed to point to a custom function.
-// By default it prints a simple header and calls PrintDefaults; for details about the
-// format of the output and how to control it, see the documentation for PrintDefaults.
-// Custom usage functions may choose to exit the program; by default exiting
-// happens anyway as the command line's error handling strategy is set to
-// ExitOnError.
-var Usage = func() {
- fmt.Fprintf(CommandLine.Output(), "Usage of %s:\n", os.Args[0])
- PrintDefaults()
-}
-
-// NFlag returns the number of flags that have been set.
-func (f *FlagSet) NFlag() int { return len(f.actual) }
-
-// NFlag returns the number of command-line flags that have been set.
-func NFlag() int { return len(CommandLine.actual) }
-
-// Arg returns the i'th argument. Arg(0) is the first remaining argument
-// after flags have been processed. Arg returns an empty string if the
-// requested element does not exist.
-func (f *FlagSet) Arg(i int) string {
- if i < 0 || i >= len(f.args) {
- return ""
- }
- return f.args[i]
-}
-
-// Arg returns the i'th command-line argument. Arg(0) is the first remaining argument
-// after flags have been processed. Arg returns an empty string if the
-// requested element does not exist.
-func Arg(i int) string {
- return CommandLine.Arg(i)
-}
-
-// NArg is the number of arguments remaining after flags have been processed.
-func (f *FlagSet) NArg() int { return len(f.args) }
-
-// NArg is the number of arguments remaining after flags have been processed.
-func NArg() int { return len(CommandLine.args) }
-
-// Args returns the non-flag arguments.
-func (f *FlagSet) Args() []string { return f.args }
-
-// Args returns the non-flag command-line arguments.
-func Args() []string { return CommandLine.args }
-
-// BoolVar defines a bool flag with specified name, default value, and usage string.
-// The argument p points to a bool variable in which to store the value of the flag.
-func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
- f.Var(newBoolValue(value, p), name, usage)
-}
-
-// BoolVar defines a bool flag with specified name, default value, and usage string.
-// The argument p points to a bool variable in which to store the value of the flag.
-func BoolVar(p *bool, name string, value bool, usage string) {
- CommandLine.Var(newBoolValue(value, p), name, usage)
-}
-
-// Bool defines a bool flag with specified name, default value, and usage string.
-// The return value is the address of a bool variable that stores the value of the flag.
-func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
- p := new(bool)
- f.BoolVar(p, name, value, usage)
- return p
-}
-
-// Bool defines a bool flag with specified name, default value, and usage string.
-// The return value is the address of a bool variable that stores the value of the flag.
-func Bool(name string, value bool, usage string) *bool {
- return CommandLine.Bool(name, value, usage)
-}
-
-// IntVar defines an int flag with specified name, default value, and usage string.
-// The argument p points to an int variable in which to store the value of the flag.
-func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
- f.Var(newIntValue(value, p), name, usage)
-}
-
-// IntVar defines an int flag with specified name, default value, and usage string.
-// The argument p points to an int variable in which to store the value of the flag.
-func IntVar(p *int, name string, value int, usage string) {
- CommandLine.Var(newIntValue(value, p), name, usage)
-}
-
-// Int defines an int flag with specified name, default value, and usage string.
-// The return value is the address of an int variable that stores the value of the flag.
-func (f *FlagSet) Int(name string, value int, usage string) *int {
- p := new(int)
- f.IntVar(p, name, value, usage)
- return p
-}
-
-// Int defines an int flag with specified name, default value, and usage string.
-// The return value is the address of an int variable that stores the value of the flag.
-func Int(name string, value int, usage string) *int {
- return CommandLine.Int(name, value, usage)
-}
-
-// Int64Var defines an int64 flag with specified name, default value, and usage string.
-// The argument p points to an int64 variable in which to store the value of the flag.
-func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
- f.Var(newInt64Value(value, p), name, usage)
-}
-
-// Int64Var defines an int64 flag with specified name, default value, and usage string.
-// The argument p points to an int64 variable in which to store the value of the flag.
-func Int64Var(p *int64, name string, value int64, usage string) {
- CommandLine.Var(newInt64Value(value, p), name, usage)
-}
-
-// Int64 defines an int64 flag with specified name, default value, and usage string.
-// The return value is the address of an int64 variable that stores the value of the flag.
-func (f *FlagSet) Int64(name string, value int64, usage string) *int64 {
- p := new(int64)
- f.Int64Var(p, name, value, usage)
- return p
-}
-
-// Int64 defines an int64 flag with specified name, default value, and usage string.
-// The return value is the address of an int64 variable that stores the value of the flag.
-func Int64(name string, value int64, usage string) *int64 {
- return CommandLine.Int64(name, value, usage)
-}
-
-// UintVar defines a uint flag with specified name, default value, and usage string.
-// The argument p points to a uint variable in which to store the value of the flag.
-func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
- f.Var(newUintValue(value, p), name, usage)
-}
-
-// UintVar defines a uint flag with specified name, default value, and usage string.
-// The argument p points to a uint variable in which to store the value of the flag.
-func UintVar(p *uint, name string, value uint, usage string) {
- CommandLine.Var(newUintValue(value, p), name, usage)
-}
-
-// Uint defines a uint flag with specified name, default value, and usage string.
-// The return value is the address of a uint variable that stores the value of the flag.
-func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
- p := new(uint)
- f.UintVar(p, name, value, usage)
- return p
-}
-
-// Uint defines a uint flag with specified name, default value, and usage string.
-// The return value is the address of a uint variable that stores the value of the flag.
-func Uint(name string, value uint, usage string) *uint {
- return CommandLine.Uint(name, value, usage)
-}
-
-// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
-// The argument p points to a uint64 variable in which to store the value of the flag.
-func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) {
- f.Var(newUint64Value(value, p), name, usage)
-}
-
-// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
-// The argument p points to a uint64 variable in which to store the value of the flag.
-func Uint64Var(p *uint64, name string, value uint64, usage string) {
- CommandLine.Var(newUint64Value(value, p), name, usage)
-}
-
-// Uint64 defines a uint64 flag with specified name, default value, and usage string.
-// The return value is the address of a uint64 variable that stores the value of the flag.
-func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
- p := new(uint64)
- f.Uint64Var(p, name, value, usage)
- return p
-}
-
-// Uint64 defines a uint64 flag with specified name, default value, and usage string.
-// The return value is the address of a uint64 variable that stores the value of the flag.
-func Uint64(name string, value uint64, usage string) *uint64 {
- return CommandLine.Uint64(name, value, usage)
-}
-
-// StringVar defines a string flag with specified name, default value, and usage string.
-// The argument p points to a string variable in which to store the value of the flag.
-func (f *FlagSet) StringVar(p *string, name string, value string, usage string) {
- f.Var(newStringValue(value, p), name, usage)
-}
-
-// StringVar defines a string flag with specified name, default value, and usage string.
-// The argument p points to a string variable in which to store the value of the flag.
-func StringVar(p *string, name string, value string, usage string) {
- CommandLine.Var(newStringValue(value, p), name, usage)
-}
-
-// String defines a string flag with specified name, default value, and usage string.
-// The return value is the address of a string variable that stores the value of the flag.
-func (f *FlagSet) String(name string, value string, usage string) *string {
- p := new(string)
- f.StringVar(p, name, value, usage)
- return p
-}
-
-// String defines a string flag with specified name, default value, and usage string.
-// The return value is the address of a string variable that stores the value of the flag.
-func String(name string, value string, usage string) *string {
- return CommandLine.String(name, value, usage)
-}
-
-// Float64Var defines a float64 flag with specified name, default value, and usage string.
-// The argument p points to a float64 variable in which to store the value of the flag.
-func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
- f.Var(newFloat64Value(value, p), name, usage)
-}
-
-// Float64Var defines a float64 flag with specified name, default value, and usage string.
-// The argument p points to a float64 variable in which to store the value of the flag.
-func Float64Var(p *float64, name string, value float64, usage string) {
- CommandLine.Var(newFloat64Value(value, p), name, usage)
-}
-
-// Float64 defines a float64 flag with specified name, default value, and usage string.
-// The return value is the address of a float64 variable that stores the value of the flag.
-func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
- p := new(float64)
- f.Float64Var(p, name, value, usage)
- return p
-}
-
-// Float64 defines a float64 flag with specified name, default value, and usage string.
-// The return value is the address of a float64 variable that stores the value of the flag.
-func Float64(name string, value float64, usage string) *float64 {
- return CommandLine.Float64(name, value, usage)
-}
-
-// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
-// The argument p points to a time.Duration variable in which to store the value of the flag.
-// The flag accepts a value acceptable to time.ParseDuration.
-func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
- f.Var(newDurationValue(value, p), name, usage)
-}
-
-// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
-// The argument p points to a time.Duration variable in which to store the value of the flag.
-// The flag accepts a value acceptable to time.ParseDuration.
-func DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
- CommandLine.Var(newDurationValue(value, p), name, usage)
-}
-
-// Duration defines a time.Duration flag with specified name, default value, and usage string.
-// The return value is the address of a time.Duration variable that stores the value of the flag.
-// The flag accepts a value acceptable to time.ParseDuration.
-func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration {
- p := new(time.Duration)
- f.DurationVar(p, name, value, usage)
- return p
-}
-
-// Duration defines a time.Duration flag with specified name, default value, and usage string.
-// The return value is the address of a time.Duration variable that stores the value of the flag.
-// The flag accepts a value acceptable to time.ParseDuration.
-func Duration(name string, value time.Duration, usage string) *time.Duration {
- return CommandLine.Duration(name, value, usage)
-}
-
-// Var defines a flag with the specified name and usage string. The type and
-// value of the flag are represented by the first argument, of type Value, which
-// typically holds a user-defined implementation of Value. For instance, the
-// caller could create a flag that turns a comma-separated string into a slice
-// of strings by giving the slice the methods of Value; in particular, Set would
-// decompose the comma-separated string into the slice.
-func (f *FlagSet) Var(value Value, name string, usage string) {
- // Remember the default value as a string; it won't change.
- flag := &Flag{name, usage, value, value.String()}
- _, alreadythere := f.formal[name]
- if alreadythere {
- var msg string
- if f.name == "" {
- msg = fmt.Sprintf("flag redefined: %s", name)
- } else {
- msg = fmt.Sprintf("%s flag redefined: %s", f.name, name)
- }
- fmt.Fprintln(f.Output(), msg)
- panic(msg) // Happens only if flags are declared with identical names
- }
- if f.formal == nil {
- f.formal = make(map[string]*Flag)
- }
- f.formal[name] = flag
-}
-
-// Var defines a flag with the specified name and usage string. The type and
-// value of the flag are represented by the first argument, of type Value, which
-// typically holds a user-defined implementation of Value. For instance, the
-// caller could create a flag that turns a comma-separated string into a slice
-// of strings by giving the slice the methods of Value; in particular, Set would
-// decompose the comma-separated string into the slice.
-func Var(value Value, name string, usage string) {
- CommandLine.Var(value, name, usage)
-}
-
-// failf prints to standard error a formatted error and usage message and
-// returns the error.
-func (f *FlagSet) failf(format string, a ...interface{}) error {
- err := fmt.Errorf(format, a...)
- fmt.Fprintln(f.Output(), err)
- f.usage()
- return err
-}
-
-// usage calls the Usage method for the flag set if one is specified,
-// or the appropriate default usage function otherwise.
-func (f *FlagSet) usage() {
- if f.Usage == nil {
- f.defaultUsage()
- } else {
- f.Usage()
- }
-}
-
-// parseOne parses one flag. It reports whether a flag was seen.
-func (f *FlagSet) parseOne() (bool, error) {
- if len(f.args) == 0 {
- return false, nil
- }
- s := f.args[0]
- if len(s) < 2 || s[0] != '-' {
- return false, nil
- }
- numMinuses := 1
- if s[1] == '-' {
- numMinuses++
- if len(s) == 2 { // "--" terminates the flags
- f.args = f.args[1:]
- return false, nil
- }
- }
- name := s[numMinuses:]
- if len(name) == 0 || name[0] == '-' || name[0] == '=' {
- return false, f.failf("bad flag syntax: %s", s)
- }
-
- // it's a flag. does it have an argument?
- f.args = f.args[1:]
- hasValue := false
- value := ""
- for i := 1; i < len(name); i++ { // equals cannot be first
- if name[i] == '=' {
- value = name[i+1:]
- hasValue = true
- name = name[0:i]
- break
- }
- }
- m := f.formal
- flag, alreadythere := m[name] // BUG
- if !alreadythere {
- if name == "help" || name == "h" { // special case for nice help message.
- f.usage()
- return false, ErrHelp
- }
- return false, f.failf("flag provided but not defined: -%s", name)
- }
-
- if fv, ok := flag.Value.(boolFlag); ok && fv.IsBoolFlag() { // special case: doesn't need an arg
- if hasValue {
- if err := fv.Set(value); err != nil {
- return false, f.failf("invalid boolean value %q for -%s: %v", value, name, err)
- }
- } else {
- if err := fv.Set("true"); err != nil {
- return false, f.failf("invalid boolean flag %s: %v", name, err)
- }
- }
- } else {
- // It must have a value, which might be the next argument.
- if !hasValue && len(f.args) > 0 {
- // value is the next arg
- hasValue = true
- value, f.args = f.args[0], f.args[1:]
- }
- if !hasValue {
- return false, f.failf("flag needs an argument: -%s", name)
- }
- if err := flag.Value.Set(value); err != nil {
- return false, f.failf("invalid value %q for flag -%s: %v", value, name, err)
- }
- }
- if f.actual == nil {
- f.actual = make(map[string]*Flag)
- }
- f.actual[name] = flag
- return true, nil
-}
-
-// Parse parses flag definitions from the argument list, which should not
-// include the command name. Must be called after all flags in the FlagSet
-// are defined and before flags are accessed by the program.
-// The return value will be ErrHelp if -help or -h were set but not defined.
-func (f *FlagSet) Parse(arguments []string) error {
- f.parsed = true
- f.args = arguments
- for {
- seen, err := f.parseOne()
- if seen {
- continue
- }
- if err == nil {
- break
- }
- switch f.errorHandling {
- case ContinueOnError:
- return err
- case ExitOnError:
- os.Exit(2)
- case PanicOnError:
- panic(err)
- }
- }
- return nil
-}
-
-// Parsed reports whether f.Parse has been called.
-func (f *FlagSet) Parsed() bool {
- return f.parsed
-}
-
-// Parse parses the command-line flags from os.Args[1:]. Must be called
-// after all flags are defined and before flags are accessed by the program.
-func Parse() {
- // Ignore errors; CommandLine is set for ExitOnError.
- CommandLine.Parse(os.Args[1:])
-}
-
-// Parsed reports whether the command-line flags have been parsed.
-func Parsed() bool {
- return CommandLine.Parsed()
-}
-
-// CommandLine is the default set of command-line flags, parsed from os.Args.
-// The top-level functions such as BoolVar, Arg, and so on are wrappers for the
-// methods of CommandLine.
-var CommandLine = NewFlagSet(os.Args[0], ExitOnError)
-
-func init() {
- // Override generic FlagSet default Usage with call to global Usage.
- // Note: This is not CommandLine.Usage = Usage,
- // because we want any eventual call to use any updated value of Usage,
- // not the value it has when this line is run.
- CommandLine.Usage = commandLineUsage
-}
-
-func commandLineUsage() {
- Usage()
-}
-
-// NewFlagSet returns a new, empty flag set with the specified name and
-// error handling property. If the name is not empty, it will be printed
-// in the default usage message and in error messages.
-func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet {
- f := &FlagSet{
- name: name,
- errorHandling: errorHandling,
- }
- f.Usage = f.defaultUsage
- return f
-}
-
-// Init sets the name and error handling property for a flag set.
-// By default, the zero FlagSet uses an empty name and the
-// ContinueOnError error handling policy.
-func (f *FlagSet) Init(name string, errorHandling ErrorHandling) {
- f.name = name
- f.errorHandling = errorHandling
-}
diff --git a/internal/stdlib/testdata/v1.12.5/src/flag/flag_test.go b/internal/stdlib/testdata/v1.12.5/src/flag/flag_test.go
deleted file mode 100644
index dc1b2b5..0000000
--- a/internal/stdlib/testdata/v1.12.5/src/flag/flag_test.go
+++ /dev/null
@@ -1,545 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package flag_test
-
-import (
- "bytes"
- . "flag"
- "fmt"
- "io"
- "os"
- "sort"
- "strconv"
- "strings"
- "testing"
- "time"
-)
-
-func boolString(s string) string {
- if s == "0" {
- return "false"
- }
- return "true"
-}
-
-func TestEverything(t *testing.T) {
- ResetForTesting(nil)
- Bool("test_bool", false, "bool value")
- Int("test_int", 0, "int value")
- Int64("test_int64", 0, "int64 value")
- Uint("test_uint", 0, "uint value")
- Uint64("test_uint64", 0, "uint64 value")
- String("test_string", "0", "string value")
- Float64("test_float64", 0, "float64 value")
- Duration("test_duration", 0, "time.Duration value")
-
- m := make(map[string]*Flag)
- desired := "0"
- visitor := func(f *Flag) {
- if len(f.Name) > 5 && f.Name[0:5] == "test_" {
- m[f.Name] = f
- ok := false
- switch {
- case f.Value.String() == desired:
- ok = true
- case f.Name == "test_bool" && f.Value.String() == boolString(desired):
- ok = true
- case f.Name == "test_duration" && f.Value.String() == desired+"s":
- ok = true
- }
- if !ok {
- t.Error("Visit: bad value", f.Value.String(), "for", f.Name)
- }
- }
- }
- VisitAll(visitor)
- if len(m) != 8 {
- t.Error("VisitAll misses some flags")
- for k, v := range m {
- t.Log(k, *v)
- }
- }
- m = make(map[string]*Flag)
- Visit(visitor)
- if len(m) != 0 {
- t.Errorf("Visit sees unset flags")
- for k, v := range m {
- t.Log(k, *v)
- }
- }
- // Now set all flags
- Set("test_bool", "true")
- Set("test_int", "1")
- Set("test_int64", "1")
- Set("test_uint", "1")
- Set("test_uint64", "1")
- Set("test_string", "1")
- Set("test_float64", "1")
- Set("test_duration", "1s")
- desired = "1"
- Visit(visitor)
- if len(m) != 8 {
- t.Error("Visit fails after set")
- for k, v := range m {
- t.Log(k, *v)
- }
- }
- // Now test they're visited in sort order.
- var flagNames []string
- Visit(func(f *Flag) { flagNames = append(flagNames, f.Name) })
- if !sort.StringsAreSorted(flagNames) {
- t.Errorf("flag names not sorted: %v", flagNames)
- }
-}
-
-func TestGet(t *testing.T) {
- ResetForTesting(nil)
- Bool("test_bool", true, "bool value")
- Int("test_int", 1, "int value")
- Int64("test_int64", 2, "int64 value")
- Uint("test_uint", 3, "uint value")
- Uint64("test_uint64", 4, "uint64 value")
- String("test_string", "5", "string value")
- Float64("test_float64", 6, "float64 value")
- Duration("test_duration", 7, "time.Duration value")
-
- visitor := func(f *Flag) {
- if len(f.Name) > 5 && f.Name[0:5] == "test_" {
- g, ok := f.Value.(Getter)
- if !ok {
- t.Errorf("Visit: value does not satisfy Getter: %T", f.Value)
- return
- }
- switch f.Name {
- case "test_bool":
- ok = g.Get() == true
- case "test_int":
- ok = g.Get() == int(1)
- case "test_int64":
- ok = g.Get() == int64(2)
- case "test_uint":
- ok = g.Get() == uint(3)
- case "test_uint64":
- ok = g.Get() == uint64(4)
- case "test_string":
- ok = g.Get() == "5"
- case "test_float64":
- ok = g.Get() == float64(6)
- case "test_duration":
- ok = g.Get() == time.Duration(7)
- }
- if !ok {
- t.Errorf("Visit: bad value %T(%v) for %s", g.Get(), g.Get(), f.Name)
- }
- }
- }
- VisitAll(visitor)
-}
-
-func TestUsage(t *testing.T) {
- called := false
- ResetForTesting(func() { called = true })
- if CommandLine.Parse([]string{"-x"}) == nil {
- t.Error("parse did not fail for unknown flag")
- }
- if !called {
- t.Error("did not call Usage for unknown flag")
- }
-}
-
-func testParse(f *FlagSet, t *testing.T) {
- if f.Parsed() {
- t.Error("f.Parse() = true before Parse")
- }
- boolFlag := f.Bool("bool", false, "bool value")
- bool2Flag := f.Bool("bool2", false, "bool2 value")
- intFlag := f.Int("int", 0, "int value")
- int64Flag := f.Int64("int64", 0, "int64 value")
- uintFlag := f.Uint("uint", 0, "uint value")
- uint64Flag := f.Uint64("uint64", 0, "uint64 value")
- stringFlag := f.String("string", "0", "string value")
- float64Flag := f.Float64("float64", 0, "float64 value")
- durationFlag := f.Duration("duration", 5*time.Second, "time.Duration value")
- extra := "one-extra-argument"
- args := []string{
- "-bool",
- "-bool2=true",
- "--int", "22",
- "--int64", "0x23",
- "-uint", "24",
- "--uint64", "25",
- "-string", "hello",
- "-float64", "2718e28",
- "-duration", "2m",
- extra,
- }
- if err := f.Parse(args); err != nil {
- t.Fatal(err)
- }
- if !f.Parsed() {
- t.Error("f.Parse() = false after Parse")
- }
- if *boolFlag != true {
- t.Error("bool flag should be true, is ", *boolFlag)
- }
- if *bool2Flag != true {
- t.Error("bool2 flag should be true, is ", *bool2Flag)
- }
- if *intFlag != 22 {
- t.Error("int flag should be 22, is ", *intFlag)
- }
- if *int64Flag != 0x23 {
- t.Error("int64 flag should be 0x23, is ", *int64Flag)
- }
- if *uintFlag != 24 {
- t.Error("uint flag should be 24, is ", *uintFlag)
- }
- if *uint64Flag != 25 {
- t.Error("uint64 flag should be 25, is ", *uint64Flag)
- }
- if *stringFlag != "hello" {
- t.Error("string flag should be `hello`, is ", *stringFlag)
- }
- if *float64Flag != 2718e28 {
- t.Error("float64 flag should be 2718e28, is ", *float64Flag)
- }
- if *durationFlag != 2*time.Minute {
- t.Error("duration flag should be 2m, is ", *durationFlag)
- }
- if len(f.Args()) != 1 {
- t.Error("expected one argument, got", len(f.Args()))
- } else if f.Args()[0] != extra {
- t.Errorf("expected argument %q got %q", extra, f.Args()[0])
- }
-}
-
-func TestParse(t *testing.T) {
- ResetForTesting(func() { t.Error("bad parse") })
- testParse(CommandLine, t)
-}
-
-func TestFlagSetParse(t *testing.T) {
- testParse(NewFlagSet("test", ContinueOnError), t)
-}
-
-// Declare a user-defined flag type.
-type flagVar []string
-
-func (f *flagVar) String() string {
- return fmt.Sprint([]string(*f))
-}
-
-func (f *flagVar) Set(value string) error {
- *f = append(*f, value)
- return nil
-}
-
-func TestUserDefined(t *testing.T) {
- var flags FlagSet
- flags.Init("test", ContinueOnError)
- var v flagVar
- flags.Var(&v, "v", "usage")
- if err := flags.Parse([]string{"-v", "1", "-v", "2", "-v=3"}); err != nil {
- t.Error(err)
- }
- if len(v) != 3 {
- t.Fatal("expected 3 args; got ", len(v))
- }
- expect := "[1 2 3]"
- if v.String() != expect {
- t.Errorf("expected value %q got %q", expect, v.String())
- }
-}
-
-func TestUserDefinedForCommandLine(t *testing.T) {
- const help = "HELP"
- var result string
- ResetForTesting(func() { result = help })
- Usage()
- if result != help {
- t.Fatalf("got %q; expected %q", result, help)
- }
-}
-
-// Declare a user-defined boolean flag type.
-type boolFlagVar struct {
- count int
-}
-
-func (b *boolFlagVar) String() string {
- return fmt.Sprintf("%d", b.count)
-}
-
-func (b *boolFlagVar) Set(value string) error {
- if value == "true" {
- b.count++
- }
- return nil
-}
-
-func (b *boolFlagVar) IsBoolFlag() bool {
- return b.count < 4
-}
-
-func TestUserDefinedBool(t *testing.T) {
- var flags FlagSet
- flags.Init("test", ContinueOnError)
- var b boolFlagVar
- var err error
- flags.Var(&b, "b", "usage")
- if err = flags.Parse([]string{"-b", "-b", "-b", "-b=true", "-b=false", "-b", "barg", "-b"}); err != nil {
- if b.count < 4 {
- t.Error(err)
- }
- }
-
- if b.count != 4 {
- t.Errorf("want: %d; got: %d", 4, b.count)
- }
-
- if err == nil {
- t.Error("expected error; got none")
- }
-}
-
-func TestSetOutput(t *testing.T) {
- var flags FlagSet
- var buf bytes.Buffer
- flags.SetOutput(&buf)
- flags.Init("test", ContinueOnError)
- flags.Parse([]string{"-unknown"})
- if out := buf.String(); !strings.Contains(out, "-unknown") {
- t.Logf("expected output mentioning unknown; got %q", out)
- }
-}
-
-// This tests that one can reset the flags. This still works but not well, and is
-// superseded by FlagSet.
-func TestChangingArgs(t *testing.T) {
- ResetForTesting(func() { t.Fatal("bad parse") })
- oldArgs := os.Args
- defer func() { os.Args = oldArgs }()
- os.Args = []string{"cmd", "-before", "subcmd", "-after", "args"}
- before := Bool("before", false, "")
- if err := CommandLine.Parse(os.Args[1:]); err != nil {
- t.Fatal(err)
- }
- cmd := Arg(0)
- os.Args = Args()
- after := Bool("after", false, "")
- Parse()
- args := Args()
-
- if !*before || cmd != "subcmd" || !*after || len(args) != 1 || args[0] != "args" {
- t.Fatalf("expected true subcmd true [args] got %v %v %v %v", *before, cmd, *after, args)
- }
-}
-
-// Test that -help invokes the usage message and returns ErrHelp.
-func TestHelp(t *testing.T) {
- var helpCalled = false
- fs := NewFlagSet("help test", ContinueOnError)
- fs.Usage = func() { helpCalled = true }
- var flag bool
- fs.BoolVar(&flag, "flag", false, "regular flag")
- // Regular flag invocation should work
- err := fs.Parse([]string{"-flag=true"})
- if err != nil {
- t.Fatal("expected no error; got ", err)
- }
- if !flag {
- t.Error("flag was not set by -flag")
- }
- if helpCalled {
- t.Error("help called for regular flag")
- helpCalled = false // reset for next test
- }
- // Help flag should work as expected.
- err = fs.Parse([]string{"-help"})
- if err == nil {
- t.Fatal("error expected")
- }
- if err != ErrHelp {
- t.Fatal("expected ErrHelp; got ", err)
- }
- if !helpCalled {
- t.Fatal("help was not called")
- }
- // If we define a help flag, that should override.
- var help bool
- fs.BoolVar(&help, "help", false, "help flag")
- helpCalled = false
- err = fs.Parse([]string{"-help"})
- if err != nil {
- t.Fatal("expected no error for defined -help; got ", err)
- }
- if helpCalled {
- t.Fatal("help was called; should not have been for defined help flag")
- }
-}
-
-const defaultOutput = ` -A for bootstrapping, allow 'any' type
- -Alongflagname
- disable bounds checking
- -C a boolean defaulting to true (default true)
- -D path
- set relative path for local imports
- -E string
- issue 23543 (default "0")
- -F number
- a non-zero number (default 2.7)
- -G float
- a float that defaults to zero
- -M string
- a multiline
- help
- string
- -N int
- a non-zero int (default 27)
- -O a flag
- multiline help string (default true)
- -Z int
- an int that defaults to zero
- -maxT timeout
- set timeout for dial
-`
-
-func TestPrintDefaults(t *testing.T) {
- fs := NewFlagSet("print defaults test", ContinueOnError)
- var buf bytes.Buffer
- fs.SetOutput(&buf)
- fs.Bool("A", false, "for bootstrapping, allow 'any' type")
- fs.Bool("Alongflagname", false, "disable bounds checking")
- fs.Bool("C", true, "a boolean defaulting to true")
- fs.String("D", "", "set relative `path` for local imports")
- fs.String("E", "0", "issue 23543")
- fs.Float64("F", 2.7, "a non-zero `number`")
- fs.Float64("G", 0, "a float that defaults to zero")
- fs.String("M", "", "a multiline\nhelp\nstring")
- fs.Int("N", 27, "a non-zero int")
- fs.Bool("O", true, "a flag\nmultiline help string")
- fs.Int("Z", 0, "an int that defaults to zero")
- fs.Duration("maxT", 0, "set `timeout` for dial")
- fs.PrintDefaults()
- got := buf.String()
- if got != defaultOutput {
- t.Errorf("got %q want %q\n", got, defaultOutput)
- }
-}
-
-// Issue 19230: validate range of Int and Uint flag values.
-func TestIntFlagOverflow(t *testing.T) {
- if strconv.IntSize != 32 {
- return
- }
- ResetForTesting(nil)
- Int("i", 0, "")
- Uint("u", 0, "")
- if err := Set("i", "2147483648"); err == nil {
- t.Error("unexpected success setting Int")
- }
- if err := Set("u", "4294967296"); err == nil {
- t.Error("unexpected success setting Uint")
- }
-}
-
-// Issue 20998: Usage should respect CommandLine.output.
-func TestUsageOutput(t *testing.T) {
- ResetForTesting(DefaultUsage)
- var buf bytes.Buffer
- CommandLine.SetOutput(&buf)
- defer func(old []string) { os.Args = old }(os.Args)
- os.Args = []string{"app", "-i=1", "-unknown"}
- Parse()
- const want = "flag provided but not defined: -i\nUsage of app:\n"
- if got := buf.String(); got != want {
- t.Errorf("output = %q; want %q", got, want)
- }
-}
-
-func TestGetters(t *testing.T) {
- expectedName := "flag set"
- expectedErrorHandling := ContinueOnError
- expectedOutput := io.Writer(os.Stderr)
- fs := NewFlagSet(expectedName, expectedErrorHandling)
-
- if fs.Name() != expectedName {
- t.Errorf("unexpected name: got %s, expected %s", fs.Name(), expectedName)
- }
- if fs.ErrorHandling() != expectedErrorHandling {
- t.Errorf("unexpected ErrorHandling: got %d, expected %d", fs.ErrorHandling(), expectedErrorHandling)
- }
- if fs.Output() != expectedOutput {
- t.Errorf("unexpected output: got %#v, expected %#v", fs.Output(), expectedOutput)
- }
-
- expectedName = "gopher"
- expectedErrorHandling = ExitOnError
- expectedOutput = os.Stdout
- fs.Init(expectedName, expectedErrorHandling)
- fs.SetOutput(expectedOutput)
-
- if fs.Name() != expectedName {
- t.Errorf("unexpected name: got %s, expected %s", fs.Name(), expectedName)
- }
- if fs.ErrorHandling() != expectedErrorHandling {
- t.Errorf("unexpected ErrorHandling: got %d, expected %d", fs.ErrorHandling(), expectedErrorHandling)
- }
- if fs.Output() != expectedOutput {
- t.Errorf("unexpected output: got %v, expected %v", fs.Output(), expectedOutput)
- }
-}
-
-func TestParseError(t *testing.T) {
- for _, typ := range []string{"bool", "int", "int64", "uint", "uint64", "float64", "duration"} {
- fs := NewFlagSet("parse error test", ContinueOnError)
- fs.SetOutput(io.Discard)
- _ = fs.Bool("bool", false, "")
- _ = fs.Int("int", 0, "")
- _ = fs.Int64("int64", 0, "")
- _ = fs.Uint("uint", 0, "")
- _ = fs.Uint64("uint64", 0, "")
- _ = fs.Float64("float64", 0, "")
- _ = fs.Duration("duration", 0, "")
- // Strings cannot give errors.
- args := []string{"-" + typ + "=x"}
- err := fs.Parse(args) // x is not a valid setting for any flag.
- if err == nil {
- t.Errorf("Parse(%q)=%v; expected parse error", args, err)
- continue
- }
- if !strings.Contains(err.Error(), "invalid") || !strings.Contains(err.Error(), "parse error") {
- t.Errorf("Parse(%q)=%v; expected parse error", args, err)
- }
- }
-}
-
-func TestRangeError(t *testing.T) {
- bad := []string{
- "-int=123456789012345678901",
- "-int64=123456789012345678901",
- "-uint=123456789012345678901",
- "-uint64=123456789012345678901",
- "-float64=1e1000",
- }
- for _, arg := range bad {
- fs := NewFlagSet("parse error test", ContinueOnError)
- fs.SetOutput(io.Discard)
- _ = fs.Int("int", 0, "")
- _ = fs.Int64("int64", 0, "")
- _ = fs.Uint("uint", 0, "")
- _ = fs.Uint64("uint64", 0, "")
- _ = fs.Float64("float64", 0, "")
- // Strings cannot give errors, and bools and durations do not return strconv.NumError.
- err := fs.Parse([]string{arg})
- if err == nil {
- t.Errorf("Parse(%q)=%v; expected range error", arg, err)
- continue
- }
- if !strings.Contains(err.Error(), "invalid") || !strings.Contains(err.Error(), "value out of range") {
- t.Errorf("Parse(%q)=%v; expected range error", arg, err)
- }
- }
-}
diff --git a/internal/stdlib/testdata/v1.14.6/LICENSE b/internal/stdlib/testdata/v1.14.6/LICENSE
deleted file mode 100644
index 6a66aea..0000000
--- a/internal/stdlib/testdata/v1.14.6/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2009 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/internal/stdlib/testdata/v1.14.6/README.md b/internal/stdlib/testdata/v1.14.6/README.md
deleted file mode 100644
index d6d2b9d..0000000
--- a/internal/stdlib/testdata/v1.14.6/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# The Go Programming Language
diff --git a/internal/stdlib/testdata/v1.14.6/src/README.vendor b/internal/stdlib/testdata/v1.14.6/src/README.vendor
deleted file mode 100644
index e74fc2f..0000000
--- a/internal/stdlib/testdata/v1.14.6/src/README.vendor
+++ /dev/null
@@ -1,54 +0,0 @@
-Vendoring in std and cmd
-========================
-
-The Go command maintains copies of external packages needed by the
-standard library in the src/vendor and src/cmd/vendor directories.
-
-In GOPATH mode, imports of vendored packages are resolved to these
-directories following normal vendor directory logic
-(see golang.org/s/go15vendor).
-
-In module mode, std and cmd are modules (defined in src/go.mod and
-src/cmd/go.mod). When a package outside std or cmd is imported
-by a package inside std or cmd, the import path is interpreted
-as if it had a "vendor/" prefix. For example, within "crypto/tls",
-an import of "golang.org/x/crypto/cryptobyte" resolves to
-"vendor/golang.org/x/crypto/cryptobyte". When a package with the
-same path is imported from a package outside std or cmd, it will
-be resolved normally. Consequently, a binary may be built with two
-copies of a package at different versions if the package is
-imported normally and vendored by the standard library.
-
-Vendored packages are internally renamed with a "vendor/" prefix
-to preserve the invariant that all packages have distinct paths.
-This is necessary to avoid compiler and linker conflicts. Adding
-a "vendor/" prefix also maintains the invariant that standard
-library packages begin with a dotless path element.
-
-The module requirements of std and cmd do not influence version
-selection in other modules. They are only considered when running
-module commands like 'go get' and 'go mod vendor' from a directory
-in GOROOT/src.
-
-Maintaining vendor directories
-==============================
-
-Before updating vendor directories, ensure that module mode is enabled.
-Make sure GO111MODULE=off is not set ('on' or 'auto' should work).
-
-Requirements may be added, updated, and removed with 'go get'.
-The vendor directory may be updated with 'go mod vendor'.
-A typical sequence might be:
-
- cd src
- go get -d golang.org/x/net@latest
- go mod tidy
- go mod vendor
-
-Use caution when passing '-u' to 'go get'. The '-u' flag updates
-modules providing all transitively imported packages, not only
-the module providing the target package.
-
-Note that 'go mod vendor' only copies packages that are transitively
-imported by packages in the current module. If a new package is needed,
-it should be imported before running 'go mod vendor'.
diff --git a/internal/stdlib/testdata/v1.14.6/src/cmd/README.vendor b/internal/stdlib/testdata/v1.14.6/src/cmd/README.vendor
deleted file mode 100644
index ac0df5e..0000000
--- a/internal/stdlib/testdata/v1.14.6/src/cmd/README.vendor
+++ /dev/null
@@ -1,2 +0,0 @@
-See src/README.vendor for information on loading vendored packages
-and updating the vendor directory.
diff --git a/internal/stdlib/testdata/v1.14.6/src/context/context.go b/internal/stdlib/testdata/v1.14.6/src/context/context.go
deleted file mode 100644
index b561968..0000000
--- a/internal/stdlib/testdata/v1.14.6/src/context/context.go
+++ /dev/null
@@ -1,554 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package context defines the Context type, which carries deadlines,
-// cancellation signals, and other request-scoped values across API boundaries
-// and between processes.
-//
-// Incoming requests to a server should create a Context, and outgoing
-// calls to servers should accept a Context. The chain of function
-// calls between them must propagate the Context, optionally replacing
-// it with a derived Context created using WithCancel, WithDeadline,
-// WithTimeout, or WithValue. When a Context is canceled, all
-// Contexts derived from it are also canceled.
-//
-// The WithCancel, WithDeadline, and WithTimeout functions take a
-// Context (the parent) and return a derived Context (the child) and a
-// CancelFunc. Calling the CancelFunc cancels the child and its
-// children, removes the parent's reference to the child, and stops
-// any associated timers. Failing to call the CancelFunc leaks the
-// child and its children until the parent is canceled or the timer
-// fires. The go vet tool checks that CancelFuncs are used on all
-// control-flow paths.
-//
-// Programs that use Contexts should follow these rules to keep interfaces
-// consistent across packages and enable static analysis tools to check context
-// propagation:
-//
-// Do not store Contexts inside a struct type; instead, pass a Context
-// explicitly to each function that needs it. The Context should be the first
-// parameter, typically named ctx:
-//
-// func DoSomething(ctx context.Context, arg Arg) error {
-// // ... use ctx ...
-// }
-//
-// Do not pass a nil Context, even if a function permits it. Pass context.TODO
-// if you are unsure about which Context to use.
-//
-// Use context Values only for request-scoped data that transits processes and
-// APIs, not for passing optional parameters to functions.
-//
-// The same Context may be passed to functions running in different goroutines;
-// Contexts are safe for simultaneous use by multiple goroutines.
-//
-// See https://blog.golang.org/context for example code for a server that uses
-// Contexts.
-package context
-
-import (
- "errors"
- "internal/reflectlite"
- "sync"
- "sync/atomic"
- "time"
-)
-
-// A Context carries a deadline, a cancellation signal, and other values across
-// API boundaries.
-//
-// Context's methods may be called by multiple goroutines simultaneously.
-type Context interface {
- // Deadline returns the time when work done on behalf of this context
- // should be canceled. Deadline returns ok==false when no deadline is
- // set. Successive calls to Deadline return the same results.
- Deadline() (deadline time.Time, ok bool)
-
- // Done returns a channel that's closed when work done on behalf of this
- // context should be canceled. Done may return nil if this context can
- // never be canceled. Successive calls to Done return the same value.
- // The close of the Done channel may happen asynchronously,
- // after the cancel function returns.
- //
- // WithCancel arranges for Done to be closed when cancel is called;
- // WithDeadline arranges for Done to be closed when the deadline
- // expires; WithTimeout arranges for Done to be closed when the timeout
- // elapses.
- //
- // Done is provided for use in select statements:
- //
- // // Stream generates values with DoSomething and sends them to out
- // // until DoSomething returns an error or ctx.Done is closed.
- // func Stream(ctx context.Context, out chan<- Value) error {
- // for {
- // v, err := DoSomething(ctx)
- // if err != nil {
- // return err
- // }
- // select {
- // case <-ctx.Done():
- // return ctx.Err()
- // case out <- v:
- // }
- // }
- // }
- //
- // See https://blog.golang.org/pipelines for more examples of how to use
- // a Done channel for cancellation.
- Done() <-chan struct{}
-
- // If Done is not yet closed, Err returns nil.
- // If Done is closed, Err returns a non-nil error explaining why:
- // Canceled if the context was canceled
- // or DeadlineExceeded if the context's deadline passed.
- // After Err returns a non-nil error, successive calls to Err return the same error.
- Err() error
-
- // Value returns the value associated with this context for key, or nil
- // if no value is associated with key. Successive calls to Value with
- // the same key returns the same result.
- //
- // Use context values only for request-scoped data that transits
- // processes and API boundaries, not for passing optional parameters to
- // functions.
- //
- // A key identifies a specific value in a Context. Functions that wish
- // to store values in Context typically allocate a key in a global
- // variable then use that key as the argument to context.WithValue and
- // Context.Value. A key can be any type that supports equality;
- // packages should define keys as an unexported type to avoid
- // collisions.
- //
- // Packages that define a Context key should provide type-safe accessors
- // for the values stored using that key:
- //
- // // Package user defines a User type that's stored in Contexts.
- // package user
- //
- // import "context"
- //
- // // User is the type of value stored in the Contexts.
- // type User struct {...}
- //
- // // key is an unexported type for keys defined in this package.
- // // This prevents collisions with keys defined in other packages.
- // type key int
- //
- // // userKey is the key for user.User values in Contexts. It is
- // // unexported; clients use user.NewContext and user.FromContext
- // // instead of using this key directly.
- // var userKey key
- //
- // // NewContext returns a new Context that carries value u.
- // func NewContext(ctx context.Context, u *User) context.Context {
- // return context.WithValue(ctx, userKey, u)
- // }
- //
- // // FromContext returns the User value stored in ctx, if any.
- // func FromContext(ctx context.Context) (*User, bool) {
- // u, ok := ctx.Value(userKey).(*User)
- // return u, ok
- // }
- Value(key interface{}) interface{}
-}
-
-// Canceled is the error returned by Context.Err when the context is canceled.
-var Canceled = errors.New("context canceled")
-
-// DeadlineExceeded is the error returned by Context.Err when the context's
-// deadline passes.
-var DeadlineExceeded error = deadlineExceededError{}
-
-type deadlineExceededError struct{}
-
-func (deadlineExceededError) Error() string { return "context deadline exceeded" }
-func (deadlineExceededError) Timeout() bool { return true }
-func (deadlineExceededError) Temporary() bool { return true }
-
-// An emptyCtx is never canceled, has no values, and has no deadline. It is not
-// struct{}, since vars of this type must have distinct addresses.
-type emptyCtx int
-
-func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
- return
-}
-
-func (*emptyCtx) Done() <-chan struct{} {
- return nil
-}
-
-func (*emptyCtx) Err() error {
- return nil
-}
-
-func (*emptyCtx) Value(key interface{}) interface{} {
- return nil
-}
-
-func (e *emptyCtx) String() string {
- switch e {
- case background:
- return "context.Background"
- case todo:
- return "context.TODO"
- }
- return "unknown empty Context"
-}
-
-var (
- background = new(emptyCtx)
- todo = new(emptyCtx)
-)
-
-// Background returns a non-nil, empty Context. It is never canceled, has no
-// values, and has no deadline. It is typically used by the main function,
-// initialization, and tests, and as the top-level Context for incoming
-// requests.
-func Background() Context {
- return background
-}
-
-// TODO returns a non-nil, empty Context. Code should use context.TODO when
-// it's unclear which Context to use or it is not yet available (because the
-// surrounding function has not yet been extended to accept a Context
-// parameter).
-func TODO() Context {
- return todo
-}
-
-// A CancelFunc tells an operation to abandon its work.
-// A CancelFunc does not wait for the work to stop.
-// A CancelFunc may be called by multiple goroutines simultaneously.
-// After the first call, subsequent calls to a CancelFunc do nothing.
-type CancelFunc func()
-
-// WithCancel returns a copy of parent with a new Done channel. The returned
-// context's Done channel is closed when the returned cancel function is called
-// or when the parent context's Done channel is closed, whichever happens first.
-//
-// Canceling this context releases resources associated with it, so code should
-// call cancel as soon as the operations running in this Context complete.
-func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
- c := newCancelCtx(parent)
- propagateCancel(parent, &c)
- return &c, func() { c.cancel(true, Canceled) }
-}
-
-// newCancelCtx returns an initialized cancelCtx.
-func newCancelCtx(parent Context) cancelCtx {
- return cancelCtx{Context: parent}
-}
-
-// goroutines counts the number of goroutines ever created; for testing.
-var goroutines int32
-
-// propagateCancel arranges for child to be canceled when parent is.
-func propagateCancel(parent Context, child canceler) {
- done := parent.Done()
- if done == nil {
- return // parent is never canceled
- }
-
- select {
- case <-done:
- // parent is already canceled
- child.cancel(false, parent.Err())
- return
- default:
- }
-
- if p, ok := parentCancelCtx(parent); ok {
- p.mu.Lock()
- if p.err != nil {
- // parent has already been canceled
- child.cancel(false, p.err)
- } else {
- if p.children == nil {
- p.children = make(map[canceler]struct{})
- }
- p.children[child] = struct{}{}
- }
- p.mu.Unlock()
- } else {
- atomic.AddInt32(&goroutines, +1)
- go func() {
- select {
- case <-parent.Done():
- child.cancel(false, parent.Err())
- case <-child.Done():
- }
- }()
- }
-}
-
-// &cancelCtxKey is the key that a cancelCtx returns itself for.
-var cancelCtxKey int
-
-// parentCancelCtx returns the underlying *cancelCtx for parent.
-// It does this by looking up parent.Value(&cancelCtxKey) to find
-// the innermost enclosing *cancelCtx and then checking whether
-// parent.Done() matches that *cancelCtx. (If not, the *cancelCtx
-// has been wrapped in a custom implementation providing a
-// different done channel, in which case we should not bypass it.)
-func parentCancelCtx(parent Context) (*cancelCtx, bool) {
- done := parent.Done()
- if done == closedchan || done == nil {
- return nil, false
- }
- p, ok := parent.Value(&cancelCtxKey).(*cancelCtx)
- if !ok {
- return nil, false
- }
- p.mu.Lock()
- ok = p.done == done
- p.mu.Unlock()
- if !ok {
- return nil, false
- }
- return p, true
-}
-
-// removeChild removes a context from its parent.
-func removeChild(parent Context, child canceler) {
- p, ok := parentCancelCtx(parent)
- if !ok {
- return
- }
- p.mu.Lock()
- if p.children != nil {
- delete(p.children, child)
- }
- p.mu.Unlock()
-}
-
-// A canceler is a context type that can be canceled directly. The
-// implementations are *cancelCtx and *timerCtx.
-type canceler interface {
- cancel(removeFromParent bool, err error)
- Done() <-chan struct{}
-}
-
-// closedchan is a reusable closed channel.
-var closedchan = make(chan struct{})
-
-func init() {
- close(closedchan)
-}
-
-// A cancelCtx can be canceled. When canceled, it also cancels any children
-// that implement canceler.
-type cancelCtx struct {
- Context
-
- mu sync.Mutex // protects following fields
- done chan struct{} // created lazily, closed by first cancel call
- children map[canceler]struct{} // set to nil by the first cancel call
- err error // set to non-nil by the first cancel call
-}
-
-func (c *cancelCtx) Value(key interface{}) interface{} {
- if key == &cancelCtxKey {
- return c
- }
- return c.Context.Value(key)
-}
-
-func (c *cancelCtx) Done() <-chan struct{} {
- c.mu.Lock()
- if c.done == nil {
- c.done = make(chan struct{})
- }
- d := c.done
- c.mu.Unlock()
- return d
-}
-
-func (c *cancelCtx) Err() error {
- c.mu.Lock()
- err := c.err
- c.mu.Unlock()
- return err
-}
-
-type stringer interface {
- String() string
-}
-
-func contextName(c Context) string {
- if s, ok := c.(stringer); ok {
- return s.String()
- }
- return reflectlite.TypeOf(c).String()
-}
-
-func (c *cancelCtx) String() string {
- return contextName(c.Context) + ".WithCancel"
-}
-
-// cancel closes c.done, cancels each of c's children, and, if
-// removeFromParent is true, removes c from its parent's children.
-func (c *cancelCtx) cancel(removeFromParent bool, err error) {
- if err == nil {
- panic("context: internal error: missing cancel error")
- }
- c.mu.Lock()
- if c.err != nil {
- c.mu.Unlock()
- return // already canceled
- }
- c.err = err
- if c.done == nil {
- c.done = closedchan
- } else {
- close(c.done)
- }
- for child := range c.children {
- // NOTE: acquiring the child's lock while holding parent's lock.
- child.cancel(false, err)
- }
- c.children = nil
- c.mu.Unlock()
-
- if removeFromParent {
- removeChild(c.Context, c)
- }
-}
-
-// WithDeadline returns a copy of the parent context with the deadline adjusted
-// to be no later than d. If the parent's deadline is already earlier than d,
-// WithDeadline(parent, d) is semantically equivalent to parent. The returned
-// context's Done channel is closed when the deadline expires, when the returned
-// cancel function is called, or when the parent context's Done channel is
-// closed, whichever happens first.
-//
-// Canceling this context releases resources associated with it, so code should
-// call cancel as soon as the operations running in this Context complete.
-func WithDeadline(parent Context, d time.Time) (Context, CancelFunc) {
- if cur, ok := parent.Deadline(); ok && cur.Before(d) {
- // The current deadline is already sooner than the new one.
- return WithCancel(parent)
- }
- c := &timerCtx{
- cancelCtx: newCancelCtx(parent),
- deadline: d,
- }
- propagateCancel(parent, c)
- dur := time.Until(d)
- if dur <= 0 {
- c.cancel(true, DeadlineExceeded) // deadline has already passed
- return c, func() { c.cancel(false, Canceled) }
- }
- c.mu.Lock()
- defer c.mu.Unlock()
- if c.err == nil {
- c.timer = time.AfterFunc(dur, func() {
- c.cancel(true, DeadlineExceeded)
- })
- }
- return c, func() { c.cancel(true, Canceled) }
-}
-
-// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
-// implement Done and Err. It implements cancel by stopping its timer then
-// delegating to cancelCtx.cancel.
-type timerCtx struct {
- cancelCtx
- timer *time.Timer // Under cancelCtx.mu.
-
- deadline time.Time
-}
-
-func (c *timerCtx) Deadline() (deadline time.Time, ok bool) {
- return c.deadline, true
-}
-
-func (c *timerCtx) String() string {
- return contextName(c.cancelCtx.Context) + ".WithDeadline(" +
- c.deadline.String() + " [" +
- time.Until(c.deadline).String() + "])"
-}
-
-func (c *timerCtx) cancel(removeFromParent bool, err error) {
- c.cancelCtx.cancel(false, err)
- if removeFromParent {
- // Remove this timerCtx from its parent cancelCtx's children.
- removeChild(c.cancelCtx.Context, c)
- }
- c.mu.Lock()
- if c.timer != nil {
- c.timer.Stop()
- c.timer = nil
- }
- c.mu.Unlock()
-}
-
-// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
-//
-// Canceling this context releases resources associated with it, so code should
-// call cancel as soon as the operations running in this Context complete:
-//
-// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
-// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
-// defer cancel() // releases resources if slowOperation completes before timeout elapses
-// return slowOperation(ctx)
-// }
-func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
- return WithDeadline(parent, time.Now().Add(timeout))
-}
-
-// WithValue returns a copy of parent in which the value associated with key is
-// val.
-//
-// Use context Values only for request-scoped data that transits processes and
-// APIs, not for passing optional parameters to functions.
-//
-// The provided key must be comparable and should not be of type
-// string or any other built-in type to avoid collisions between
-// packages using context. Users of WithValue should define their own
-// types for keys. To avoid allocating when assigning to an
-// interface{}, context keys often have concrete type
-// struct{}. Alternatively, exported context key variables' static
-// type should be a pointer or interface.
-func WithValue(parent Context, key, val interface{}) Context {
- if key == nil {
- panic("nil key")
- }
- if !reflectlite.TypeOf(key).Comparable() {
- panic("key is not comparable")
- }
- return &valueCtx{parent, key, val}
-}
-
-// A valueCtx carries a key-value pair. It implements Value for that key and
-// delegates all other calls to the embedded Context.
-type valueCtx struct {
- Context
- key, val interface{}
-}
-
-// stringify tries a bit to stringify v, without using fmt, since we don't
-// want context depending on the unicode tables. This is only used by
-// *valueCtx.String().
-func stringify(v interface{}) string {
- switch s := v.(type) {
- case stringer:
- return s.String()
- case string:
- return s
- }
- return "<not Stringer>"
-}
-
-func (c *valueCtx) String() string {
- return contextName(c.Context) + ".WithValue(type " +
- reflectlite.TypeOf(c.key).String() +
- ", val " + stringify(c.val) + ")"
-}
-
-func (c *valueCtx) Value(key interface{}) interface{} {
- if c.key == key {
- return c.val
- }
- return c.Context.Value(key)
-}
diff --git a/internal/stdlib/testdata/v1.14.6/src/errors/errors.go b/internal/stdlib/testdata/v1.14.6/src/errors/errors.go
deleted file mode 100644
index b8a4692..0000000
--- a/internal/stdlib/testdata/v1.14.6/src/errors/errors.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package errors implements functions to manipulate errors.
-package errors
-
-// New returns an error that formats as the given text.
-func New(text string) error {
- return &errorString{text}
-}
-
-// errorString is a trivial implementation of error.
-type errorString struct {
- s string
-}
-
-func (e *errorString) Error() string {
- return e.s
-}
diff --git a/internal/stdlib/testdata/v1.14.6/src/errors/errors_test.go b/internal/stdlib/testdata/v1.14.6/src/errors/errors_test.go
deleted file mode 100644
index cf4df90..0000000
--- a/internal/stdlib/testdata/v1.14.6/src/errors/errors_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "errors"
- "fmt"
- "testing"
-)
-
-func TestNewEqual(t *testing.T) {
- // Different allocations should not be equal.
- if errors.New("abc") == errors.New("abc") {
- t.Errorf(`New("abc") == New("abc")`)
- }
- if errors.New("abc") == errors.New("xyz") {
- t.Errorf(`New("abc") == New("xyz")`)
- }
-
- // Same allocation should be equal to itself (not crash).
- err := errors.New("jkl")
- if err != err {
- t.Errorf(`err != err`)
- }
-}
-
-func TestErrorMethod(t *testing.T) {
- err := errors.New("abc")
- if err.Error() != "abc" {
- t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
- }
-}
-
-func ExampleNew() {
- err := errors.New("emit macho dwarf: elf header corrupted")
- if err != nil {
- fmt.Print(err)
- }
- // Output: emit macho dwarf: elf header corrupted
-}
-
-// The fmt package's Errorf function lets us use the package's formatting
-// features to create descriptive error messages.
-func ExampleNew_errorf() {
- const name, id = "bimmler", 17
- err := fmt.Errorf("user %q (id %d) not found", name, id)
- if err != nil {
- fmt.Print(err)
- }
- // Output: user "bimmler" (id 17) not found
-}
diff --git a/internal/stdlib/testdata/v1.3.2/AUTHORS b/internal/stdlib/testdata/v1.3.2/AUTHORS
deleted file mode 100644
index d4fbbd1..0000000
--- a/internal/stdlib/testdata/v1.3.2/AUTHORS
+++ /dev/null
@@ -1,425 +0,0 @@
-# This is the official list of Go authors for copyright purposes.
-# This file is distinct from the CONTRIBUTORS files.
-# See the latter for an explanation.
-
-# Names should be added to this file as
-# Name or Organization <email address>
-# The email address is not required for organizations.
-
-# Please keep the list sorted.
-
-Aaron France <aaron.l.france@gmail.com>
-Abhinav Gupta <abhinav.g90@gmail.com>
-Adrian Nos <nos.adrian@gmail.com>
-Adrian O'Grady <elpollouk@gmail.com>
-Adrien Bustany <adrien-xx-google@bustany.org>
-Akshat Kumar <seed@mail.nanosouffle.net>
-Albert Strasheim <fullung@gmail.com>
-Alberto García Hierro <alberto@garciahierro.com> <alberto.garcia.hierro@gmail.com>
-Aleksandar Dezelin <dezelin@gmail.com>
-Alex A Skinner <alex@lx.lc>
-Alex Brainman <alex.brainman@gmail.com>
-Alex Jin <toalexjin@gmail.com>
-Alexander Larsson <alexander.larsson@gmail.com>
-Alexander Orlov <alexander.orlov@loxal.net>
-Alexander Reece <awreece@gmail.com>
-Alexander Surma <surma@surmair.de>
-Alexander Zhavnerchik <alex.vizor@gmail.com>
-Alexandre Normand <alexandre.normand@gmail.com>
-Alexei Sholik <alcosholik@gmail.com>
-Alexey Borzenkov <snaury@gmail.com>
-Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
-Amir Mohammad Saied <amir@gluegadget.com>
-Amrut Joshi <amrut.joshi@gmail.com>
-Andrei Vieru <euvieru@gmail.com>
-Andrew Balholm <andybalholm@gmail.com>
-Andrew Bonventre <andybons@chromium.org>
-Andrew Harding <andrew@spacemonkey.com>
-Andrew Lutomirski <andy@luto.us>
-Andrew Pritchard <awpritchard@gmail.com>
-Andrew Radev <andrey.radev@gmail.com>
-Andrew Skiba <skibaa@gmail.com>
-Andrew Szeto <andrew@jabagawee.com>
-Andrew Wilkins <axwalk@gmail.com>
-Andrey Mirtchovski <mirtchovski@gmail.com>
-Andriy Lytvynov <lytvynov.a.v@gmail.com>
-Andy Davis <andy@bigandian.com>
-Anfernee Yongkun Gui <anfernee.gui@gmail.com>
-Anh Hai Trinh <anh.hai.trinh@gmail.com>
-Anschel Schaffer-Cohen <anschelsc@gmail.com>
-Anthony Eufemio <anthony.eufemio@gmail.com>
-Anthony Martin <ality@pbrane.org>
-Anthony Starks <ajstarks@gmail.com>
-Apisak Darakananda <pongad@gmail.com>
-Aram Hăvărneanu <aram@mgk.ro>
-Arnaud Ysmal <arnaud.ysmal@gmail.com>
-Arne Hormann <arnehormann@gmail.com>
-Aron Nopanen <aron.nopanen@gmail.com>
-Arvindh Rajesh Tamilmani <art@a-30.net>
-Ato Araki <ato.araki@gmail.com>
-Aulus Egnatius Varialus <varialus@gmail.com>
-Ben Olive <sionide21@gmail.com>
-Benjamin Black <b@b3k.us>
-Benny Siegert <bsiegert@gmail.com>
-Berengar Lehr <berengar.lehr@gmx.de>
-Billie Harold Cleek <bhcleek@gmail.com>
-Bjorn Tillenius <bjorn@tillenius.me>
-Bjorn Tipling <bjorn.tipling@gmail.com>
-Blake Mizerany <blake.mizerany@gmail.com>
-Bobby Powers <bobbypowers@gmail.com>
-Brendan Daniel Tracey <tracey.brendan@gmail.com>
-Brian Dellisanti <briandellisanti@gmail.com>
-Brian G. Merrell <bgmerrell@gmail.com>
-Brian Gitonga Marete <marete@toshnix.com>
-Brian Ketelsen <bketelsen@gmail.com>
-Caine Tighe <arctanofyourface@gmail.com>
-Caleb Spare <cespare@gmail.com>
-Carl Chatfield <carlchatfield@gmail.com>
-Carlos Castillo <cookieo9@gmail.com>
-Case Nelson <case.nelson@gmail.com>
-Casey Marshall <casey.marshall@gmail.com>
-Cezar Sá Espinola <cezarsa@gmail.com>
-ChaiShushan <chaishushan@gmail.com>
-Charles L. Dorian <cldorian@gmail.com>
-Charles Lee <zombie.fml@gmail.com>
-Chris Dollin <ehog.hedge@gmail.com>
-Chris Farmiloe <chrisfarms@gmail.com>
-Chris Howey <howeyc@gmail.com>
-Chris Jones <chris@cjones.org>
-Chris Lennert <calennert@gmail.com>
-Christian Himpel <chressie@googlemail.com>
-Christine Hansmann <chhansmann@gmail.com>
-Christoffer Buchholz <christoffer.buchholz@gmail.com>
-Christoph Hack <christoph@tux21b.org>
-Christopher Cahoon <chris.cahoon@gmail.com>
-Christopher Nielsen <m4dh4tt3r@gmail.com>
-Christopher Redden <christopher.redden@gmail.com>
-Christopher Wedgwood <cw@f00f.org>
-Clement Skau <clementskau@gmail.com>
-Conrad Meyer <cemeyer@cs.washington.edu>
-Corey Thomasson <cthom.lists@gmail.com>
-Damian Gryski <dgryski@gmail.com>
-Dan Callahan <dan.callahan@gmail.com>
-Dan Peterson <dpiddy@gmail.com>
-Dan Sinclair <dan.sinclair@gmail.com>
-Daniel Fleischman <danielfleischman@gmail.com>
-Daniel Krech <eikeon@eikeon.com>
-Daniel Lidén <daniel.liden.87@gmail.com>
-Daniel Morsing <daniel.morsing@gmail.com>
-Daniel Theophanes <kardianos@gmail.com>
-Darren Elwood <darren@textnode.com>
-Dave Cheney <dave@cheney.net>
-David Bürgin <676c7473@gmail.com>
-David Calavera <david.calavera@gmail.com>
-David du Colombier <0intro@gmail.com>
-David Forsythe <dforsythe@gmail.com>
-David G. Andersen <dave.andersen@gmail.com>
-David Jakob Fritz <david.jakob.fritz@gmail.com>
-David Thomas <davidthomas426@gmail.com>
-David Titarenco <david.titarenco@gmail.com>
-Dean Prichard <dean.prichard@gmail.com>
-Denis Brandolini <denis.brandolini@gmail.com>
-Devon H. O'Dell <devon.odell@gmail.com>
-Dhiru Kholia <dhiru.kholia@gmail.com>
-Dimitri Tcaciuc <dtcaciuc@gmail.com>
-Dmitri Shuralyov <shurcooL@gmail.com>
-Dmitriy Shelenin <deemok@googlemail.com> <deemok@gmail.com>
-Dmitry Chestnykh <dchest@gmail.com>
-Dominik Honnef <dominik.honnef@gmail.com>
-Donovan Hide <donovanhide@gmail.com>
-Dropbox, Inc.
-Duncan Holm <mail@frou.org>
-Dustin Sallings <dsallings@gmail.com>
-Dustin Shields-Cloues <dcloues@gmail.com>
-Eden Li <eden.li@gmail.com>
-Egon Elbre <egonelbre@gmail.com>
-Ehren Kret <ehren.kret@gmail.com>
-Eivind Uggedal <eivind@uggedal.com>
-Elias Naur <elias.naur@gmail.com>
-Emil Hessman <c.emil.hessman@gmail.com>
-Eoghan Sherry <ejsherry@gmail.com>
-Eric Clark <zerohp@gmail.com>
-Eric Milliken <emilliken@gmail.com>
-Eric Roshan-Eisner <eric.d.eisner@gmail.com>
-Erik St. Martin <alakriti@gmail.com>
-Erik Westrup <erik.westrup@gmail.com>
-Esko Luontola <esko.luontola@gmail.com>
-Evan Shaw <chickencha@gmail.com>
-Ewan Chou <coocood@gmail.com>
-Fabrizio Milo <mistobaan@gmail.com>
-Fan Hongjian <fan.howard@gmail.com>
-Fazlul Shahriar <fshahriar@gmail.com>
-Felix Geisendörfer <haimuiba@gmail.com>
-Firmansyah Adiputra <frm.adiputra@gmail.com>
-Florian Uekermann <florian@uekermann-online.de>
-Florian Weimer <fw@deneb.enyo.de>
-Francisco Souza <franciscossouza@gmail.com>
-Frederick Kelly Mayle III <frederickmayle@gmail.com>
-Fredrik Enestad <fredrik.enestad@soundtrackyourbrand.com>
-Frithjof Schulze <schulze@math.uni-hannover.de> <sfrithjof@gmail.com>
-Gary Burd <gary@beagledreams.com>
-Gautham Thambidorai <gautham.dorai@gmail.com>
-Georg Reinke <guelfey@gmail.com>
-Gerasimos Dimitriadis <gedimitr@gmail.com>
-Gideon Jan-Wessel Redelinghuys <gjredelinghuys@gmail.com>
-Giles Lean <giles.lean@pobox.com>
-Google Inc.
-Gordon Klaus <gordon.klaus@gmail.com>
-Graham King <graham4king@gmail.com>
-Graham Miller <graham.miller@gmail.com>
-Greg Ward <greg@gerg.ca>
-Guillaume J. Charmes <guillaume@charmes.net>
-Gustav Paul <gustav.paul@gmail.com>
-Gustavo Niemeyer <gustavo@niemeyer.net>
-Gwenael Treguier <gwenn.kahz@gmail.com>
-Harley Laue <losinggeneration@gmail.com>
-Hector Chu <hectorchu@gmail.com>
-Henrik Edwards <henrik.edwards@gmail.com>
-Herbert Georg Fischer <herbert.fischer@gmail.com>
-Hong Ruiqi <hongruiqi@gmail.com>
-Icarus Sparry <golang@icarus.freeuk.com>
-Ingo Oeser <nightlyone@googlemail.com>
-Isaac Wagner <ibw@isaacwagner.me>
-Jakob Borg <jakob@nym.se>
-Jakub Ryszard Czarnowicz <j.czarnowicz@gmail.com>
-James David Chalfant <james.chalfant@gmail.com>
-James Fysh <james.fysh@gmail.com>
-James Gray <james@james4k.com>
-James Meneghello <rawrz0r@gmail.com>
-James P. Cooper <jamespcooper@gmail.com>
-James Toy <nil@opensesame.st>
-James Whitehead <jnwhiteh@gmail.com>
-Jan H. Hosang <jan.hosang@gmail.com>
-Jan Mercl <0xjnml@gmail.com>
-Jan Mercl <befelemepeseveze@gmail.com>
-Jan Newmarch <jan.newmarch@gmail.com>
-Jan Ziak <0xe2.0x9a.0x9b@gmail.com>
-Jani Monoses <jani.monoses@ubuntu.com>
-Jaroslavas Počepko <jp@webmaster.ms>
-Jason Del Ponte <delpontej@gmail.com>
-Jason Travis <infomaniac7@gmail.com>
-Jay Weisskopf <jay@jayschwa.net>
-Jeff Hodges <jeff@somethingsimilar.com>
-Jeff R. Allen <jra@nella.org>
-Jeff Sickel <jas@corpus-callosum.com>
-Jeff Wendling <jeff@spacemonkey.com>
-Jeremy Jackins <jeremyjackins@gmail.com>
-Jim McGrath <jimmc2@gmail.com>
-Jimmy Zelinskie <jimmyzelinskie@gmail.com>
-Jingcheng Zhang <diogin@gmail.com>
-Joakim Sernbrant <serbaut@gmail.com>
-Joe Poirier <jdpoirier@gmail.com>
-John Asmuth <jasmuth@gmail.com>
-John C Barstow <jbowtie@amathaine.com>
-John Graham-Cumming <jgc@jgc.org> <jgrahamc@gmail.com>
-John Howard Palevich <jack.palevich@gmail.com>
-John Shahid <jvshahid@gmail.com>
-Jonathan Gold <jgold.bg@gmail.com>
-Jonathan Mark <jhmark@xenops.com>
-Jonathan Rudenberg <jonathan@titanous.com>
-Jonathan Wills <runningwild@gmail.com>
-Jongmin Kim <atomaths@gmail.com>
-Jose Luis Vázquez González <josvazg@gmail.com>
-Joseph Holsten <joseph@josephholsten.com>
-Josh Bleecher Snyder <josharian@gmail.com>
-Josh Goebel <dreamer3@gmail.com>
-Josh Holland <jrh@joshh.co.uk>
-Joshua Chase <jcjoshuachase@gmail.com>
-Jukka-Pekka Kekkonen <karatepekka@gmail.com>
-Julian Phillips <julian@quantumfyre.co.uk>
-Julien Schmidt <google@julienschmidt.com>
-Kai Backman <kaib@golang.org>
-Kamil Kisiel <kamil@kamilkisiel.net> <kamil.kisiel@gmail.com>
-Katrina Owen <katrina.owen@gmail.com>
-Kei Son <hey.calmdown@gmail.com>
-Keith Rarick <kr@xph.us>
-Kelsey Hightower <kelsey.hightower@gmail.com>
-Kelvin Foo Chuan Lyi <vmirage@gmail.com>
-Ken Friedenbach <kenliz@cruzio.com>
-Ken Rockot <ken@oz.gs>
-Kevin Ballard <kevin@sb.org>
-Kyle Consalus <consalus@gmail.com>
-Kyle Isom <kyle@gokyle.net>
-Kyle Lemons <kyle@kylelemons.net>
-L Campbell <unpantsu@gmail.com>
-Lai Jiangshan <eag0628@gmail.com>
-Linaro Limited
-Lorenzo Stoakes <lstoakes@gmail.com>
-Luca Greco <luca.greco@alcacoop.it>
-Lucio De Re <lucio.dere@gmail.com>
-Luit van Drongelen <luitvd@gmail.com>
-Luka Zakrajšek <tr00.g33k@gmail.com>
-Luke Curley <qpingu@gmail.com>
-Marc Weistroff <marc@weistroff.net>
-Marco Hennings <marco.hennings@freiheit.com>
-Marko Juhani Silokunnas <marko.silokunnas@gmail.com>
-Marko Tiikkaja <marko@joh.to>
-Markus Duft <markus.duft@salomon.at>
-Markus Sonderegger <marraison@gmail.com>
-Markus Zimmermann <zimmski@gmail.com>
-Martin Neubauer <m.ne@gmx.net>
-Martin Olsson <martin@minimum.se>
-Mateusz Czapliński <czapkofan@gmail.com>
-Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
-Mats Lidell <mats.lidell@cag.se>
-Matt Aimonetti <mattaimonetti@gmail.com>
-Matt Jibson <matt.jibson@gmail.com>
-Matt Joiner <anacrolix@gmail.com>
-Matt Reiferson <mreiferson@gmail.com>
-Matthew Cottingham <mattcottingham@gmail.com>
-Matthew Horsnell <matthew.horsnell@gmail.com>
-Maxim Khitrov <max@mxcrypt.com>
-Micah Stetson <micah.stetson@gmail.com>
-Michael Chaten <mchaten@gmail.com>
-Michael Elkins <michael.elkins@gmail.com>
-Michael Fraenkel <michael.fraenkel@gmail.com>
-Michael Gehring <mg@ebfe.org> <gnirheg.leahcim@gmail.com>
-Michael Hoisie <hoisie@gmail.com>
-Michael Lewis <mikelikespie@gmail.com>
-Michael Pearson <mipearson@gmail.com>
-Michael Stapelberg <michael@stapelberg.de>
-Michael Teichgräber <mteichgraeber@gmx.de>
-Michał Derkacz <ziutek@lnet.pl>
-Miek Gieben <miek@miek.nl>
-Mihai Borobocea <MihaiBorobocea@gmail.com>
-Mikael Tillenius <mikti42@gmail.com>
-Mike Andrews <mra@xoba.com>
-Mike Rosset <mike.rosset@gmail.com>
-Mikhail Panchenko <m@mihasya.com>
-Miki Tebeka <miki.tebeka@gmail.com>
-Mikio Hara <mikioh.mikioh@gmail.com>
-Mikkel Krautz <mikkel@krautz.dk>
-Miquel Sabaté Solà <mikisabate@gmail.com>
-Moov Corporation
-Moriyoshi Koizumi <mozo@mozo.jp>
-Môshe van der Sterre <moshevds@gmail.com>
-Nan Deng <monnand@gmail.com>
-Nathan John Youngman <nj@nathany.com>
-ngmoco, LLC
-Nicholas Katsaros <nick@nickkatsaros.com>
-Nicholas Presta <nick@nickpresta.ca> <nick1presta@gmail.com>
-Nicholas Sullivan <nicholas.sullivan@gmail.com>
-Nicholas Waples <nwaples@gmail.com>
-Nick Craig-Wood <nick@craig-wood.com> <nickcw@gmail.com>
-Nicolas Kaiser <nikai@nikai.net>
-Nicolas Owens <mischief@offblast.org>
-Nigel Kerr <nigel.kerr@gmail.com>
-Noah Campbell <noahcampbell@gmail.com>
-Oling Cat <olingcat@gmail.com>
-Oliver Hookins <ohookins@gmail.com>
-Olivier Antoine <olivier.antoine@gmail.com>
-Olivier Duperray <duperray.olivier@gmail.com>
-Olivier Saingre <osaingre@gmail.com>
-Padraig Kitterick <padraigkitterick@gmail.com>
-Paolo Giarrusso <p.giarrusso@gmail.com>
-Pascal S. de Kloe <pascal@quies.net>
-Patrick Crosby <patrick@stathat.com>
-Patrick Gavlin <pgavlin@gmail.com>
-Patrick Higgins <patrick.allen.higgins@gmail.com>
-Patrick Mézard <patrick@mezard.eu>
-Patrick Mylund Nielsen <patrick@patrickmn.com>
-Patrick Smith <pat42smith@gmail.com>
-Paul A Querna <paul.querna@gmail.com>
-Paul Hammond <paul@paulhammond.org>
-Paul Lalonde <paul.a.lalonde@gmail.com>
-Paul Sbarra <Sbarra.Paul@gmail.com>
-Paul van Brouwershaven <paul@vanbrouwershaven.com>
-Pavel Zinovkin <pavel.zinovkin@gmail.com>
-Petar Maymounkov <petarm@gmail.com>
-Peter Armitage <peter.armitage@gmail.com>
-Peter Froehlich <peter.hans.froehlich@gmail.com>
-Peter Kleiweg <pkleiweg@xs4all.nl>
-Peter Mundy <go.peter.90@gmail.com>
-Péter Surányi <speter.go1@gmail.com>
-Péter Szilágyi <peterke@gmail.com>
-Peter Waller <peter.waller@gmail.com>
-Peter Williams <pwil3058@gmail.com>
-Philip K. Warren <pkwarren@gmail.com>
-Pieter Droogendijk <pieter@binky.org.uk>
-Pietro Gagliardi <pietro10@mac.com>
-Preetam Jinka <pj@preet.am>
-Quan Yong Zhai <qyzhai@gmail.com>
-Raif S. Naffah <go@naffah-raif.name>
-Rémy Oudompheng <oudomphe@phare.normalesup.org>
-Richard Crowley <r@rcrowley.org>
-Richard Eric Gavaletz <gavaletz@gmail.com>
-Richard Musiol <mail@richard-musiol.de>
-Rick Arnold <rickarnoldjr@gmail.com>
-Risto Jaakko Saarelma <rsaarelm@gmail.com>
-Robert Daniel Kortschak <dan.kortschak@adelaide.edu.au>
-Robert Dinu <r@varp.se>
-Robert Figueiredo <robfig@gmail.com>
-Robert Hencke <robert.hencke@gmail.com>
-Robert Obryk <robryk@gmail.com>
-Robin Eklind <r.eklind.87@gmail.com>
-Rodrigo Moraes de Oliveira <rodrigo.moraes@gmail.com>
-Rodrigo Rafael Monti Kochenburger <divoxx@gmail.com>
-Roger Pau Monné <royger@gmail.com>
-Roger Peppe <rogpeppe@gmail.com>
-Ron Minnich <rminnich@gmail.com>
-Ross Light <rlight2@gmail.com>
-Rowan Worth <sqweek@gmail.com>
-Ryan Hitchman <hitchmanr@gmail.com>
-Ryan Slade <ryanslade@gmail.com>
-S.Çağlar Onur <caglar@10ur.org>
-Sanjay Menakuru <balasanjay@gmail.com>
-Scott Ferguson <scottwferg@gmail.com>
-Scott Lawrence <bytbox@gmail.com>
-Sebastien Binet <seb.binet@gmail.com>
-Sébastien Paolacci <sebastien.paolacci@gmail.com>
-Sergei Skorobogatov <skorobo@rambler.ru>
-Sergey 'SnakE' Gromov <snake.scaly@gmail.com>
-Sergio Luis O. B. Correia <sergio@correia.cc>
-Shane Hansen <shanemhansen@gmail.com>
-Shawn Smith <shawn.p.smith@gmail.com>
-Shenghou Ma <minux.ma@gmail.com>
-Shivakumar GN <shivakumar.gn@gmail.com>
-Sokolov Yura <funny.falcon@gmail.com>
-Spring Mc <heresy.mc@gmail.com>
-StalkR <stalkr@stalkr.net>
-Stefan Nilsson <snilsson@nada.kth.se> <trolleriprofessorn@gmail.com>
-Stéphane Travostino <stephane.travostino@gmail.com>
-Stephen McQuay <stephen@mcquay.me>
-Stephen Weinberg <stephen@q5comm.com>
-Steve McCoy <mccoyst@gmail.com>
-Steven Elliot Harris <seharris@gmail.com>
-Steven Hartland <steven.hartland@multiplay.co.uk>
-Sven Almgren <sven@tras.se>
-Szabolcs Nagy <nsz@port70.net>
-Tad Glines <tad.glines@gmail.com>
-Taj Khattra <taj.khattra@gmail.com>
-Tarmigan Casebolt <tarmigan@gmail.com>
-Taru Karttunen <taruti@taruti.net>
-Thomas Alan Copeland <talan.copeland@gmail.com>
-Thomas Kappler <tkappler@gmail.com>
-Timo Savola <timo.savola@gmail.com>
-Tobias Columbus <tobias.columbus@gmail.com>
-Tor Andersson <tor.andersson@gmail.com>
-Travis Cline <travis.cline@gmail.com>
-Tudor Golubenco <tudor.g@gmail.com>
-Tw <tw19881113@gmail.com>
-Tyler Bunnell <tylerbunnell@gmail.com>
-Ugorji Nwoke <ugorji@gmail.com>
-Ulf Holm Nielsen <doktor@dyregod.dk>
-Uriel Mangado <uriel@berlinblue.org>
-Vadim Vygonets <unixdj@gmail.com>
-Vincent Ambo <tazjin@googlemail.com>
-Vincent Vanackere <vincent.vanackere@gmail.com>
-Vinu Rajashekhar <vinutheraj@gmail.com>
-Vladimir Nikishenko <vova616@gmail.com>
-Volker Dobler <dr.volker.dobler@gmail.com>
-Wei Guangjing <vcc.163@gmail.com>
-Willem van der Schyff <willemvds@gmail.com>
-William Josephson <wjosephson@gmail.com>
-William Orr <will@worrbase.com> <ay1244@gmail.com>
-Xing Xing <mikespook@gmail.com>
-Yasuhiro Matsumoto <mattn.jp@gmail.com>
-Yissakhar Z. Beck <yissakhar.beck@gmail.com>
-Yongjian Xu <i3dmaster@gmail.com>
-Yoshiyuki Kanno <nekotaroh@gmail.com> <yoshiyuki.kanno@stoic.co.jp>
-Yusuke Kagiwada <block.rxckin.beats@gmail.com>
-Yuusei Kuwana <kuwana@kumama.org>
-Yuval Pavel Zholkover <paulzhol@gmail.com>
-Ziad Hatahet <hatahet@gmail.com>
-Zorion Arrizabalaga <zorionk@gmail.com>
-申习之 <bronze1man@gmail.com>
diff --git a/internal/stdlib/testdata/v1.3.2/CONTRIBUTORS b/internal/stdlib/testdata/v1.3.2/CONTRIBUTORS
deleted file mode 100644
index 3722298..0000000
--- a/internal/stdlib/testdata/v1.3.2/CONTRIBUTORS
+++ /dev/null
@@ -1,581 +0,0 @@
-# This is the official list of people who can contribute
-# (and typically have contributed) code to the Go repository.
-# The AUTHORS file lists the copyright holders; this file
-# lists people. For example, Google employees are listed here
-# but not in AUTHORS, because Google holds the copyright.
-#
-# The submission process automatically checks to make sure
-# that people submitting code are listed in this file (by email address).
-#
-# Names should be added to this file only after verifying that
-# the individual or the individual's organization has agreed to
-# the appropriate Contributor License Agreement, found here:
-#
-# http://code.google.com/legal/individual-cla-v1.0.html
-# http://code.google.com/legal/corporate-cla-v1.0.html
-#
-# The agreement for individuals can be filled out on the web.
-#
-# When adding J Random Contributor's name to this file,
-# either J's name or J's organization's name should be
-# added to the AUTHORS file, depending on whether the
-# individual or corporate CLA was used.
-
-# Names should be added to this file like so:
-# Name <email address>
-#
-# An entry with two email addresses specifies that the
-# first address should be used in the submit logs and
-# that the second address should be recognized as the
-# same person when interacting with Rietveld.
-
-# Please keep the list sorted.
-
-Aaron France <aaron.l.france@gmail.com>
-Aaron Kemp <kemp.aaron@gmail.com>
-Abhinav Gupta <abhinav.g90@gmail.com>
-Adam Langley <agl@golang.org>
-Adrian Nos <nos.adrian@gmail.com>
-Adrian O'Grady <elpollouk@gmail.com>
-Adrien Bustany <adrien-xx-google@bustany.org>
-Akshat Kumar <seed@mail.nanosouffle.net>
-Alan Donovan <adonovan@google.com>
-Albert Strasheim <fullung@gmail.com>
-Alberto García Hierro <alberto@garciahierro.com> <alberto.garcia.hierro@gmail.com>
-Aleksandar Dezelin <dezelin@gmail.com>
-Alex A Skinner <alex@lx.lc>
-Alex Brainman <alex.brainman@gmail.com>
-Alex Bramley <abramley@google.com>
-Alex Jin <toalexjin@gmail.com>
-Alexander Larsson <alexander.larsson@gmail.com>
-Alexander Orlov <alexander.orlov@loxal.net>
-Alexander Reece <awreece@gmail.com>
-Alexander Surma <surma@surmair.de>
-Alexander Zhavnerchik <alex.vizor@gmail.com>
-Alexandre Normand <alexandre.normand@gmail.com>
-Alexandru Moșoi <brtzsnr@gmail.com>
-Alexei Sholik <alcosholik@gmail.com>
-Alexey Borzenkov <snaury@gmail.com>
-Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
-Alexis Imperial-Legrand <ail@google.com>
-Amir Mohammad Saied <amir@gluegadget.com>
-Amrut Joshi <amrut.joshi@gmail.com>
-Andrea Spadaccini <spadaccio@google.com>
-Andreas Jellinghaus <andreas@ionisiert.de> <anj@google.com>
-Andrei Vieru <euvieru@gmail.com>
-Andrew Balholm <andybalholm@gmail.com>
-Andrew Bonventre <andybons@chromium.org>
-Andrew Gerrand <adg@golang.org>
-Andrew Harding <andrew@spacemonkey.com>
-Andrew Lutomirski <andy@luto.us>
-Andrew Pritchard <awpritchard@gmail.com>
-Andrew Radev <andrey.radev@gmail.com>
-Andrew Skiba <skibaa@gmail.com>
-Andrew Szeto <andrew@jabagawee.com>
-Andrew Wilkins <axwalk@gmail.com>
-Andrey Mirtchovski <mirtchovski@gmail.com>
-Andriy Lytvynov <lytvynov.a.v@gmail.com>
-Andy Davis <andy@bigandian.com>
-Anfernee Yongkun Gui <anfernee.gui@gmail.com>
-Anh Hai Trinh <anh.hai.trinh@gmail.com>
-Anschel Schaffer-Cohen <anschelsc@gmail.com>
-Anthony Eufemio <anthony.eufemio@gmail.com>
-Anthony Martin <ality@pbrane.org>
-Anthony Starks <ajstarks@gmail.com>
-Apisak Darakananda <pongad@gmail.com>
-Aram Hăvărneanu <aram@mgk.ro>
-Arnaud Ysmal <arnaud.ysmal@gmail.com>
-Arne Hormann <arnehormann@gmail.com>
-Aron Nopanen <aron.nopanen@gmail.com>
-Arvindh Rajesh Tamilmani <art@a-30.net>
-Asim Shankar <asimshankar@gmail.com>
-Ato Araki <ato.araki@gmail.com>
-Aulus Egnatius Varialus <varialus@gmail.com>
-Austin Clements <aclements@csail.mit.edu>
-Balazs Lecz <leczb@google.com>
-Ben Eitzen <eitzenb@golang.org>
-Ben Fried <ben.fried@gmail.com>
-Ben Lynn <benlynn@gmail.com>
-Ben Olive <sionide21@gmail.com>
-Benjamin Black <b@b3k.us>
-Benny Siegert <bsiegert@gmail.com>
-Berengar Lehr <Berengar.Lehr@gmx.de>
-Bill Neubauer <wcn@golang.org> <wcn@google.com> <bill.neubauer@gmail.com>
-Bill Thiede <couchmoney@gmail.com>
-Billie Harold Cleek <bhcleek@gmail.com>
-Bjorn Tillenius <bjorn@tillenius.me>
-Bjorn Tipling <bjorn.tipling@gmail.com>
-Blake Mizerany <blake.mizerany@gmail.com>
-Bobby Powers <bobbypowers@gmail.com>
-Brad Fitzpatrick <bradfitz@golang.org> <bradfitz@gmail.com>
-Brad Garcia <bgarcia@golang.org>
-Brendan Daniel Tracey <tracey.brendan@gmail.com>
-Brendan O'Dea <bod@golang.org>
-Brian Dellisanti <briandellisanti@gmail.com>
-Brian G. Merrell <bgmerrell@gmail.com>
-Brian Gitonga Marete <marete@toshnix.com>
-Brian Ketelsen <bketelsen@gmail.com>
-Brian Slesinsky <skybrian@google.com>
-Burcu Dogan <jbd@google.com>
-Caine Tighe <arctanofyourface@gmail.com>
-Caleb Spare <cespare@gmail.com>
-Carl Chatfield <carlchatfield@gmail.com>
-Carl Mastrangelo <notcarl@google.com>
-Carl Shapiro <cshapiro@google.com> <cshapiro@golang.org>
-Carlos Castillo <cookieo9@gmail.com>
-Cary Hull <chull@google.com>
-Case Nelson <case.nelson@gmail.com>
-Casey Marshall <casey.marshall@gmail.com>
-Catalin Patulea <catalinp@google.com>
-Cezar Sá Espinola <cezarsa@gmail.com>
-ChaiShushan <chaishushan@gmail.com>
-Charles L. Dorian <cldorian@gmail.com>
-Charles Lee <zombie.fml@gmail.com>
-Chris Dollin <ehog.hedge@gmail.com>
-Chris Farmiloe <chrisfarms@gmail.com>
-Chris Howey <howeyc@gmail.com>
-Chris Hundt <hundt@google.com>
-Chris Jones <chris@cjones.org> <chris.jones.yar@gmail.com>
-Chris Lennert <calennert@gmail.com>
-Chris Manghane <cmang@golang.org>
-Christian Himpel <chressie@googlemail.com> <chressie@gmail.com>
-Christine Hansmann <chhansmann@gmail.com>
-Christoffer Buchholz <christoffer.buchholz@gmail.com>
-Christoph Hack <christoph@tux21b.org>
-Christopher Cahoon <chris.cahoon@gmail.com>
-Christopher Nielsen <m4dh4tt3r@gmail.com>
-Christopher Redden <christopher.redden@gmail.com>
-Christopher Swenson <cswenson@google.com>
-Christopher Wedgwood <cw@f00f.org>
-Clement Skau <clementskau@gmail.com>
-Colby Ranger <cranger@google.com>
-Conrad Meyer <cemeyer@cs.washington.edu>
-Corey Thomasson <cthom.lists@gmail.com>
-Cosmos Nicolaou <cnicolaou@google.com>
-Damian Gryski <dgryski@gmail.com>
-Dan Callahan <dan.callahan@gmail.com>
-Dan Peterson <dpiddy@gmail.com>
-Dan Sinclair <dan.sinclair@gmail.com>
-Daniel Fleischman <danielfleischman@gmail.com>
-Daniel Krech <eikeon@eikeon.com>
-Daniel Lidén <daniel.liden.87@gmail.com>
-Daniel Morsing <daniel.morsing@gmail.com>
-Daniel Nadasi <dnadasi@google.com>
-Daniel Theophanes <kardianos@gmail.com>
-Darren Elwood <darren@textnode.com>
-Dave Borowitz <dborowitz@google.com>
-Dave Cheney <dave@cheney.net>
-Dave Day <djd@golang.org>
-Dave Grijalva <dgrijalva@ngmoco.com>
-David Anderson <danderson@google.com>
-David Barnett <dbarnett@google.com>
-David Bürgin <676c7473@gmail.com>
-David Calavera <david.calavera@gmail.com>
-David Covert <davidhcovert@gmail.com>
-David Crawshaw <david.crawshaw@zentus.com> <crawshaw@google.com> <crawshaw@golang.org>
-David du Colombier <0intro@gmail.com>
-David Forsythe <dforsythe@gmail.com>
-David G. Andersen <dave.andersen@gmail.com>
-David Jakob Fritz <david.jakob.fritz@gmail.com>
-David McLeish <davemc@google.com>
-David Presotto <presotto@gmail.com>
-David Symonds <dsymonds@golang.org>
-David Thomas <davidthomas426@gmail.com>
-David Titarenco <david.titarenco@gmail.com>
-Dean Prichard <dean.prichard@gmail.com>
-Denis Brandolini <denis.brandolini@gmail.com>
-Devon H. O'Dell <devon.odell@gmail.com>
-Dhiru Kholia <dhiru.kholia@gmail.com>
-Dimitri Tcaciuc <dtcaciuc@gmail.com>
-Dmitri Shuralyov <shurcooL@gmail.com>
-Dmitriy Shelenin <deemok@googlemail.com> <deemok@gmail.com>
-Dmitriy Vyukov <dvyukov@google.com>
-Dmitry Chestnykh <dchest@gmail.com>
-Dominik Honnef <dominik.honnef@gmail.com>
-Donovan Hide <donovanhide@gmail.com>
-Drew Hintz <adhintz@google.com>
-Duncan Holm <mail@frou.org>
-Dustin Sallings <dsallings@gmail.com>
-Dustin Shields-Cloues <dcloues@gmail.com>
-Eden Li <eden.li@gmail.com>
-Egon Elbre <egonelbre@gmail.com>
-Ehren Kret <ehren.kret@gmail.com>
-Eivind Uggedal <eivind@uggedal.com>
-Elias Naur <elias.naur@gmail.com>
-Emil Hessman <c.emil.hessman@gmail.com>
-Eoghan Sherry <ejsherry@gmail.com>
-Eric Clark <zerohp@gmail.com>
-Eric Milliken <emilliken@gmail.com>
-Eric Roshan-Eisner <eric.d.eisner@gmail.com>
-Erik St. Martin <alakriti@gmail.com>
-Erik Westrup <erik.westrup@gmail.com>
-Esko Luontola <esko.luontola@gmail.com>
-Evan Martin <evan.martin@gmail.com>
-Evan Shaw <chickencha@gmail.com>
-Ewan Chou <coocood@gmail.com>
-Fabrizio Milo <mistobaan@gmail.com>
-Fan Hongjian <fan.howard@gmail.com>
-Fazlul Shahriar <fshahriar@gmail.com>
-Felix Geisendörfer <haimuiba@gmail.com>
-Firmansyah Adiputra <frm.adiputra@gmail.com>
-Florian Uekermann <florian@uekermann-online.de> <f1@uekermann-online.de>
-Florian Weimer <fw@deneb.enyo.de>
-Folke Behrens <folke@google.com>
-Francesc Campoy <campoy@golang.org>
-Francisco Souza <franciscossouza@gmail.com>
-Frederick Kelly Mayle III <frederickmayle@gmail.com>
-Fredrik Enestad <fredrik.enestad@soundtrackyourbrand.com>
-Frithjof Schulze <schulze@math.uni-hannover.de> <sfrithjof@gmail.com>
-Fumitoshi Ukai <ukai@google.com>
-Gaal Yahas <gaal@google.com>
-Gary Burd <gary@beagledreams.com> <gary.burd@gmail.com>
-Gautham Thambidorai <gautham.dorai@gmail.com>
-Georg Reinke <guelfey@gmail.com>
-Gerasimos Dimitriadis <gedimitr@gmail.com>
-Gideon Jan-Wessel Redelinghuys <gjredelinghuys@gmail.com>
-Giles Lean <giles.lean@pobox.com>
-Gordon Klaus <gordon.klaus@gmail.com>
-Graham King <graham4king@gmail.com>
-Graham Miller <graham.miller@gmail.com>
-Greg Ward <greg@gerg.ca>
-Guillaume J. Charmes <guillaume@charmes.net>
-Gustav Paul <gustav.paul@gmail.com>
-Gustavo Franco <gustavorfranco@gmail.com>
-Gustavo Niemeyer <gustavo@niemeyer.net> <n13m3y3r@gmail.com>
-Gwenael Treguier <gwenn.kahz@gmail.com>
-Han-Wen Nienhuys <hanwen@google.com>
-Harley Laue <losinggeneration@gmail.com>
-Hector Chu <hectorchu@gmail.com>
-Henrik Edwards <henrik.edwards@gmail.com>
-Herbert Georg Fischer <herbert.fischer@gmail.com>
-Hong Ruiqi <hongruiqi@gmail.com>
-Hossein Sheikh Attar <hattar@google.com>
-Ian Lance Taylor <iant@golang.org>
-Icarus Sparry <golang@icarus.freeuk.com>
-Ingo Oeser <nightlyone@googlemail.com> <nightlyone@gmail.com>
-Isaac Wagner <ibw@isaacwagner.me>
-Ivan Krasin <krasin@golang.org>
-Jacob Baskin <jbaskin@google.com>
-Jakob Borg <jakob@nym.se>
-Jakub Ryszard Czarnowicz <j.czarnowicz@gmail.com>
-James Aguilar <jaguilar@google.com>
-James David Chalfant <james.chalfant@gmail.com>
-James Fysh <james.fysh@gmail.com>
-James Gray <james@james4k.com>
-James Meneghello <rawrz0r@gmail.com>
-James P. Cooper <jamespcooper@gmail.com>
-James Toy <nil@opensesame.st>
-James Tucker <raggi@google.com>
-James Whitehead <jnwhiteh@gmail.com>
-Jamie Gennis <jgennis@google.com> <jgennis@gmail.com>
-Jamie Turner <jamwt@dropbox.com>
-Jamie Wilkinson <jaq@spacepants.org>
-Jan H. Hosang <jan.hosang@gmail.com>
-Jan Mercl <0xjnml@gmail.com>
-Jan Mercl <befelemepeseveze@gmail.com>
-Jan Newmarch <jan.newmarch@gmail.com>
-Jan Ziak <0xe2.0x9a.0x9b@gmail.com>
-Jani Monoses <jani.monoses@ubuntu.com> <jani.monoses@gmail.com>
-Jaroslavas Počepko <jp@webmaster.ms>
-Jason Del Ponte <delpontej@gmail.com>
-Jason Travis <infomaniac7@gmail.com>
-Jay Weisskopf <jay@jayschwa.net>
-Jean-Marc Eurin <jmeurin@google.com>
-Jeff Hodges <jeff@somethingsimilar.com>
-Jeff R. Allen <jra@nella.org> <jeff.allen@gmail.com>
-Jeff Sickel <jas@corpus-callosum.com>
-Jeff Wendling <jeff@spacemonkey.com>
-Jeremiah Harmsen <jeremiah@google.com>
-Jeremy Jackins <jeremyjackins@gmail.com>
-Jeremy Schlatter <jeremy.schlatter@gmail.com>
-Jim McGrath <jimmc2@gmail.com>
-Jimmy Zelinskie <jimmyzelinskie@gmail.com>
-Jingcheng Zhang <diogin@gmail.com>
-Joakim Sernbrant <serbaut@gmail.com>
-Joe Poirier <jdpoirier@gmail.com>
-Joel Sing <jsing@google.com>
-Johan Euphrosine <proppy@google.com>
-John Asmuth <jasmuth@gmail.com>
-John Beisley <huin@google.com>
-John C Barstow <jbowtie@amathaine.com>
-John DeNero <denero@google.com>
-John Graham-Cumming <jgc@jgc.org> <jgrahamc@gmail.com>
-John Howard Palevich <jack.palevich@gmail.com>
-John Newlin <jnewlin@google.com>
-John Shahid <jvshahid@gmail.com>
-Jonathan Allie <jonallie@google.com>
-Jonathan Feinberg <feinberg@google.com>
-Jonathan Gold <jgold.bg@gmail.com>
-Jonathan Hseu <jhseu@google.com>
-Jonathan Mark <jhmark@xenops.com> <jhmark000@gmail.com>
-Jonathan Nieder <jrn@google.com>
-Jonathan Pittman <jmpittman@google.com> <jonathan.mark.pittman@gmail.com>
-Jonathan Rudenberg <jonathan@titanous.com>
-Jonathan Wills <runningwild@gmail.com>
-Jongmin Kim <atomaths@gmail.com>
-Jos Visser <josv@google.com>
-Jose Luis Vázquez González <josvazg@gmail.com>
-Joseph Bonneau <jcb@google.com>
-Joseph Holsten <joseph@josephholsten.com>
-Josh Bleecher Snyder <josharian@gmail.com>
-Josh Goebel <dreamer3@gmail.com>
-Josh Hoak <jhoak@google.com>
-Josh Holland <jrh@joshh.co.uk>
-Joshua Chase <jcjoshuachase@gmail.com>
-JP Sugarbroad <jpsugar@google.com>
-Jukka-Pekka Kekkonen <karatepekka@gmail.com>
-Julian Phillips <julian@quantumfyre.co.uk>
-Julien Schmidt <google@julienschmidt.com>
-Kai Backman <kaib@golang.org>
-Kamil Kisiel <kamil@kamilkisiel.net> <kamil.kisiel@gmail.com>
-Katrina Owen <katrina.owen@gmail.com>
-Kay Zhu <kayzhu@google.com>
-Kei Son <hey.calmdown@gmail.com>
-Keith Randall <khr@golang.org>
-Keith Rarick <kr@xph.us>
-Kelsey Hightower <kelsey.hightower@gmail.com>
-Kelvin Foo Chuan Lyi <vmirage@gmail.com>
-Ken Friedenbach <kenliz@cruzio.com>
-Ken Rockot <ken@oz.gs> <ken.rockot@gmail.com>
-Ken Thompson <ken@golang.org>
-Kevin Ballard <kevin@sb.org>
-Kevin Klues <klueska@gmail.com> <klueska@google.com>
-Kirklin McDonald <kirklin.mcdonald@gmail.com>
-Kyle Consalus <consalus@gmail.com>
-Kyle Isom <kyle@gokyle.net>
-Kyle Lemons <kyle@kylelemons.net> <kevlar@google.com>
-L Campbell <unpantsu@gmail.com>
-Lai Jiangshan <eag0628@gmail.com>
-Larry Hosken <lahosken@golang.org>
-Lorenzo Stoakes <lstoakes@gmail.com>
-Louis Kruger <louisk@google.com>
-Luca Greco <luca.greco@alcacoop.it>
-Lucio De Re <lucio.dere@gmail.com>
-Luit van Drongelen <luitvd@gmail.com>
-Luka Zakrajšek <tr00.g33k@gmail.com>
-Luke Curley <qpingu@gmail.com>
-Luuk van Dijk <lvd@golang.org> <lvd@google.com>
-Manoj Dayaram <platform-dev@moovweb.com> <manoj.dayaram@moovweb.com>
-Manu Garg <manugarg@google.com>
-Marc Weistroff <marc@weistroff.net>
-Marcel van Lohuizen <mpvl@golang.org>
-Marco Hennings <marco.hennings@freiheit.com>
-Mark Zavislak <zavislak@google.com>
-Marko Juhani Silokunnas <marko.silokunnas@gmail.com>
-Marko Mikulicic <mkm@google.com>
-Marko Tiikkaja <marko@joh.to>
-Markus Duft <markus.duft@salomon.at>
-Markus Sonderegger <marraison@gmail.com>
-Markus Zimmermann <zimmski@gmail.com>
-Martin Neubauer <m.ne@gmx.net>
-Martin Olsson <martin@minimum.se>
-Mateusz Czapliński <czapkofan@gmail.com>
-Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
-Mats Lidell <mats.lidell@cag.se> <mats.lidell@gmail.com>
-Matt Aimonetti <mattaimonetti@gmail.com>
-Matt Brown <mdbrown@google.com>
-Matt Jibson <matt.jibson@gmail.com>
-Matt Joiner <anacrolix@gmail.com>
-Matt Jones <mrjones@google.com>
-Matt Reiferson <mreiferson@gmail.com>
-Matthew Cottingham <mattcottingham@gmail.com>
-Matthew Dempsky <mdempsky@google.com>
-Matthew Horsnell <matthew.horsnell@gmail.com>
-Maxim Khitrov <max@mxcrypt.com>
-Maxim Pimenov <mpimenov@google.com>
-Maxim Ushakov <ushakov@google.com>
-Micah Stetson <micah.stetson@gmail.com>
-Michael Chaten <mchaten@gmail.com>
-Michael Elkins <michael.elkins@gmail.com>
-Michael Fraenkel <michael.fraenkel@gmail.com>
-Michael Gehring <mg@ebfe.org> <gnirheg.leahcim@gmail.com>
-Michael Hoisie <hoisie@gmail.com>
-Michael Hudson-Doyle <michael.hudson@linaro.org>
-Michael Kelly <mjk@google.com>
-Michael Lewis <mikelikespie@gmail.com>
-Michael Matloob <matloob@google.com>
-Michael Pearson <mipearson@gmail.com>
-Michael Piatek <piatek@google.com>
-Michael Shields <mshields@google.com>
-Michael Stapelberg <michael@stapelberg.de> <mstplbrg@googlemail.com>
-Michael T. Jones <mtj@google.com> <michael.jones@gmail.com>
-Michael Teichgräber <mteichgraeber@gmx.de> <mt4swm@googlemail.com>
-Michał Derkacz <ziutek@lnet.pl>
-Miek Gieben <miek@miek.nl> <remigius.gieben@gmail.com>
-Mihai Borobocea <MihaiBorobocea@gmail.com>
-Mikael Tillenius <mikti42@gmail.com>
-Mike Andrews <mra@xoba.com>
-Mike Rosset <mike.rosset@gmail.com>
-Mike Samuel <mikesamuel@gmail.com>
-Mike Solomon <msolo@gmail.com>
-Mikhail Panchenko <m@mihasya.com>
-Miki Tebeka <miki.tebeka@gmail.com>
-Mikio Hara <mikioh.mikioh@gmail.com>
-Mikkel Krautz <mikkel@krautz.dk> <krautz@gmail.com>
-Miquel Sabaté Solà <mikisabate@gmail.com>
-Moriyoshi Koizumi <mozo@mozo.jp>
-Môshe van der Sterre <moshevds@gmail.com>
-Nan Deng <monnand@gmail.com>
-Nathan John Youngman <nj@nathany.com>
-Nicholas Katsaros <nick@nickkatsaros.com>
-Nicholas Presta <nick@nickpresta.ca> <nick1presta@gmail.com>
-Nicholas Sullivan <nicholas.sullivan@gmail.com>
-Nicholas Waples <nwaples@gmail.com>
-Nick Craig-Wood <nick@craig-wood.com> <nickcw@gmail.com>
-Nicolas Kaiser <nikai@nikai.net>
-Nicolas Owens <mischief@offblast.org>
-Nigel Kerr <nigel.kerr@gmail.com>
-Nigel Tao <nigeltao@golang.org>
-Noah Campbell <noahcampbell@gmail.com>
-Oling Cat <olingcat@gmail.com>
-Oliver Hookins <ohookins@gmail.com>
-Olivier Antoine <olivier.antoine@gmail.com>
-Olivier Duperray <duperray.olivier@gmail.com>
-Olivier Saingre <osaingre@gmail.com>
-Padraig Kitterick <padraigkitterick@gmail.com>
-Paolo Giarrusso <p.giarrusso@gmail.com>
-Pascal S. de Kloe <pascal@quies.net>
-Patrick Crosby <patrick@stathat.com>
-Patrick Gavlin <pgavlin@gmail.com>
-Patrick Higgins <patrick.allen.higgins@gmail.com>
-Patrick Mézard <patrick@mezard.eu>
-Patrick Mylund Nielsen <patrick@patrickmn.com>
-Patrick Riley <pfr@google.com>
-Patrick Smith <pat42smith@gmail.com>
-Paul A Querna <paul.querna@gmail.com>
-Paul Borman <borman@google.com>
-Paul Chang <paulchang@google.com>
-Paul Hammond <paul@paulhammond.org>
-Paul Lalonde <paul.a.lalonde@gmail.com>
-Paul Sbarra <Sbarra.Paul@gmail.com>
-Paul van Brouwershaven <paul@vanbrouwershaven.com>
-Pavel Zinovkin <pavel.zinovkin@gmail.com>
-Pawel Szczur <filemon@google.com>
-Petar Maymounkov <petarm@gmail.com>
-Peter Armitage <peter.armitage@gmail.com>
-Peter Collingbourne <pcc@google.com>
-Peter Froehlich <peter.hans.froehlich@gmail.com>
-Peter Kleiweg <pkleiweg@xs4all.nl>
-Peter McKenzie <petermck@google.com>
-Peter Mundy <go.peter.90@gmail.com>
-Péter Surányi <speter.go1@gmail.com>
-Péter Szabó <pts@google.com>
-Péter Szilágyi <peterke@gmail.com>
-Peter Waller <peter.waller@gmail.com>
-Peter Weinberger <pjw@golang.org>
-Peter Williams <pwil3058@gmail.com>
-Phil Pennock <pdp@golang.org>
-Philip K. Warren <pkwarren@gmail.com>
-Pieter Droogendijk <pieter@binky.org.uk>
-Pietro Gagliardi <pietro10@mac.com>
-Preetam Jinka <pj@preet.am>
-Quan Yong Zhai <qyzhai@gmail.com>
-Raif S. Naffah <go@naffah-raif.name>
-Raph Levien <raph@google.com>
-Rémy Oudompheng <oudomphe@phare.normalesup.org> <remyoudompheng@gmail.com>
-Richard Crowley <r@rcrowley.org>
-Richard Eric Gavaletz <gavaletz@gmail.com>
-Richard Musiol <mail@richard-musiol.de> <neelance@gmail.com>
-Rick Arnold <rickarnoldjr@gmail.com>
-Risto Jaakko Saarelma <rsaarelm@gmail.com>
-Rob Pike <r@golang.org>
-Robert Daniel Kortschak <dan.kortschak@adelaide.edu.au>
-Robert Dinu <r@varp.se>
-Robert Figueiredo <robfig@gmail.com>
-Robert Griesemer <gri@golang.org>
-Robert Hencke <robert.hencke@gmail.com>
-Robert Obryk <robryk@gmail.com>
-Robert Sesek <rsesek@google.com>
-Robert Snedegar <roberts@google.com>
-Robin Eklind <r.eklind.87@gmail.com>
-Rodrigo Moraes de Oliveira <rodrigo.moraes@gmail.com>
-Rodrigo Rafael Monti Kochenburger <divoxx@gmail.com>
-Roger Pau Monné <royger@gmail.com>
-Roger Peppe <rogpeppe@gmail.com>
-Ron Minnich <rminnich@gmail.com>
-Ross Light <rlight2@gmail.com>
-Rowan Worth <sqweek@gmail.com>
-Rui Ueyama <ruiu@google.com>
-Russ Cox <rsc@golang.org>
-Ryan Barrett <ryanb@google.com>
-Ryan Hitchman <hitchmanr@gmail.com>
-Ryan Slade <ryanslade@gmail.com>
-S.Çağlar Onur <caglar@10ur.org>
-Sam Thorogood <thorogood@google.com> <sam.thorogood@gmail.com>
-Sameer Ajmani <sameer@golang.org> <ajmani@gmail.com>
-Sanjay Menakuru <balasanjay@gmail.com>
-Scott Ferguson <scottwferg@gmail.com>
-Scott Lawrence <bytbox@gmail.com>
-Scott Schwartz <scotts@golang.org>
-Sean Burford <sburford@google.com>
-Sebastien Binet <seb.binet@gmail.com>
-Sébastien Paolacci <sebastien.paolacci@gmail.com>
-Sergei Skorobogatov <skorobo@rambler.ru>
-Sergey 'SnakE' Gromov <snake.scaly@gmail.com>
-Sergio Luis O. B. Correia <sergio@correia.cc>
-Shane Hansen <shanemhansen@gmail.com>
-Shawn Ledbetter <sledbetter@google.com>
-Shawn Smith <shawn.p.smith@gmail.com>
-Shenghou Ma <minux@golang.org> <minux.ma@gmail.com>
-Shivakumar GN <shivakumar.gn@gmail.com>
-Sokolov Yura <funny.falcon@gmail.com>
-Spring Mc <heresy.mc@gmail.com>
-StalkR <stalkr@stalkr.net>
-Stefan Nilsson <snilsson@nada.kth.se> <trolleriprofessorn@gmail.com>
-Stéphane Travostino <stephane.travostino@gmail.com>
-Stephen Ma <stephenm@golang.org>
-Stephen McQuay <stephen@mcquay.me>
-Stephen Weinberg <stephen@q5comm.com>
-Steve McCoy <mccoyst@gmail.com>
-Steven Elliot Harris <seharris@gmail.com>
-Steven Hartland <steven.hartland@multiplay.co.uk>
-Sugu Sougoumarane <ssougou@gmail.com>
-Sven Almgren <sven@tras.se>
-Szabolcs Nagy <nsz@port70.net>
-Tad Glines <tad.glines@gmail.com>
-Taj Khattra <taj.khattra@gmail.com>
-Tarmigan Casebolt <tarmigan@gmail.com>
-Taru Karttunen <taruti@taruti.net>
-Thomas Alan Copeland <talan.copeland@gmail.com>
-Thomas Habets <habets@google.com>
-Thomas Kappler <tkappler@gmail.com>
-Timo Savola <timo.savola@gmail.com>
-Tobias Columbus <tobias.columbus@gmail.com> <tobias.columbus@googlemail.com>
-Todd Wang <toddwang@gmail.com>
-Tom Szymanski <tgs@google.com>
-Tor Andersson <tor.andersson@gmail.com>
-Travis Cline <travis.cline@gmail.com>
-Trevor Strohman <trevor.strohman@gmail.com>
-Tudor Golubenco <tudor.g@gmail.com>
-Tw <tw19881113@gmail.com>
-Tyler Bunnell <tylerbunnell@gmail.com>
-Ugorji Nwoke <ugorji@gmail.com>
-Ulf Holm Nielsen <doktor@dyregod.dk>
-Uriel Mangado <uriel@berlinblue.org>
-Vadim Vygonets <unixdj@gmail.com>
-Vega Garcia Luis Alfonso <vegacom@gmail.com>
-Vincent Ambo <tazjin@googlemail.com>
-Vincent Vanackere <vincent.vanackere@gmail.com>
-Vinu Rajashekhar <vinutheraj@gmail.com>
-Vish Subramanian <vish@google.com>
-Vladimir Nikishenko <vova616@gmail.com>
-Volker Dobler <dr.volker.dobler@gmail.com>
-Wei Guangjing <vcc.163@gmail.com>
-Will Norris <willnorris@google.com>
-Willem van der Schyff <willemvds@gmail.com>
-William Chan <willchan@chromium.org>
-William Josephson <wjosephson@gmail.com>
-William Orr <will@worrbase.com> <ay1244@gmail.com>
-Xing Xing <mikespook@gmail.com>
-Yan Zou <yzou@google.com>
-Yasuhiro Matsumoto <mattn.jp@gmail.com>
-Yissakhar Z. Beck <yissakhar.beck@gmail.com>
-Yongjian Xu <i3dmaster@gmail.com>
-Yoshiyuki Kanno <nekotaroh@gmail.com> <yoshiyuki.kanno@stoic.co.jp>
-Yusuke Kagiwada <block.rxckin.beats@gmail.com>
-Yuusei Kuwana <kuwana@kumama.org>
-Yuval Pavel Zholkover <paulzhol@gmail.com>
-Yves Junqueira <yves.junqueira@gmail.com>
-Ziad Hatahet <hatahet@gmail.com>
-Zorion Arrizabalaga <zorionk@gmail.com>
-申习之 <bronze1man@gmail.com>
diff --git a/internal/stdlib/testdata/v1.3.2/LICENSE b/internal/stdlib/testdata/v1.3.2/LICENSE
deleted file mode 100644
index 7448756..0000000
--- a/internal/stdlib/testdata/v1.3.2/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2012 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/internal/stdlib/testdata/v1.3.2/PATENTS b/internal/stdlib/testdata/v1.3.2/PATENTS
deleted file mode 100644
index 7330990..0000000
--- a/internal/stdlib/testdata/v1.3.2/PATENTS
+++ /dev/null
@@ -1,22 +0,0 @@
-Additional IP Rights Grant (Patents)
-
-"This implementation" means the copyrightable works distributed by
-Google as part of the Go project.
-
-Google hereby grants to You a perpetual, worldwide, non-exclusive,
-no-charge, royalty-free, irrevocable (except as stated in this section)
-patent license to make, have made, use, offer to sell, sell, import,
-transfer and otherwise run, modify and propagate the contents of this
-implementation of Go, where such license applies only to those patent
-claims, both currently owned or controlled by Google and acquired in
-the future, licensable by Google that are necessarily infringed by this
-implementation of Go. This grant does not include claims that would be
-infringed only as a consequence of further modification of this
-implementation. If you or your agent or exclusive licensee institute or
-order or agree to the institution of patent litigation against any
-entity (including a cross-claim or counterclaim in a lawsuit) alleging
-that this implementation of Go or any code incorporated within this
-implementation of Go constitutes direct or contributory patent
-infringement, or inducement of patent infringement, then any patent
-rights granted to you under this License for this implementation of Go
-shall terminate as of the date such litigation is filed.
diff --git a/internal/stdlib/testdata/v1.3.2/README b/internal/stdlib/testdata/v1.3.2/README
deleted file mode 100644
index a557fe9..0000000
--- a/internal/stdlib/testdata/v1.3.2/README
+++ /dev/null
@@ -1,32 +0,0 @@
-This is the source code repository for the Go programming language.
-
-For documentation about how to install and use Go,
-visit http://golang.org/ or load doc/install-source.html
-in your web browser.
-
-After installing Go, you can view a nicely formatted
-doc/install-source.html by running godoc --http=:6060
-and then visiting http://localhost:6060/doc/install/source.
-
-Unless otherwise noted, the Go source files are distributed
-under the BSD-style license found in the LICENSE file.
-
---
-
-Binary Distribution Notes
-
-If you have just untarred a binary Go distribution, you need to set
-the environment variable $GOROOT to the full path of the go
-directory (the one containing this README). You can omit the
-variable if you unpack it into /usr/local/go, or if you rebuild
-from sources by running all.bash (see doc/install.html).
-You should also add the Go binary directory $GOROOT/bin
-to your shell's path.
-
-For example, if you extracted the tar file into $HOME/go, you might
-put the following in your .profile:
-
- export GOROOT=$HOME/go
- export PATH=$PATH:$GOROOT/bin
-
-See doc/install.html for more details.
diff --git a/internal/stdlib/testdata/v1.3.2/VERSION b/internal/stdlib/testdata/v1.3.2/VERSION
deleted file mode 100644
index db938eb..0000000
--- a/internal/stdlib/testdata/v1.3.2/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-go1.3.2
\ No newline at end of file
diff --git a/internal/stdlib/testdata/v1.3.2/VERSION.cache b/internal/stdlib/testdata/v1.3.2/VERSION.cache
deleted file mode 100644
index 9588aef..0000000
--- a/internal/stdlib/testdata/v1.3.2/VERSION.cache
+++ /dev/null
@@ -1 +0,0 @@
-devel +a626dacd1c Sat Aug 24 19:56:37 2019 -0400
\ No newline at end of file
diff --git a/internal/stdlib/testdata/v1.3.2/favicon.ico b/internal/stdlib/testdata/v1.3.2/favicon.ico
deleted file mode 100644
index d287722..0000000
--- a/internal/stdlib/testdata/v1.3.2/favicon.ico
+++ /dev/null
Binary files differ
diff --git a/internal/stdlib/testdata/v1.3.2/robots.txt b/internal/stdlib/testdata/v1.3.2/robots.txt
deleted file mode 100644
index 1f53798..0000000
--- a/internal/stdlib/testdata/v1.3.2/robots.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-User-agent: *
-Disallow: /
diff --git a/internal/stdlib/testdata/v1.3.2/src/pkg/errors/errors.go b/internal/stdlib/testdata/v1.3.2/src/pkg/errors/errors.go
deleted file mode 100644
index b8a4692..0000000
--- a/internal/stdlib/testdata/v1.3.2/src/pkg/errors/errors.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package errors implements functions to manipulate errors.
-package errors
-
-// New returns an error that formats as the given text.
-func New(text string) error {
- return &errorString{text}
-}
-
-// errorString is a trivial implementation of error.
-type errorString struct {
- s string
-}
-
-func (e *errorString) Error() string {
- return e.s
-}
diff --git a/internal/stdlib/testdata/v1.3.2/src/pkg/errors/errors_test.go b/internal/stdlib/testdata/v1.3.2/src/pkg/errors/errors_test.go
deleted file mode 100644
index cf4df90..0000000
--- a/internal/stdlib/testdata/v1.3.2/src/pkg/errors/errors_test.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "errors"
- "fmt"
- "testing"
-)
-
-func TestNewEqual(t *testing.T) {
- // Different allocations should not be equal.
- if errors.New("abc") == errors.New("abc") {
- t.Errorf(`New("abc") == New("abc")`)
- }
- if errors.New("abc") == errors.New("xyz") {
- t.Errorf(`New("abc") == New("xyz")`)
- }
-
- // Same allocation should be equal to itself (not crash).
- err := errors.New("jkl")
- if err != err {
- t.Errorf(`err != err`)
- }
-}
-
-func TestErrorMethod(t *testing.T) {
- err := errors.New("abc")
- if err.Error() != "abc" {
- t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
- }
-}
-
-func ExampleNew() {
- err := errors.New("emit macho dwarf: elf header corrupted")
- if err != nil {
- fmt.Print(err)
- }
- // Output: emit macho dwarf: elf header corrupted
-}
-
-// The fmt package's Errorf function lets us use the package's formatting
-// features to create descriptive error messages.
-func ExampleNew_errorf() {
- const name, id = "bimmler", 17
- err := fmt.Errorf("user %q (id %d) not found", name, id)
- if err != nil {
- fmt.Print(err)
- }
- // Output: user "bimmler" (id 17) not found
-}
diff --git a/internal/stdlib/testdata/v1.3.2/src/pkg/errors/example_test.go b/internal/stdlib/testdata/v1.3.2/src/pkg/errors/example_test.go
deleted file mode 100644
index 5dc8841..0000000
--- a/internal/stdlib/testdata/v1.3.2/src/pkg/errors/example_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "fmt"
- "time"
-)
-
-// MyError is an error implementation that includes a time and message.
-type MyError struct {
- When time.Time
- What string
-}
-
-func (e MyError) Error() string {
- return fmt.Sprintf("%v: %v", e.When, e.What)
-}
-
-func oops() error {
- return MyError{
- time.Date(1989, 3, 15, 22, 30, 0, 0, time.UTC),
- "the file system has gone away",
- }
-}
-
-func Example() {
- if err := oops(); err != nil {
- fmt.Println(err)
- }
- // Output: 1989-03-15 22:30:00 +0000 UTC: the file system has gone away
-}