Skip to content

Commit

Permalink
Refactor bytes_diff_visualizer.go and bytes_diff_visualizer_test.go
Browse files Browse the repository at this point in the history
The commit message should be concise and describe the changes made in the code. Here's a possible commit message under 80 characters:

"Refactor bytes_diff_visualizer.go and bytes_diff_visualizer_test.go
  • Loading branch information
rohitpaulk committed Oct 2, 2023
1 parent 1646c4a commit 72db75b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion bytes_diff_visualizer/bytes_diff_visualizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func VisualizeByteDiff(actual []byte, expected []byte) []string {

tabWriter.Flush()

return strings.Split(string(linesBuffer.Bytes()), "\n")
output := string(linesBuffer.Bytes())
if output[len(output)-1] == '\n' {
output = output[:len(output)-1]
}
return strings.Split(output, "\n")
}

func formatBytesAsAscii(value []byte) string {
Expand Down
10 changes: 6 additions & 4 deletions bytes_diff_visualizer/bytes_diff_visualizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func TestVisualizeByteDiffWorksWithStrings(t *testing.T) {
t.FailNow()
}
}

assert.Equal(t, len(expectedLines), len(result))
}

func TestVisualizeByteDiffWorksWithNonPrintableCharacters(t *testing.T) {
Expand All @@ -41,10 +43,6 @@ func TestVisualizeByteDiffWorksWithNonPrintableCharacters(t *testing.T) {

result := VisualizeByteDiff(actual, expected)

if len(result) == 0 {
t.Errorf("Expected a non-empty result")
}

expectedLines := []string{
"Expected (bytes 0-12), hexadecimal: | ASCII:",
"62 6c 6f 62 00 00 68 65 61 64 65 72 | blob..header",
Expand All @@ -62,6 +60,8 @@ func TestVisualizeByteDiffWorksWithNonPrintableCharacters(t *testing.T) {
t.FailNow()
}
}

assert.Equal(t, len(expectedLines), len(result))
}

func TestVisualizeByteDiffWorksWithLongerSequences(t *testing.T) {
Expand Down Expand Up @@ -93,4 +93,6 @@ func TestVisualizeByteDiffWorksWithLongerSequences(t *testing.T) {
t.FailNow()
}
}

assert.Equal(t, len(expectedLines), len(result))
}

0 comments on commit 72db75b

Please sign in to comment.