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

Method Begin

cmp/internal/diff/debug_enable.go:72–98  ·  view source on GitHub ↗
(nx, ny int, f EqualFunc, p1, p2 *EditScript)

Source from the content-addressed store, hash-verified

70}
71
72func (dbg *debugger) Begin(nx, ny int, f EqualFunc, p1, p2 *EditScript) EqualFunc {
73 dbg.Lock()
74 dbg.fwdPath, dbg.revPath = p1, p2
75 top := "┌─" + strings.Repeat("──", nx) + "┐\n"
76 row := "│ " + strings.Repeat("· ", nx) + "│\n"
77 btm := "└─" + strings.Repeat("──", nx) + "┘\n"
78 dbg.grid = []byte(top + strings.Repeat(row, ny) + btm)
79 dbg.lines = strings.Count(dbg.String(), "\n")
80 fmt.Print(dbg)
81
82 // Wrap the EqualFunc so that we can intercept each result.
83 return func(ix, iy int) (r Result) {
84 cell := dbg.grid[len(top)+iy*len(row):][len("│ ")+len("· ")*ix:][:len("·")]
85 for i := range cell {
86 cell[i] = 0 // Zero out the multiple bytes of UTF-8 middle-dot
87 }
88 switch r = f(ix, iy); {
89 case r.Equal():
90 cell[0] = '\\'
91 case r.Similar():
92 cell[0] = 'X'
93 default:
94 cell[0] = '#'
95 }
96 return
97 }
98}
99
100func (dbg *debugger) Update() {
101 dbg.print(updateDelay)

Callers 1

DifferenceFunction · 0.45

Calls 3

StringMethod · 0.95
SimilarMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected