1 // Copyright 2017, 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.
7 // defaultReporter implements the reporter interface.
9 // As Equal serially calls the PushStep, Report, and PopStep methods, the
10 // defaultReporter constructs a tree-based representation of the compared value
11 // and the result of each comparison (see valueNode).
13 // When the String method is called, the FormatDiff method transforms the
14 // valueNode tree into a textNode tree, which is a tree-based representation
15 // of the textual output (see textNode).
17 // Lastly, the textNode.String method produces the final report as a string.
18 type defaultReporter struct {
23 func (r *defaultReporter) PushStep(ps PathStep) {
24 r.curr = r.curr.PushStep(ps)
29 func (r *defaultReporter) Report(rs Result) {
32 func (r *defaultReporter) PopStep() {
33 r.curr = r.curr.PopStep()
36 // String provides a full report of the differences detected as a structured
37 // literal in pseudo-Go syntax. String may only be called after the entire tree
38 // has been traversed.
39 func (r *defaultReporter) String() string {
40 assert(r.root != nil && r.curr == nil)
41 if r.root.NumDiff == 0 {
44 ptrs := new(pointerReferences)
45 text := formatOptions{}.FormatDiff(r.root, ptrs)
46 resolveReferences(text)
50 func assert(ok bool) {
52 panic("assertion failure")