Skip to content

Commit 14ad8a0

Browse files
authored
Format with Go 1.19 formatter (#304)
This allows the GoDoc to take advantage of new markup syntax introduced in Go 1.19. This does not require that our minimum supported version be bumped to Go 1.19 since the pkgsite renders our godoc regardless of supported Go version.
1 parent a53d7e0 commit 14ad8a0

File tree

11 files changed

+88
-75
lines changed

11 files changed

+88
-75
lines changed

cmp/cmpopts/equate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func isEmpty(x, y interface{}) bool {
4242
// The fraction and margin must be non-negative.
4343
//
4444
// The mathematical expression used is equivalent to:
45+
//
4546
// |x-y| ≤ max(fraction*min(|x|, |y|), margin)
4647
//
4748
// EquateApprox can be used in conjunction with EquateNaNs.

cmp/cmpopts/sort.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
// sort any slice with element type V that is assignable to T.
1919
//
2020
// The less function must be:
21-
// Deterministic: less(x, y) == less(x, y)
22-
// Irreflexive: !less(x, x)
23-
// Transitive: if !less(x, y) and !less(y, z), then !less(x, z)
21+
// - Deterministic: less(x, y) == less(x, y)
22+
// - Irreflexive: !less(x, x)
23+
// - Transitive: if !less(x, y) and !less(y, z), then !less(x, z)
2424
//
2525
// The less function does not have to be "total". That is, if !less(x, y) and
2626
// !less(y, x) for two elements x and y, their relative order is maintained.
@@ -91,10 +91,10 @@ func (ss sliceSorter) less(v reflect.Value, i, j int) bool {
9191
// use Comparers on K or the K.Equal method if it exists.
9292
//
9393
// The less function must be:
94-
// Deterministic: less(x, y) == less(x, y)
95-
// Irreflexive: !less(x, x)
96-
// Transitive: if !less(x, y) and !less(y, z), then !less(x, z)
97-
// Total: if x != y, then either less(x, y) or less(y, x)
94+
// - Deterministic: less(x, y) == less(x, y)
95+
// - Irreflexive: !less(x, x)
96+
// - Transitive: if !less(x, y) and !less(y, z), then !less(x, z)
97+
// - Total: if x != y, then either less(x, y) or less(y, x)
9898
//
9999
// SortMaps can be used in conjunction with EquateEmpty.
100100
func SortMaps(lessFunc interface{}) cmp.Option {

cmp/cmpopts/struct_filter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ func (sf structFilter) filter(p cmp.Path) bool {
6767
// fieldTree represents a set of dot-separated identifiers.
6868
//
6969
// For example, inserting the following selectors:
70+
//
7071
// Foo
7172
// Foo.Bar.Baz
7273
// Foo.Buzz
7374
// Nuka.Cola.Quantum
7475
//
7576
// Results in a tree of the form:
77+
//
7678
// {sub: {
7779
// "Foo": {ok: true, sub: {
7880
// "Bar": {sub: {

cmp/cmpopts/xform.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func (xf xformFilter) filter(p cmp.Path) bool {
2323
// that the transformer cannot be recursively applied upon its own output.
2424
//
2525
// An example use case is a transformer that splits a string by lines:
26+
//
2627
// AcyclicTransformer("SplitLines", func(s string) []string{
2728
// return strings.Split(s, "\n")
2829
// })

cmp/compare.go

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
//
1414
// The primary features of cmp are:
1515
//
16-
// When the default behavior of equality does not suit the needs of the test,
17-
// custom equality functions can override the equality operation.
18-
// For example, an equality function may report floats as equal so long as they
19-
// are within some tolerance of each other.
16+
// - When the default behavior of equality does not suit the test's needs,
17+
// custom equality functions can override the equality operation.
18+
// For example, an equality function may report floats as equal so long as
19+
// they are within some tolerance of each other.
2020
//
21-
// • Types that have an Equal method may use that method to determine equality.
22-
// This allows package authors to determine the equality operation for the types
23-
// that they define.
21+
// - Types with an Equal method may use that method to determine equality.
22+
// This allows package authors to determine the equality operation
23+
// for the types that they define.
2424
//
25-
// If no custom equality functions are used and no Equal method is defined,
26-
// equality is determined by recursively comparing the primitive kinds on both
27-
// values, much like reflect.DeepEqual. Unlike reflect.DeepEqual, unexported
28-
// fields are not compared by default; they result in panics unless suppressed
29-
// by using an Ignore option (see cmpopts.IgnoreUnexported) or explicitly
30-
// compared using the Exporter option.
25+
// - If no custom equality functions are used and no Equal method is defined,
26+
// equality is determined by recursively comparing the primitive kinds on
27+
// both values, much like reflect.DeepEqual. Unlike reflect.DeepEqual,
28+
// unexported fields are not compared by default; they result in panics
29+
// unless suppressed by using an Ignore option (see cmpopts.IgnoreUnexported)
30+
// or explicitly compared using the Exporter option.
3131
package cmp
3232

3333
import (
@@ -45,25 +45,25 @@ import (
4545
// Equal reports whether x and y are equal by recursively applying the
4646
// following rules in the given order to x and y and all of their sub-values:
4747
//
48-
// Let S be the set of all Ignore, Transformer, and Comparer options that
49-
// remain after applying all path filters, value filters, and type filters.
50-
// If at least one Ignore exists in S, then the comparison is ignored.
51-
// If the number of Transformer and Comparer options in S is greater than one,
52-
// then Equal panics because it is ambiguous which option to use.
53-
// If S contains a single Transformer, then use that to transform the current
54-
// values and recursively call Equal on the output values.
55-
// If S contains a single Comparer, then use that to compare the current values.
56-
// Otherwise, evaluation proceeds to the next rule.
48+
// - Let S be the set of all Ignore, Transformer, and Comparer options that
49+
// remain after applying all path filters, value filters, and type filters.
50+
// If at least one Ignore exists in S, then the comparison is ignored.
51+
// If the number of Transformer and Comparer options in S is non-zero,
52+
// then Equal panics because it is ambiguous which option to use.
53+
// If S contains a single Transformer, then use that to transform
54+
// the current values and recursively call Equal on the output values.
55+
// If S contains a single Comparer, then use that to compare the current values.
56+
// Otherwise, evaluation proceeds to the next rule.
5757
//
58-
// If the values have an Equal method of the form "(T) Equal(T) bool" or
59-
// "(T) Equal(I) bool" where T is assignable to I, then use the result of
60-
// x.Equal(y) even if x or y is nil. Otherwise, no such method exists and
61-
// evaluation proceeds to the next rule.
58+
// - If the values have an Equal method of the form "(T) Equal(T) bool" or
59+
// "(T) Equal(I) bool" where T is assignable to I, then use the result of
60+
// x.Equal(y) even if x or y is nil. Otherwise, no such method exists and
61+
// evaluation proceeds to the next rule.
6262
//
63-
// Lastly, try to compare x and y based on their basic kinds.
64-
// Simple kinds like booleans, integers, floats, complex numbers, strings, and
65-
// channels are compared using the equivalent of the == operator in Go.
66-
// Functions are only equal if they are both nil, otherwise they are unequal.
63+
// - Lastly, try to compare x and y based on their basic kinds.
64+
// Simple kinds like booleans, integers, floats, complex numbers, strings,
65+
// and channels are compared using the equivalent of the == operator in Go.
66+
// Functions are only equal if they are both nil, otherwise they are unequal.
6767
//
6868
// Structs are equal if recursively calling Equal on all fields report equal.
6969
// If a struct contains unexported fields, Equal panics unless an Ignore option
@@ -639,7 +639,9 @@ type dynChecker struct{ curr, next int }
639639
// Next increments the state and reports whether a check should be performed.
640640
//
641641
// Checks occur every Nth function call, where N is a triangular number:
642+
//
642643
// 0 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 ...
644+
//
643645
// See https://en.wikipedia.org/wiki/Triangular_number
644646
//
645647
// This sequence ensures that the cost of checks drops significantly as

cmp/compare_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var update = flag.Bool("update", false, "update golden test files")
4343
const goldenHeaderPrefix = "<<< "
4444
const goldenFooterPrefix = ">>> "
4545

46-
/// mustParseGolden parses a file as a set of key-value pairs.
46+
// mustParseGolden parses a file as a set of key-value pairs.
4747
//
4848
// The syntax is simple and looks something like:
4949
//

cmp/internal/diff/diff.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ var randBool = rand.New(rand.NewSource(time.Now().Unix())).Intn(2) == 0
127127
// This function returns an edit-script, which is a sequence of operations
128128
// needed to convert one list into the other. The following invariants for
129129
// the edit-script are maintained:
130-
// eq == (es.Dist()==0)
131-
// nx == es.LenX()
132-
// ny == es.LenY()
130+
// - eq == (es.Dist()==0)
131+
// - nx == es.LenX()
132+
// - ny == es.LenY()
133133
//
134134
// This algorithm is not guaranteed to be an optimal solution (i.e., one that
135135
// produces an edit-script with a minimal Levenshtein distance). This algorithm
@@ -169,12 +169,13 @@ func Difference(nx, ny int, f EqualFunc) (es EditScript) {
169169
// A diagonal edge is equivalent to a matching symbol between both X and Y.
170170

171171
// Invariants:
172-
// 0 ≤ fwdPath.X ≤ (fwdFrontier.X, revFrontier.X) ≤ revPath.X ≤ nx
173-
// 0 ≤ fwdPath.Y ≤ (fwdFrontier.Y, revFrontier.Y) ≤ revPath.Y ≤ ny
172+
// - 0 ≤ fwdPath.X ≤ (fwdFrontier.X, revFrontier.X) ≤ revPath.X ≤ nx
173+
// - 0 ≤ fwdPath.Y ≤ (fwdFrontier.Y, revFrontier.Y) ≤ revPath.Y ≤ ny
174174
//
175175
// In general:
176-
// • fwdFrontier.X < revFrontier.X
177-
// • fwdFrontier.Y < revFrontier.Y
176+
// - fwdFrontier.X < revFrontier.X
177+
// - fwdFrontier.Y < revFrontier.Y
178+
//
178179
// Unless, it is time for the algorithm to terminate.
179180
fwdPath := path{+1, point{0, 0}, make(EditScript, 0, (nx+ny)/2)}
180181
revPath := path{-1, point{nx, ny}, make(EditScript, 0)}
@@ -195,19 +196,21 @@ func Difference(nx, ny int, f EqualFunc) (es EditScript) {
195196
// computing sub-optimal edit-scripts between two lists.
196197
//
197198
// The algorithm is approximately as follows:
198-
// • Searching for differences switches back-and-forth between
199-
// a search that starts at the beginning (the top-left corner), and
200-
// a search that starts at the end (the bottom-right corner). The goal of
201-
// the search is connect with the search from the opposite corner.
202-
// • As we search, we build a path in a greedy manner, where the first
203-
// match seen is added to the path (this is sub-optimal, but provides a
204-
// decent result in practice). When matches are found, we try the next pair
205-
// of symbols in the lists and follow all matches as far as possible.
206-
// • When searching for matches, we search along a diagonal going through
207-
// through the "frontier" point. If no matches are found, we advance the
208-
// frontier towards the opposite corner.
209-
// • This algorithm terminates when either the X coordinates or the
210-
// Y coordinates of the forward and reverse frontier points ever intersect.
199+
// - Searching for differences switches back-and-forth between
200+
// a search that starts at the beginning (the top-left corner), and
201+
// a search that starts at the end (the bottom-right corner).
202+
// The goal of the search is connect with the search
203+
// from the opposite corner.
204+
// - As we search, we build a path in a greedy manner,
205+
// where the first match seen is added to the path (this is sub-optimal,
206+
// but provides a decent result in practice). When matches are found,
207+
// we try the next pair of symbols in the lists and follow all matches
208+
// as far as possible.
209+
// - When searching for matches, we search along a diagonal going through
210+
// through the "frontier" point. If no matches are found,
211+
// we advance the frontier towards the opposite corner.
212+
// - This algorithm terminates when either the X coordinates or the
213+
// Y coordinates of the forward and reverse frontier points ever intersect.
211214

212215
// This algorithm is correct even if searching only in the forward direction
213216
// or in the reverse direction. We do both because it is commonly observed
@@ -389,6 +392,7 @@ type point struct{ X, Y int }
389392
func (p *point) add(dx, dy int) { p.X += dx; p.Y += dy }
390393

391394
// zigzag maps a consecutive sequence of integers to a zig-zag sequence.
395+
//
392396
// [0 1 2 3 4 5 ...] => [0 -1 +1 -2 +2 ...]
393397
func zigzag(x int) int {
394398
if x&1 != 0 {

cmp/options.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Option interface {
3333
}
3434

3535
// applicableOption represents the following types:
36+
//
3637
// Fundamental: ignore | validator | *comparer | *transformer
3738
// Grouping: Options
3839
type applicableOption interface {
@@ -43,6 +44,7 @@ type applicableOption interface {
4344
}
4445

4546
// coreOption represents the following types:
47+
//
4648
// Fundamental: ignore | validator | *comparer | *transformer
4749
// Filters: *pathFilter | *valuesFilter
4850
type coreOption interface {
@@ -336,9 +338,9 @@ func (tr transformer) String() string {
336338
// both implement T.
337339
//
338340
// The equality function must be:
339-
// Symmetric: equal(x, y) == equal(y, x)
340-
// Deterministic: equal(x, y) == equal(x, y)
341-
// Pure: equal(x, y) does not modify x or y
341+
// - Symmetric: equal(x, y) == equal(y, x)
342+
// - Deterministic: equal(x, y) == equal(x, y)
343+
// - Pure: equal(x, y) does not modify x or y
342344
func Comparer(f interface{}) Option {
343345
v := reflect.ValueOf(f)
344346
if !function.IsType(v.Type(), function.Equal) || v.IsNil() {

cmp/path.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ type PathStep interface {
4141
// The type of each valid value is guaranteed to be identical to Type.
4242
//
4343
// In some cases, one or both may be invalid or have restrictions:
44-
// For StructField, both are not interface-able if the current field
45-
// is unexported and the struct type is not explicitly permitted by
46-
// an Exporter to traverse unexported fields.
47-
// For SliceIndex, one may be invalid if an element is missing from
48-
// either the x or y slice.
49-
// For MapIndex, one may be invalid if an entry is missing from
50-
// either the x or y map.
44+
// - For StructField, both are not interface-able if the current field
45+
// is unexported and the struct type is not explicitly permitted by
46+
// an Exporter to traverse unexported fields.
47+
// - For SliceIndex, one may be invalid if an element is missing from
48+
// either the x or y slice.
49+
// - For MapIndex, one may be invalid if an entry is missing from
50+
// either the x or y map.
5151
//
5252
// The provided values must not be mutated.
5353
Values() (vx, vy reflect.Value)
@@ -94,6 +94,7 @@ func (pa Path) Index(i int) PathStep {
9494
// The simplified path only contains struct field accesses.
9595
//
9696
// For example:
97+
//
9798
// MyMap.MySlices.MyField
9899
func (pa Path) String() string {
99100
var ss []string
@@ -108,6 +109,7 @@ func (pa Path) String() string {
108109
// GoString returns the path to a specific node using Go syntax.
109110
//
110111
// For example:
112+
//
111113
// (*root.MyMap["key"].(*mypkg.MyStruct).MySlices)[2][3].MyField
112114
func (pa Path) GoString() string {
113115
var ssPre, ssPost []string

cmp/report_slices.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ func (opts formatOptions) FormatDiffSlice(v *valueNode) textNode {
171171
// differences in a string literal. This format is more readable,
172172
// but has edge-cases where differences are visually indistinguishable.
173173
// This format is avoided under the following conditions:
174-
// A line starts with `"""`
175-
// A line starts with "..."
176-
// A line contains non-printable characters
177-
// Adjacent different lines differ only by whitespace
174+
// - A line starts with `"""`
175+
// - A line starts with "..."
176+
// - A line contains non-printable characters
177+
// - Adjacent different lines differ only by whitespace
178178
//
179179
// For example:
180+
//
180181
// """
181182
// ... // 3 identical lines
182183
// foo
@@ -446,7 +447,6 @@ func (opts formatOptions) formatDiffSlice(
446447
// {NumIdentical: 3},
447448
// {NumInserted: 1},
448449
// ]
449-
//
450450
func coalesceAdjacentEdits(name string, es diff.EditScript) (groups []diffStats) {
451451
var prevMode byte
452452
lastStats := func(mode byte) *diffStats {
@@ -503,7 +503,6 @@ func coalesceAdjacentEdits(name string, es diff.EditScript) (groups []diffStats)
503503
// {NumIdentical: 8, NumRemoved: 12, NumInserted: 3},
504504
// {NumIdentical: 63},
505505
// ]
506-
//
507506
func coalesceInterveningIdentical(groups []diffStats, windowSize int) []diffStats {
508507
groups, groupsOrig := groups[:0], groups
509508
for i, ds := range groupsOrig {
@@ -548,7 +547,6 @@ func coalesceInterveningIdentical(groups []diffStats, windowSize int) []diffStat
548547
// {NumRemoved: 9},
549548
// {NumIdentical: 64}, // incremented by 10
550549
// ]
551-
//
552550
func cleanupSurroundingIdentical(groups []diffStats, eq func(i, j int) bool) []diffStats {
553551
var ix, iy int // indexes into sequence x and y
554552
for i, ds := range groups {

0 commit comments

Comments
 (0)