Debian Codegraph @

internal/diff/lcs/old_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 package lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/
6
7 import (
8 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
9 "logscip-go gomod github.com/golang/go/src go1.25.0 log/"
10 "math/rand/v2scip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/"
11 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
12 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
13 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
14 )
15
16 func TestAlgosOldscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestAlgosOld().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
17 for i, algo := range []func(*editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#{forwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/forward()., backwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/backward()., twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided().} {
18 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.25.0 strings/Fields().("forward backward twosided")[i], 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#) {
19 for _, tx := range Btestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btests. {
20 lim := len(tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a.) + len(tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b.)
21
22 diffs, lcs := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a., tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b.}, algo, lim)
23 checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/check().(t, tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a., lcs, tx.lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#lcs.)
24 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a., diffs, tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b.)
25
26 diffs, lcs = computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b., tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a.}, algo, lim)
27 checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/check().(t, tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b., lcs, tx.lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#lcs.)
28 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b., diffs, tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a.)
29 }
30 })
31 }
32 }
33
34 func TestIntOldscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestIntOld().(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#) {
35 // need to avoid any characters in btests
36 lfill, rfill := "AAAAAAAAAAAA", "BBBBBBBBBBBB"
37 for _, tx := range Btestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btests. {
38 if len(tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a.) < 2 || len(tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b.) < 2 {
39 continue
40 }
41 left := tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a. + lfill
42 right := tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b. + rfill
43 lim := len(tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a.) + len(tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b.)
44 diffs, lcs := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{left, right}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., lim)
45 checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/check().(t, left, lcs, tx.lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#lcs.)
46 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, left, diffs, right)
47 diffs, lcs = computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{right, left}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., lim)
48 checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/check().(t, right, lcs, tx.lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#lcs.)
49 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, right, diffs, left)
50
51 left = lfill + tx.ascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#a.
52 right = rfill + tx.bscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#b.
53 diffs, lcs = computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{left, right}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., lim)
54 checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/check().(t, left, lcs, tx.lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#lcs.)
55 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, left, diffs, right)
56 diffs, lcs = computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{right, left}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., lim)
57 checkscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/check().(t, right, lcs, tx.lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Btest#lcs.)
58 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, right, diffs, left)
59 }
60 }
61
62 func TestSpecialOldscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestSpecialOld().(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#) { // exercises lcs.fix
63 a := "golang.org/x/tools/intern"
64 b := "github.com/google/safehtml/template\"\n\t\"golang.org/x/tools/intern"
65 diffs, lcs := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{a, b}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., 4)
66 if !lcs.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
67 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d,%v", len(diffs), lcs)
68 }
69 }
70
71 func TestRegressionOld001scip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestRegressionOld001().(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#) {
72 a := "// Copyright 2019 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage diff_test\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"golang.org/x/tools/gopls/internal/lsp/diff\"\n\t\"golang.org/x/tools/internal/diff/difftest\"\n\t\"golang.org/x/tools/gopls/internal/span\"\n)\n"
73
74 b := "// Copyright 2019 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage diff_test\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/google/safehtml/template\"\n\t\"golang.org/x/tools/gopls/internal/lsp/diff\"\n\t\"golang.org/x/tools/internal/diff/difftest\"\n\t\"golang.org/x/tools/gopls/internal/span\"\n)\n"
75 for i := 1; i < len(b); i++ {
76 diffs, lcs := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{a, b}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., i) // 14 from gopls
77 if !lcs.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
78 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d,%v", len(diffs), lcs)
79 }
80 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, a, diffs, b)
81 }
82 }
83
84 func TestRegressionOld002scip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestRegressionOld002().(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#) {
85 a := "n\"\n)\n"
86 b := "n\"\n\t\"golang.org/x//nnal/stack\"\n)\n"
87 for i := 1; i <= len(b); i++ {
88 diffs, lcs := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{a, b}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., i)
89 if !lcs.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
90 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d,%v", len(diffs), lcs)
91 }
92 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, a, diffs, b)
93 }
94 }
95
96 func TestRegressionOld003scip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestRegressionOld003().(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#) {
97 a := "golang.org/x/hello v1.0.0\nrequire golang.org/x/unused v1"
98 b := "golang.org/x/hello v1"
99 for i := 1; i <= len(a); i++ {
100 diffs, lcs := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{a, b}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., i)
101 if !lcs.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
102 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%d,%v", len(diffs), lcs)
103 }
104 checkDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/checkDiffs().(t, a, diffs, b)
105 }
106 }
107
108 func TestRandOldscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestRandOld().(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#) {
109 rng := rngscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/rng().(t)
110
111 for i := range 1000 {
112 // TODO(adonovan): use ASCII and bytesSeqs here? The use of
113 // non-ASCII isn't relevant to the property exercised by the test.
114 a := []rune(randstrscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/randstr().(rng, "abω", 16))
115 b := []rune(randstrscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/randstr().(rng, "abωc", 16))
116 seq := runesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/runesSeqs#{a, b}
117
118 const lim = 0 // make sure we get the lcs (24 was too small)
119 _, forw := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(seq, forwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/forward()., lim)
120 _, back := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(seq, backwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/backward()., lim)
121 _, two := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(seq, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., lim)
122 if lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(two) != lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(forw) || lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(forw) != lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(back) {
123 t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("\n%v\n%v\n%v", forw, back, two)
124 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("%d forw:%d back:%d two:%d", i, lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(forw), lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(back), lcslenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcslen().(two))
125 }
126 if !two.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() || !forw.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() || !back.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
127 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("check failure")
128 }
129 }
130 }
131
132 // TestDiffAPI tests the public API functions (Diff{Bytes,Strings,Runes})
133 // to ensure at least minimal parity of the three representations.
134 func TestDiffAPIscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/TestDiffAPI().(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#) {
135 for _, test := range []struct {
136 a, b string
137 wantBytes, wantRunes string
138 }{
139 {"abcXdef", "abcxdef", "[{3 4 3 4}]", "[{3 4 3 4}]"}, // ASCII
140 {"abcωdef", "abcΩdef", "[{3 5 3 5}]", "[{3 4 3 4}]"}, // non-ASCII
141 } {
142
143 gotBytes := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(DiffBytesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/DiffBytes().([]byte(test.a), []byte(test.b)))
144 if gotBytes != test.wantBytes {
145 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("DiffBytes(%q, %q) = %v, want %v",
146 test.a, test.b, gotBytes, test.wantBytes)
147 }
148 gotRunes := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprint().(DiffRunesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/DiffRunes().([]rune(test.a), []rune(test.b)))
149 if gotRunes != test.wantRunes {
150 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("DiffRunes(%q, %q) = %v, want %v",
151 test.a, test.b, gotRunes, test.wantRunes)
152 }
153 }
154 }
155
156 func BenchmarkTwoOldscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/BenchmarkTwoOld().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
157 tests := genBenchscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/genBench().(rngscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/rng().(b), "abc", 96)
158 for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() {
159 for _, tt := range tests {
160 _, two := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{tt.before, tt.after}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., 100)
161 if !two.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
162 b.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("check failed")
163 }
164 }
165 }
166 }
167
168 func BenchmarkForwOldscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/BenchmarkForwOld().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
169 tests := genBenchscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/genBench().(rngscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/rng().(b), "abc", 96)
170 for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() {
171 for _, tt := range tests {
172 _, two := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{tt.before, tt.after}, forwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/forward()., 100)
173 if !two.validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#valid().() {
174 b.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("check failed")
175 }
176 }
177 }
178 }
179
180 // rng returns a randomly initialized PRNG whose seeds are logged so
181 // that occasional test failures can be deterministically replayed.
182 func rngscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/rng().(tb testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.TBscip-go gomod github.com/golang/go/src go1.25.0 testing/TB#) *randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.Randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/Rand# {
183 seed1, seed2 := randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.Uint64scip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/Uint64().(), randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.Uint64scip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/Uint64().()
184 tb.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/TB#Logf().("PRNG seeds: %d, %d", seed1, seed2)
185 return randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.Newscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/New().(randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.NewPCGscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/NewPCG().(seed1, seed2))
186 }
187
188 func genBenchscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/genBench().(rng *randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.Randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/Rand#, set string, n int) []struct{ before, after string } {
189 // before and after for benchmarks. 24 strings of length n with
190 // before and after differing at least once, and about 5%
191 var ans []struct{ before, after string }
192 for range 24 {
193 // maybe b should have an approximately known number of diffs
194 a := randstrscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/randstr().(rng, set, n)
195 cnt := 0
196 bb := make([]rune, 0, n)
197 for _, r := range a {
198 if randscip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/.Float64scip-go gomod github.com/golang/go/src go1.25.0 `math/rand/v2`/Float64().() < .05 {
199 cnt++
200 r = 'N'
201 }
202 bb = append(bb, r)
203 }
204 if cnt == 0 {
205 // avoid == shortcut
206 bb[n/2] = 'N'
207 }
208 ans = append(ans, struct{ before, after string }{a, string(bb)})
209 }
210 return ans
211 }
212
213 // This benchmark represents a common case for a diff command:
214 // large file with a single relatively small diff in the middle.
215 // (It's not clear whether this is representative of gopls workloads
216 // or whether it is important to gopls diff performance.)
217 //
218 // TODO(adonovan) opt: it could be much faster. For example,
219 // comparing a file against itself is about 10x faster than with the
220 // small deletion in the middle. Strangely, comparing a file against
221 // itself minus the last byte is faster still; I don't know why.
222 // There is much low-hanging fruit here for further improvement.
223 func BenchmarkLargeFileSmallDiffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/BenchmarkLargeFileSmallDiff().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
224 data, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().("old.go") // large file
225 if err != nil {
226 logscip-go gomod github.com/golang/go/src go1.25.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.25.0 log/Fatal().(err)
227 }
228
229 n := len(data)
230
231 src := string(data)
232 dst := src[:n*49/100] + src[n*51/100:] // remove 2% from the middle
233 b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("string", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
234 for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() {
235 computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(stringSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/stringSeqs#{src, dst}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., len(src)+len(dst))
236 }
237 })
238
239 srcBytes := []byte(src)
240 dstBytes := []byte(dst)
241 b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("bytes", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
242 for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() {
243 computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(bytesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/bytesSeqs#{srcBytes, dstBytes}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., len(srcBytes)+len(dstBytes))
244 }
245 })
246
247 srcRunes := []rune(src)
248 dstRunes := []rune(dst)
249 b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("runes", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
250 for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() {
251 computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(runesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/runesSeqs#{srcRunes, dstRunes}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., len(srcRunes)+len(dstRunes))
252 }
253 })
254 srcLines := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(src, "\n")
255 dstLines := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(dst, "\n")
256 b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("lines", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
257 for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() {
258 computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(linesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/linesSeqs#{srcLines, dstLines}, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., len(srcLines)+len(dstLines))
259 }
260 })
261 }