package fsys
import (
- "cmd/go/internal/txtar"
"encoding/json"
"errors"
"fmt"
"path/filepath"
"reflect"
"testing"
+
+ "golang.org/x/tools/txtar"
)
// initOverlay resets the overlay state to reflect the config.
+++ /dev/null
-// 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 txtar
-
-import (
- "bytes"
- "fmt"
- "reflect"
- "testing"
-)
-
-var tests = []struct {
- name string
- text string
- parsed *Archive
-}{
- {
- name: "basic",
- text: `comment1
-comment2
--- file1 --
-File 1 text.
--- foo ---
-More file 1 text.
--- file 2 --
-File 2 text.
--- empty --
--- noNL --
-hello world`,
- parsed: &Archive{
- Comment: []byte("comment1\ncomment2\n"),
- Files: []File{
- {"file1", []byte("File 1 text.\n-- foo ---\nMore file 1 text.\n")},
- {"file 2", []byte("File 2 text.\n")},
- {"empty", []byte{}},
- {"noNL", []byte("hello world\n")},
- },
- },
- },
-}
-
-func Test(t *testing.T) {
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- a := Parse([]byte(tt.text))
- if !reflect.DeepEqual(a, tt.parsed) {
- t.Fatalf("Parse: wrong output:\nhave:\n%s\nwant:\n%s", shortArchive(a), shortArchive(tt.parsed))
- }
- text := Format(a)
- a = Parse(text)
- if !reflect.DeepEqual(a, tt.parsed) {
- t.Fatalf("Parse after Format: wrong output:\nhave:\n%s\nwant:\n%s", shortArchive(a), shortArchive(tt.parsed))
- }
- })
- }
-}
-
-func shortArchive(a *Archive) string {
- var buf bytes.Buffer
- fmt.Fprintf(&buf, "comment: %q\n", a.Comment)
- for _, f := range a.Files {
- fmt.Fprintf(&buf, "file %q: %q\n", f.Name, f.Data)
- }
- return buf.String()
-}
"cmd/go/internal/modfetch/codehost"
"cmd/go/internal/par"
- "cmd/go/internal/txtar"
"golang.org/x/mod/module"
"golang.org/x/mod/semver"
"golang.org/x/mod/sumdb"
"golang.org/x/mod/sumdb/dirhash"
+ "golang.org/x/tools/txtar"
)
var (
"cmd/go/internal/imports"
"cmd/go/internal/par"
"cmd/go/internal/robustio"
- "cmd/go/internal/txtar"
"cmd/go/internal/work"
"cmd/internal/sys"
+
+ "golang.org/x/tools/txtar"
)
var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set, TestScript generates a go.sum file at the beginning of each test and updates test files if they pass.`)
"path/filepath"
"strings"
- "cmd/go/internal/txtar"
+ "golang.org/x/tools/txtar"
)
func usage() {
"strings"
"unicode/utf8"
- "../internal/txtar"
+ "golang.org/x/tools/txtar"
)
func usage() {
import (
"bytes"
"fmt"
- "os"
+ "io/ioutil"
"strings"
)
// ParseFile parses the named file as an archive.
func ParseFile(file string) (*Archive, error) {
- data, err := os.ReadFile(file)
+ data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
if i := bytes.IndexByte(data, '\n'); i >= 0 {
data, after = data[:i], data[i+1:]
}
- if !bytes.HasSuffix(data, markerEnd) {
+ if !(bytes.HasSuffix(data, markerEnd) && len(data) >= len(marker)+len(markerEnd)) {
return "", nil
}
return strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after
golang.org/x/tools/internal/analysisinternal
golang.org/x/tools/internal/lsp/fuzzy
golang.org/x/tools/internal/typeparams
+golang.org/x/tools/txtar
# golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
## explicit; go 1.11
golang.org/x/xerrors