Skip to content

Commit

Permalink
fix: add return to write methods to allow chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
matty-rose committed Oct 10, 2021
1 parent 5724030 commit a1d44d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/formatter/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ func (m MarkdownDocument) Render() string {
return m.builder.String()
}

func (m *MarkdownDocument) WriteText(text string) {
func (m *MarkdownDocument) WriteText(text string) *MarkdownDocument {
m.builder.WriteString(text)
return m
}

func (m *MarkdownDocument) WriteNewLine() {
func (m *MarkdownDocument) WriteNewLine() *MarkdownDocument {
m.WriteText("\n")
return m
}

type MarkdownHeadingLevel int
Expand All @@ -62,8 +64,10 @@ const (
H6
)

func (m *MarkdownDocument) WriteHeading(text string, level MarkdownHeadingLevel) {
func (m *MarkdownDocument) WriteHeading(text string, level MarkdownHeadingLevel) *MarkdownDocument {
heading := fmt.Sprintf("%s %s", strings.Repeat("#", int(level)), text)
m.WriteText(heading)
m.WriteNewLine()

return m
}
8 changes: 8 additions & 0 deletions pkg/formatter/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func TestMarkdownWriteText(t *testing.T) {
}
}

func TestMarkdownWriteNewLine(t *testing.T) {
t.Parallel()

doc := formatter.NewMarkdownDocument().WriteNewLine()

assert.Equal(t, "\n", doc.Render())
}

func TestMarkdownWriteHeading(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit a1d44d7

Please sign in to comment.