-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String formatting for Path produces empty strings when it shouldn't #305
Comments
PS: I don't know what Transform is (from the snippet), and whether it's necessary |
This is working as intended. Having On the other hand, the Writing your own |
The value.TypeString function is what the rest of the package uses and is slightly cleaner than using reflect.Type.String. Updates #305
I agree, about the documentation. I glazed over it. Please consider this as a feature request in that case. To me it's a bit incoherent that the library will happily compare and successfully find differences inside nested native collections but won't report them properly. |
Given that
The |
I was thinking more of changing the implementation of |
Closing as "working as intended". |
The value.TypeString function is what the rest of the package uses and is slightly cleaner than using reflect.Type.String. Updates #305
The value.TypeString function is what the rest of the package uses and is slightly cleaner than using reflect.Type.String. Updates #305 Co-authored-by: Damien Neil <[email protected]>
I have a use case where I compare very nested protobuf code generated structures. The behaviour is that if a structure has an Equals() method, the library stops recursing. To bypass that I convert the protobuf structures to json and back into very very nested map[string]interface{}`s. When I report a particular Diff I would like it to appear with a key -
rootType.Level1Field.Level2Field.Level3Field.Leaf
or something similar. I cannot do that because the String() implementation does not work with nested maps or slices. I have to resort tofmt.Sprintf("%#v", path)
which for nested code generated structures is very verbose. E.g.root["period"].(map[string]interface {})["endsAt"].(map[string]interface {})["value"].(string)
, this is an actual output for 3 levels of nesting (which isn't that much nesting).https://github.com/google/go-cmp/blob/master/cmp/path.go#L93
There's a type assertion that only allows struct field accesses, for a reason unknown to me. If that's necessary at the very least the documentation is misleading because it suggests that it works on maps and slices -
// MyMap.MySlices.MyField
The way I bypassed this is by implementing a custom stringer func
Ideally I shouldn't resort to that and I would like it to just work as described in the doc string.
The text was updated successfully, but these errors were encountered: