Skip to content
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

fix: improve some edge diffing cases #66

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linters:

linters-settings:
gocognit:
min-complexity: 40
min-complexity: 45
lll:
line-length: 130
gofumpt:
Expand Down
5 changes: 4 additions & 1 deletion snaps/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func isSingleline(s string) bool {
// shouldPrintHighlights checks if the two strings are going to be presented with
// inline highlights
func shouldPrintHighlights(a, b string) bool {
return !colors.NOCOLOR && a != "\n" && b != "\n" && isSingleline(a) && isSingleline(b)
return !colors.NOCOLOR && a != "" && b != "" && isSingleline(a) && isSingleline(b)
}

// Compare two sequences of lines; generate the delta as a unified diff.
Expand Down Expand Up @@ -84,6 +84,9 @@ func getUnifiedDiff(a, b string) (string, int, int) {

if c.Tag == difflib.OpEqual {
for _, line := range aLines[i1:i2] {
if line == "\n" {
line = newLineSymbol + "\n"
}
colors.FprintEqual(&s, line)
}

Expand Down
4 changes: 2 additions & 2 deletions snaps/matchSnapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestMatchSnapshot(t *testing.T) {
expected := "\n\x1b[38;5;52m\x1b[48;5;225m- Snapshot - 2\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ Received + 2\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" +
"- hello world\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ bye world\x1b[0m\n \x1b[2m\n\x1b[0m"
"+ bye world\x1b[0m\n \x1b[2m\n\x1b[0m"

test.Equal(t, expected, args[0])
},
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestMatchSnapshot(t *testing.T) {
"+ Received + 3\x1b[0m\n\n\x1b[38;5;52m\x1b[48;5;225m- int(10)\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m" +
"- hello world----\x1b[0m\n\x1b[38;5;52m\x1b[48;5;225m- ---\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ int(100)\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m+ bye world----\x1b[0m\n\x1b[38;5;22m\x1b[48;5;159m" +
"+ --\x1b[0m\n \x1b[2m\n\x1b[0m"
"+ --\x1b[0m\n \x1b[2m\n\x1b[0m"

test.Equal(t, expected, args[0])
},
Expand Down
1 change: 1 addition & 0 deletions snaps/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
updateSymbol = "✎ "
skipSymbol = "⟳ "
enterSymbol = "↳ "
newLineSymbol = "↵"

snapsExt = ".snap"
endSequence = "---"
Expand Down