MCPcopy
hub / github.com/google/go-cmp / formatDiffList

Method formatDiffList

cmp/report_compare.go:204–405  ·  view source on GitHub ↗
(recs []reportRecord, k reflect.Kind, ptrs *pointerReferences)

Source from the content-addressed store, hash-verified

202}
203
204func (opts formatOptions) formatDiffList(recs []reportRecord, k reflect.Kind, ptrs *pointerReferences) textNode {
205 // Derive record name based on the data structure kind.
206 var name string
207 var formatKey func(reflect.Value) string
208 switch k {
209 case reflect.Struct:
210 name = "field"
211 opts = opts.WithTypeMode(autoType)
212 formatKey = func(v reflect.Value) string { return v.String() }
213 case reflect.Slice, reflect.Array:
214 name = "element"
215 opts = opts.WithTypeMode(elideType)
216 formatKey = func(reflect.Value) string { return "" }
217 case reflect.Map:
218 name = "entry"
219 opts = opts.WithTypeMode(elideType)
220 formatKey = func(v reflect.Value) string { return formatMapKey(v, false, ptrs) }
221 }
222
223 maxLen := -1
224 if opts.LimitVerbosity {
225 if opts.DiffMode == diffIdentical {
226 maxLen = ((1 << opts.verbosity()) >> 1) << 2 // 0, 4, 8, 16, 32, etc...
227 } else {
228 maxLen = (1 << opts.verbosity()) << 1 // 2, 4, 8, 16, 32, 64, etc...
229 }
230 opts.VerbosityLevel--
231 }
232
233 // Handle unification.
234 switch opts.DiffMode {
235 case diffIdentical, diffRemoved, diffInserted:
236 var list textList
237 var deferredEllipsis bool // Add final "..." to indicate records were dropped
238 for _, r := range recs {
239 if len(list) == maxLen {
240 deferredEllipsis = true
241 break
242 }
243
244 // Elide struct fields that are zero value.
245 if k == reflect.Struct {
246 var isZero bool
247 switch opts.DiffMode {
248 case diffIdentical:
249 isZero = r.Value.ValueX.IsZero() || r.Value.ValueY.IsZero()
250 case diffRemoved:
251 isZero = r.Value.ValueX.IsZero()
252 case diffInserted:
253 isZero = r.Value.ValueY.IsZero()
254 }
255 if isZero {
256 continue
257 }
258 }
259 // Elide ignored nodes.
260 if r.Value.NumIgnored > 0 && r.Value.NumSame+r.Value.NumDiff == 0 {
261 deferredEllipsis = !(k == reflect.Slice || k == reflect.Array)

Callers 1

FormatDiffMethod · 0.95

Calls 15

WithTypeModeMethod · 0.95
verbosityMethod · 0.95
IsZeroMethod · 0.95
AppendEllipsisMethod · 0.95
FormatDiffMethod · 0.95
AppendMethod · 0.95
WithDiffModeMethod · 0.95
CanFormatDiffSliceMethod · 0.95
FormatDiffSliceMethod · 0.95
formatMapKeyFunction · 0.85
coalesceAdjacentRecordsFunction · 0.85
verbosityPresetFunction · 0.85

Tested by

no test coverage detected