...
1 package text
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/stretchr/testify/assert"
8 )
9
10 func ExampleFormat_Apply() {
11 fmt.Printf("FormatDefault: %#v\n", FormatDefault.Apply("jon Snow"))
12 fmt.Printf("FormatLower : %#v\n", FormatLower.Apply("jon Snow"))
13 fmt.Printf("FormatTitle : %#v\n", FormatTitle.Apply("jon Snow"))
14 fmt.Printf("FormatUpper : %#v\n", FormatUpper.Apply("jon Snow"))
15 fmt.Println()
16 fmt.Printf("FormatDefault (w/EscSeq): %#v\n", FormatDefault.Apply(Bold.Sprint("jon Snow")))
17 fmt.Printf("FormatLower (w/EscSeq): %#v\n", FormatLower.Apply(Bold.Sprint("jon Snow")))
18 fmt.Printf("FormatTitle (w/EscSeq): %#v\n", FormatTitle.Apply(Bold.Sprint("jon Snow")))
19 fmt.Printf("FormatUpper (w/EscSeq): %#v\n", FormatUpper.Apply(Bold.Sprint("jon Snow")))
20
21
22
23
24
25
26
27
28
29
30 }
31
32 func TestFormat_Apply(t *testing.T) {
33 text := "A big croc0dile; Died - Empty_fanged ツ \u2008."
34 assert.Equal(t, text, FormatDefault.Apply(text))
35 assert.Equal(t, "a big croc0dile; died - empty_fanged ツ \u2008.", FormatLower.Apply(text))
36 assert.Equal(t, "A Big Croc0dile; Died - Empty_fanged ツ \u2008.", FormatTitle.Apply(text))
37 assert.Equal(t, "A BIG CROC0DILE; DIED - EMPTY_FANGED ツ \u2008.", FormatUpper.Apply(text))
38
39
40 text = Colors{Bold}.Sprint(text)
41 assert.Equal(t, "\x1b[1mA big croc0dile; Died - Empty_fanged ツ \u2008.\x1b[0m", FormatDefault.Apply(text))
42 assert.Equal(t, "\x1b[1ma big croc0dile; died - empty_fanged ツ \u2008.\x1b[0m", FormatLower.Apply(text))
43 assert.Equal(t, "\x1b[1mA Big Croc0dile; Died - Empty_fanged ツ \u2008.\x1b[0m", FormatTitle.Apply(text))
44 assert.Equal(t, "\x1b[1mA BIG CROC0DILE; DIED - EMPTY_FANGED ツ \u2008.\x1b[0m", FormatUpper.Apply(text))
45 }
46
View as plain text