GithubHelp home page GithubHelp logo

Comments (7)

dsnet avatar dsnet commented on August 19, 2024 1

Would API like the following suffice?

// Reporter wraps the provided reporter as an Option. 
func Reporter(interface {
	// PushStep is called when a tree-traversal operation is performed
	// and provides the sub-values of x and y after applying the operation.
	// The PathStep is valid until the step is popped, while the reflect.Values
	// are valid while the entire tree is still being traversed.
	//
	// Equal and Diff always call PushStep at the start to provide an
	// operation-less PathStep used to report the root values.
	PushStep(ps PathStep, x, y reflect.Value)

	// Report is called at exactly once on leaf nodes to report whether the
	// comparison identified the node as equal, unequal, or ignored.
	// A leaf node is one that is immediately preceded by and followed by
	// a pair of PushStep and PopStep calls.
	Report(ReportFlags)

	// PopStep ascends back up the value tree.
	// There is always a matching pop call for every push call.
	PopStep()
}) Option

// ReportFlags is bit-set of reporting information about the comparison.
type ReportFlags uint

const (
	// ReportIgnored reports whether the node was ignored.
	ReportIgnored ReportFlags = iota
	// ReportEqual reports whether the node is equal.
	ReportEqual
	// reportUnequal reports whether the node is not equal.
	ReportUnequal
)

This API allows the user to pass in their own reporter and get a structured representation of the diff. The internal default reporter is being switched to use an API like this.

See report.go for an example of an implementation of this API that only report differences similar to what it does today.

from go-cmp.

dsnet avatar dsnet commented on August 19, 2024

It seems that what you're asking for is a programmatic way to interpret the diff. Is that correct?

from go-cmp.

deinspanjer avatar deinspanjer commented on August 19, 2024

I believe that sounds right. What my code is attempting to return is a set of results containing any adds, removes, or changes as discrete sets so that the consumer of this result object can perform whatever operations are necessary upon the objects that had those changes.

from go-cmp.

nhooyr avatar nhooyr commented on August 19, 2024

This would be really nice for structured logging of diffs as well.

from go-cmp.

SVenky avatar SVenky commented on August 19, 2024

@dsnet : Is this already available? If so do we have an example or test code to refer on how to use it? if not available yet, any timeline of when we can expect the same. Thanks a lot!

from go-cmp.

dsnet avatar dsnet commented on August 19, 2024

It's here at #123. I wanted to seriously think through the implications of the final API before merging, but anticipate that it will happen next week.

See here for an example: https://github.com/google/go-cmp/pull/123/files#diff-723c10615c952a994128a9cf62e6ca49

from go-cmp.

dsnet avatar dsnet commented on August 19, 2024

Fixed by #123.

from go-cmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.