forked from ukautz/clif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_test.go
46 lines (41 loc) · 1.28 KB
/
output_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package clif
import (
"bytes"
. "github.com/smartystreets/goconvey/convey"
"strings"
"testing"
)
type testCustomFormatter struct{}
func (this *testCustomFormatter) Format(msg string) string {
return strings.ToUpper(msg)
}
func (this *testCustomFormatter) Escape(msg string) string {
return msg
}
func TestOutput(t *testing.T) {
Convey("Default output rendering", t, func() {
b := bytes.NewBuffer(nil)
o := NewMonochromeOutput(b)
o.Printf("With <headline>formatted<reset> input")
So(b.String(), ShouldEqual, "With formatted input")
})
Convey("Fancy output rendering", t, func() {
b := bytes.NewBuffer(nil)
o := NewColorOutput(b)
o.Printf("With <headline>formatted<reset> input")
So(b.String(), ShouldEqual, "With \033[4;1mformatted\033[0m input")
})
Convey("Custom output rendering", t, func() {
b := bytes.NewBuffer(nil)
o := NewOutput(b, &testCustomFormatter{})
o.Printf("With <headline>formatted<reset> input")
So(b.String(), ShouldEqual, "WITH <HEADLINE>FORMATTED<RESET> INPUT")
})
Convey("Switching formatter later on", t, func() {
b := bytes.NewBuffer(nil)
o := NewMonochromeOutput(b)
o.SetFormatter(&testCustomFormatter{})
o.Printf("With <headline>formatted<reset> input")
So(b.String(), ShouldEqual, "WITH <HEADLINE>FORMATTED<RESET> INPUT")
})
}