Skip to content

RowFormat formatter appends \tmessage in Tab separated format #69

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions cmd/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (f *Formatter) rowMark(diff digest.Differences) error {
_, _ = fmt.Fprintf(f.stderr, "Rows:\n")

includes := f.ctx.GetIncludeColumnPositions()
separator := f.ctx.separator

additions := make([]string, 0, len(diff.Additions))
for _, addition := range diff.Additions {
Expand All @@ -172,15 +173,15 @@ func (f *Formatter) rowMark(diff digest.Differences) error {
}

for _, added := range additions {
_, _ = fmt.Fprintf(f.stdout, "%s,%s\n", added, "ADDED")
_, _ = fmt.Fprintf(f.stdout, "%s%s%s\n", added, string(separator), "ADDED")
}

for _, modified := range modifications {
_, _ = fmt.Fprintf(f.stdout, "%s,%s\n", modified, "MODIFIED")
_, _ = fmt.Fprintf(f.stdout, "%s%s%s\n", modified, string(separator), "MODIFIED")
}

for _, deleted := range deletions {
_, _ = fmt.Fprintf(f.stdout, "%s,%s\n", deleted, "DELETED")
_, _ = fmt.Fprintf(f.stdout, "%s%s%s\n", deleted, string(separator), "DELETED")
}

return nil
Expand Down
28 changes: 28 additions & 0 deletions cmd/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ Rows:
assert.Equal(t, expectedStderr, stderr.String())
}

func TestRowMarkFormatterForTabSeparator(t *testing.T) {
diff := digest.Differences{
Additions: []digest.Addition{[]string{"additions"}},
Modifications: []digest.Modification{{Current: []string{"modification"}}},
Deletions: []digest.Deletion{[]string{"deletions"}},
}
expectedStdout := `additions ADDED
modification MODIFIED
deletions DELETED
`
expectedStderr := `Additions 1
Modifications 1
Deletions 1
Rows:
`

var stdout bytes.Buffer
var stderr bytes.Buffer

formatter := NewFormatter(&stdout, &stderr, Context{format: "rowmark", separator: '\t'})

err := formatter.Format(diff)

assert.NoError(t, err)
assert.Equal(t, expectedStdout, stdout.String())
assert.Equal(t, expectedStderr, stderr.String())
}

func TestLineDiff(t *testing.T) {
t.Run("should show line diff with comma by default", func(t *testing.T) {
diff := digest.Differences{
Expand Down