Skip to content

Commit

Permalink
Add tests for CustomTable function
Browse files Browse the repository at this point in the history
  • Loading branch information
varmakarthik12 committed Feb 2, 2024
1 parent dd8ebfc commit 64326cb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,44 @@ func TestMarkdownError(t *testing.T) {
t.Error("expected error, but not occurred")
}
})

t.Run("Error() return error Custom Table", func(t *testing.T) {
t.Parallel()

m := NewMarkdown(os.Stdout)
m.CustomTable(TableSet{
Header: []string{"Name", "Age"},
Rows: [][]string{{"David"}},
}, TableOptions{
AutoWrapText: false,
})
if err := m.Error(); err == nil {
t.Error("expected error, but not occurred")
}
})
}

func TestMarkdownCustomTable(t *testing.T) {
t.Parallel()
t.Run("success Table()", func(t *testing.T) {
t.Parallel()

m := NewMarkdown(os.Stdout)
set := TableSet{
Header: []string{"Name", "Age"},
Rows: [][]string{{"David", "23"}},
}
m.CustomTable(set, TableOptions{
AutoWrapText: false,
})
want := []string{
fmt.Sprintf("| NAME | AGE |%s|-------|-----|%s| David | 23 |%s",
lineFeed(), lineFeed(), lineFeed()),
}
got := m.body

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("value is mismatch (-want +got):\n%s", diff)
}
})
}

0 comments on commit 64326cb

Please sign in to comment.