Comments (7)
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.
It seems that what you're asking for is a programmatic way to interpret the diff. Is that correct?
from go-cmp.
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.
This would be really nice for structured logging of diffs as well.
from go-cmp.
@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.
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.
Fixed by #123.
from go-cmp.
Related Issues (20)
- Diff is extremely slow HOT 3
- How to ignore specific field by name? HOT 1
- Ideas for a v2 HOT 3
- Default support for the `netip` package HOT 1
- New minor release of the library? HOT 4
- cmp.Diff() switching from property diffs to "new object" diff when object changes significantly HOT 1
- Inconsistent whitespace produced by cmp.Diff HOT 2
- cmpopts: add EquateUnsetFields(want) or FilterFieldsFrom(want) HOT 1
- IgnoreFields and nested struct HOT 2
- Enable a dependency update tool HOT 2
- Package Name Mismatches HOT 4
- unhelpful output for difference in slices HOT 1
- How to implement jests.js's `expect.any(String)` like functionality? HOT 1
- cmpopts.IgnoreFields does not work on structs with an Equal method HOT 1
- Performance Issue Comparing Array Types HOT 1
- Naming clash for new cmp standard package HOT 4
- Comparing two fields with diffirent types that are semantically equivalent HOT 3
- String diff for UUIDs can use strings.Join syntax which makes it more confusing HOT 4
- Reporter truncating important context on diff output but leaving others alone
- How to add more context to Diff output?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-cmp.