-
Notifications
You must be signed in to change notification settings - Fork 210
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
Simplified reporting for string Diff? #195
Comments
You are correct that is the rationale for why. The reporter output prioritizes accurate reporting over readability (though both are important goals).
Philosophically, we're generally adverse to adding lots of options to control how things look. I'd prefer pursuing an approach that (by default) produces output that is never ambiguous, but decently readable. |
I understand the reasoning. It just means I'll have to use a different tool to get the clean output I want for json/yaml file/string comparison without having to unmarshal them first (which can fail on bad syntax). |
How would something like the following look. For a standalone string: string(
"""
one
- two
+ TWO
three
"""
) For a struct string field: Foo{
StringField: string(
"""
... // 23 identical lines
zero
one
- two
+ TWO
three
four
... // 534 identical lines
"""
),
IntField: 5,
} For a slice of strings: []string{
"equal single line",
- "inequal single line",
+ "INEQUAL single line",
string(
"""
{
- "accountType": "self",
"name": "account",
"environment": "self",
"providerVersion": "v2",
"type": "kubernetes",
"skin": "v2",
+ "accountType": "self",
"cloudProvider": "kubernetes"
}
"""
),
"equal\nmultiple\nlines",
"another string",
+ "added string",
} Specifics of how it works:
|
I think the triple quotes is a great compromise for this, as long as it's still clear where the indentation starts. Whitespace changes are common when comparing formatted json/yaml for linting. Is the string() wrapper necessary? Won't triple quotes indicate it's unambiguously a string? |
The starting
Not strictly. It was to give some degree of indention to help things read nicer. Consider the []string{
"equal single line",
- "inequal single line",
+ "INEQUAL single line",
"""
{
- "accountType": "self",
"name": "account",
"environment": "self",
"providerVersion": "v2",
"type": "kubernetes",
"skin": "v2",
+ "accountType": "self",
"cloudProvider": "kubernetes"
}
""",
"equal\nmultiple\nlines",
"another string",
+ "added string",
} Visually, it's hard to distinguish between the individual strings that belong to the |
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
See #212. |
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
So, I'm trying to compare two multi-lined strings with
cmp.Diff
and it returns a diff that looks pretty bulky and kind of confusing given the string is not part of another object.Example:
I get that the objectification of strings is there to make it obvious that it's a string inside an object, but is there a way to pass in an option or reporter to Diff so that it has simplified output?
Example:
If this was possible, it would be a boon for comparison of json/yaml strings without having to Unmarshal them first (especially in cases where unmarshalling might fail). It would make Diff more useful for comparing file contents.
The text was updated successfully, but these errors were encountered: