Debian Codegraph @

trace/internal/diff/diff_test.go

raw symbols SCIP
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 // Code generated by "gen.bash" from internal/trace; DO NOT EDIT.
6
7 //go:build go1.23
8
9 package diff
10
11 import (
12 "bytes"
13 "golang.org/x/tools/txtar"
14 "path/filepath"
15 "testing"
16 )
17
18 func clean(text []byte) []byte {
19 text = bytes.ReplaceAll(text, []byte("$\n"), []byte("\n"))
20 text = bytes.TrimSuffix(text, []byte("^D\n"))
21 return text
22 }
23
24 func Test(t *testing.T) {
25 files, _ := filepath.Glob("testdata/*.txt")
26 if len(files) == 0 {
27 t.Fatalf("no testdata")
28 }
29
30 for _, file := range files {
31 t.Run(filepath.Base(file), func(t *testing.T) {
32 a, err := txtar.ParseFile(file)
33 if err != nil {
34 t.Fatal(err)
35 }
36 if len(a.Files) != 3 || a.Files[2].Name != "diff" {
37 t.Fatalf("%s: want three files, third named \"diff\"", file)
38 }
39 diffs := Diff(a.Files[0].Name, clean(a.Files[0].Data), a.Files[1].Name, clean(a.Files[1].Data))
40 want := clean(a.Files[2].Data)
41 if !bytes.Equal(diffs, want) {
42 t.Fatalf("%s: have:\n%s\nwant:\n%s\n%s", file,
43 diffs, want, Diff("have", diffs, "want", want))
44 }
45 })
46 }
47 }