-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
Description
I've been working with a test apparatus for comparing JSON data. For ease-of-use and readability, I'd like to be able to compare prettified/indented JSON strings and print the differences in an easy-to-read way.
I've found that the cmp.Diff
output can be quite varied even on similar inputs and can be either easy-to-read, somewhat hard to read, or hard to read and confusing depending on the exact input for non-obvious reasons.
See https://play.golang.org/p/mu-TsXoGEEL (pasted below):
Code:
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
)
func main() {
fmt.Printf("Confusing diff output:\n%s\n", cmp.Diff(`{
"id": 1,
"with_package_maps": true,
"with_other_maps": true
}`, `{
"id": 1434180,
"with_package_maps": true,
"with_other_maps": true
}`))
fmt.Printf("Non-confusing, but somewhat hard to find differences diff output:\n%s\n", cmp.Diff(`{
"id": 1,
"foo": true,
"bar": true,
}`, `{
"id": 1434180,
"foo": true,
"bar": true,
}`))
fmt.Printf("Non-confusing, easy to read and find differences diff output:\n%s\n", cmp.Diff(`
{
"id": 1,
"with_package_maps": true,
"with_other_maps": true
}`, `
{
"id": 1434180,
"with_package_maps": true,
"with_other_maps": true
}`))
}
Output:
Confusing diff output:
strings.Join({
"{\n \"id\": 1",
+ "434180",
",\n \"with_package_maps\": true,\n \"with_other_maps\": true\n}",
}, "")
Non-confusing, easy to read and find differences diff output:
(
"""
{
- "id": 1,
+ "id": 1434180,
"with_package_maps": true,
"with_other_maps": true
}
"""
)
Non-confusing, but somewhat harder to find differences diff output:
string(
- "{\n \"id\": 1,\n \"foo\": true,\n \"bar\": true,\n}",
+ "{\n \"id\": 1434180,\n \"foo\": true,\n \"bar\": true,\n}",
)
Metadata
Metadata
Assignees
Labels
No labels