Skip to content

Commit

Permalink
fix: improve some edge diffing cases (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis authored Jun 13, 2023
1 parent 1c1786c commit 730d0c8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
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

0 comments on commit 730d0c8

Please sign in to comment.