| 1 | // Copyright 2022 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package diffpscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/ |
| 6 | |
| 7 | import ( |
| 8 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 9 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 10 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 11 | |
| 12 | "golang.org/x/tools/txtarscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/" |
| 13 | ) |
| 14 | |
| 15 | func cleanscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/clean().(text []byte) []byte { |
| 16 | text = bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.ReplaceAllscip-go gomod github.com/golang/go/src go1.25.0 bytes/ReplaceAll().(text, []byte("$\n"), []byte("\n")) |
| 17 | text = bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.TrimSuffixscip-go gomod github.com/golang/go/src go1.25.0 bytes/TrimSuffix().(text, []byte("^D\n")) |
| 18 | return text |
| 19 | } |
| 20 | |
| 21 | func Testscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/Test().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 22 | files, _ := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Globscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Glob().("testdata/*.txt") |
| 23 | if len(files) == 0 { |
| 24 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("no testdata") |
| 25 | } |
| 26 | |
| 27 | for _, file := range files { |
| 28 | t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Base().(file), func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 29 | a, err := txtarscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/.ParseFilescip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/ParseFile().(file) |
| 30 | if err != nil { |
| 31 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 32 | } |
| 33 | if len(a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.) != 3 || a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.[2].Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/File#Name. != "diff" { |
| 34 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s: want three files, third named \"diff\"", file) |
| 35 | } |
| 36 | diffs := Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/Diff().(a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.[0].Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/File#Name., cleanscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/clean().(a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.[0].Datascip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/File#Data.), a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.[1].Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/File#Name., cleanscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/clean().(a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.[1].Datascip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/File#Data.)) |
| 37 | want := cleanscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/clean().(a.Filesscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Archive#Files.[2].Datascip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/File#Data.) |
| 38 | if !bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.25.0 bytes/Equal().(diffs, want) { |
| 39 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%s: have:\n%s\nwant:\n%s\n%s", file, |
| 40 | diffs, want, Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diffp`/Diff().("have", diffs, "want", want)) |
| 41 | } |
| 42 | }) |
| 43 | } |
| 44 | } |