forked from ukautz/clif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter_test.go
59 lines (56 loc) · 1.82 KB
/
formatter_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
47
48
49
50
51
52
53
54
55
56
57
58
59
package clif
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestDefaultFormatterFormat(t *testing.T) {
Convey("Formatting output", t, func() {
Convey("Formatting with stripped directives", func() {
f := NewDefaultFormatter(nil)
s := f.Format("Foo <headline>bar<reset> baz")
So(s, ShouldEqual, "Foo bar baz")
})
Convey("Formatting with formatted directives", func() {
f := NewDefaultFormatter(map[string]string{
"headline": "H!",
"reset": "R!",
})
s := f.Format("Foo <headline>bar<reset> baz")
So(s, ShouldEqual, "Foo H!barR! baz")
})
Convey("Formatting does not replace not registered default tokens", func() {
f := NewDefaultFormatter(nil)
s := f.Format("Foo <headline>bar<reset> <baz> boing")
So(s, ShouldEqual, "Foo bar <baz> boing")
})
Convey("Formatting does not replace not registered custom tokens", func() {
f := NewDefaultFormatter(map[string]string{
"baz": "BAZ",
})
s := f.Format("Foo <headline>bar<reset> <baz> boing")
So(s, ShouldEqual, "Foo <headline>bar<reset> BAZ boing")
})
Convey("Formatting works over multi-line string", func() {
f := NewDefaultFormatter(map[string]string{
"headline": "H!",
"reset": "R!",
})
s := f.Format("Foo <headline>bar baz\ndings<reset> baz")
So(s, ShouldEqual, "Foo H!bar baz\ndingsR! baz")
})
})
}
func TestDefaultFormatterEscape(t *testing.T) {
Convey("Escapinng output", t, func() {
Convey("Escaping tokens", func() {
f := NewDefaultFormatter(nil)
s := f.Escape("Foo <headline>bar<reset> baz")
So(s, ShouldEqual, "Foo \\<headline>bar\\<reset> baz")
})
Convey("Escaping already escaped tokens does nothing", func() {
f := NewDefaultFormatter(nil)
s := f.Escape("Foo \\<headline>bar\\<reset> baz")
So(s, ShouldEqual, "Foo \\<headline>bar\\<reset> baz")
})
})
}