-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from go-spectest/feat/status-badge
Feat generate status badge
- Loading branch information
Showing
7 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package markdown | ||
|
||
import "fmt" | ||
|
||
// RedBadge return text with red badge format. | ||
func (m *Markdown) RedBadge(text string) *Markdown { | ||
m.body = append(m.body, fmt.Sprintf("![Badge](https://img.shields.io/badge/%s-red)", text)) | ||
return m | ||
} | ||
|
||
// RedBadgef return text with red badge format. | ||
func (m *Markdown) RedBadgef(format string, args ...interface{}) *Markdown { | ||
return m.RedBadge(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
// YellowBadge return text with yellow badge format. | ||
func (m *Markdown) YellowBadge(text string) *Markdown { | ||
m.body = append(m.body, fmt.Sprintf("![Badge](https://img.shields.io/badge/%s-yellow)", text)) | ||
return m | ||
} | ||
|
||
// YellowBadgef return text with yellow badge format. | ||
func (m *Markdown) YellowBadgef(format string, args ...interface{}) *Markdown { | ||
return m.YellowBadge(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
// GreenBadge return text with green badge format. | ||
func (m *Markdown) GreenBadge(text string) *Markdown { | ||
m.body = append(m.body, fmt.Sprintf("![Badge](https://img.shields.io/badge/%s-green)", text)) | ||
return m | ||
} | ||
|
||
// GreenBadgef return text with green badge format. | ||
func (m *Markdown) GreenBadgef(format string, args ...interface{}) *Markdown { | ||
return m.GreenBadge(fmt.Sprintf(format, args...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package markdown | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestMarkdown_RedBadgef(t *testing.T) { | ||
t.Parallel() | ||
t.Run("success RedBadgef()", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
m := NewMarkdown(io.Discard) | ||
m.RedBadgef("%s", "Hello") | ||
want := []string{"![Badge](https://img.shields.io/badge/Hello-red)"} | ||
got := m.body | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("value is mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
|
||
t.Run("success YellowBadgef()", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
m := NewMarkdown(io.Discard) | ||
m.YellowBadgef("%s", "Hello") | ||
want := []string{"![Badge](https://img.shields.io/badge/Hello-yellow)"} | ||
got := m.body | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("value is mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
|
||
t.Run("success GreenBadgef()", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
m := NewMarkdown(io.Discard) | ||
m.GreenBadgef("%s", "Hello") | ||
want := []string{"![Badge](https://img.shields.io/badge/Hello-green)"} | ||
got := m.body | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("value is mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# badge example | ||
![Badge](https://img.shields.io/badge/red_badge-red) | ||
![Badge](https://img.shields.io/badge/yellow_badge-yellow) | ||
![Badge](https://img.shields.io/badge/green_badge-green) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build linux || darwin | ||
|
||
// Package main is generating markdown. | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
md "github.com/go-spectest/markdown" | ||
) | ||
|
||
//go:generate go run main.go | ||
|
||
func main() { | ||
f, err := os.Create("generated.md") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := md.NewMarkdown(f). | ||
H1("badge example"). | ||
RedBadge("red_badge"). | ||
YellowBadge("yellow_badge"). | ||
GreenBadge("green_badge"). | ||
Build(); err != nil { | ||
panic(err) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.