1 package text
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/stretchr/testify/assert"
8 )
9
10 func ExampleVAlign_Apply() {
11 lines := []string{"Game", "Of", "Thrones"}
12 maxLines := 5
13 fmt.Printf("VAlignDefault: %#v\n", VAlignDefault.Apply(lines, maxLines))
14 fmt.Printf("VAlignTop : %#v\n", VAlignTop.Apply(lines, maxLines))
15 fmt.Printf("VAlignMiddle : %#v\n", VAlignMiddle.Apply(lines, maxLines))
16 fmt.Printf("VAlignBottom : %#v\n", VAlignBottom.Apply(lines, maxLines))
17
18
19
20
21
22 }
23
24 func TestVAlign_Apply(t *testing.T) {
25 assert.Equal(t, []string{"Game", "Of", "Thrones"},
26 VAlignDefault.Apply([]string{"Game", "Of", "Thrones"}, 1))
27 assert.Equal(t, []string{"Game", "Of", "Thrones"},
28 VAlignDefault.Apply([]string{"Game", "Of", "Thrones"}, 3))
29 assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
30 VAlignDefault.Apply([]string{"Game", "Of", "Thrones"}, 5))
31
32 assert.Equal(t, []string{"Game", "Of", "Thrones"},
33 VAlignTop.Apply([]string{"Game", "Of", "Thrones"}, 1))
34 assert.Equal(t, []string{"Game", "Of", "Thrones"},
35 VAlignTop.Apply([]string{"Game", "Of", "Thrones"}, 3))
36 assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
37 VAlignTop.Apply([]string{"Game", "Of", "Thrones"}, 5))
38
39 assert.Equal(t, []string{"Game", "Of", "Thrones"},
40 VAlignMiddle.Apply([]string{"Game", "Of", "Thrones"}, 1))
41 assert.Equal(t, []string{"Game", "Of", "Thrones"},
42 VAlignMiddle.Apply([]string{"Game", "Of", "Thrones"}, 3))
43 assert.Equal(t, []string{"", "Game", "Of", "Thrones", ""},
44 VAlignMiddle.Apply([]string{"Game", "Of", "Thrones"}, 5))
45
46 assert.Equal(t, []string{"Game", "Of", "Thrones"},
47 VAlignBottom.Apply([]string{"Game", "Of", "Thrones"}, 1))
48 assert.Equal(t, []string{"Game", "Of", "Thrones"},
49 VAlignBottom.Apply([]string{"Game", "Of", "Thrones"}, 3))
50 assert.Equal(t, []string{"", "", "Game", "Of", "Thrones"},
51 VAlignBottom.Apply([]string{"Game", "Of", "Thrones"}, 5))
52 }
53
54 func ExampleVAlign_ApplyStr() {
55 str := "Game\nOf\nThrones"
56 maxLines := 5
57 fmt.Printf("VAlignDefault: %#v\n", VAlignDefault.ApplyStr(str, maxLines))
58 fmt.Printf("VAlignTop : %#v\n", VAlignTop.ApplyStr(str, maxLines))
59 fmt.Printf("VAlignMiddle : %#v\n", VAlignMiddle.ApplyStr(str, maxLines))
60 fmt.Printf("VAlignBottom : %#v\n", VAlignBottom.ApplyStr(str, maxLines))
61
62
63
64
65
66 }
67
68 func TestVAlign_ApplyStr(t *testing.T) {
69 assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
70 VAlignDefault.ApplyStr("Game\nOf\nThrones", 5))
71 assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
72 VAlignTop.ApplyStr("Game\nOf\nThrones", 5))
73 assert.Equal(t, []string{"", "Game", "Of", "Thrones", ""},
74 VAlignMiddle.ApplyStr("Game\nOf\nThrones", 5))
75 assert.Equal(t, []string{"", "", "Game", "Of", "Thrones"},
76 VAlignBottom.ApplyStr("Game\nOf\nThrones", 5))
77 }
78
79 func ExampleVAlign_HTMLProperty() {
80 fmt.Printf("VAlignDefault: '%s'\n", VAlignDefault.HTMLProperty())
81 fmt.Printf("VAlignTop : '%s'\n", VAlignTop.HTMLProperty())
82 fmt.Printf("VAlignMiddle : '%s'\n", VAlignMiddle.HTMLProperty())
83 fmt.Printf("VAlignBottom : '%s'\n", VAlignBottom.HTMLProperty())
84
85
86
87
88
89 }
90
91 func TestVAlign_HTMLProperty(t *testing.T) {
92 vAligns := map[VAlign]string{
93 VAlignDefault: "",
94 VAlignTop: "top",
95 VAlignMiddle: "middle",
96 VAlignBottom: "bottom",
97 }
98 for vAlign, htmlStyle := range vAligns {
99 assert.Contains(t, vAlign.HTMLProperty(), htmlStyle)
100 }
101 }
102
View as plain text