File: valign_test.go

package info (click to toggle)
golang-github-jedib0t-go-pretty 6.5.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,700 kB
  • sloc: makefile: 28; sh: 14
file content (101 lines) | stat: -rw-r--r-- 3,954 bytes parent folder | download | duplicates (2)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package text

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

func ExampleVAlign_Apply() {
	lines := []string{"Game", "Of", "Thrones"}
	maxLines := 5
	fmt.Printf("VAlignDefault: %#v\n", VAlignDefault.Apply(lines, maxLines))
	fmt.Printf("VAlignTop    : %#v\n", VAlignTop.Apply(lines, maxLines))
	fmt.Printf("VAlignMiddle : %#v\n", VAlignMiddle.Apply(lines, maxLines))
	fmt.Printf("VAlignBottom : %#v\n", VAlignBottom.Apply(lines, maxLines))

	// Output: VAlignDefault: []string{"Game", "Of", "Thrones", "", ""}
	// VAlignTop    : []string{"Game", "Of", "Thrones", "", ""}
	// VAlignMiddle : []string{"", "Game", "Of", "Thrones", ""}
	// VAlignBottom : []string{"", "", "Game", "Of", "Thrones"}
}

func TestVAlign_Apply(t *testing.T) {
	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignDefault.Apply([]string{"Game", "Of", "Thrones"}, 1))
	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignDefault.Apply([]string{"Game", "Of", "Thrones"}, 3))
	assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
		VAlignDefault.Apply([]string{"Game", "Of", "Thrones"}, 5))

	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignTop.Apply([]string{"Game", "Of", "Thrones"}, 1))
	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignTop.Apply([]string{"Game", "Of", "Thrones"}, 3))
	assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
		VAlignTop.Apply([]string{"Game", "Of", "Thrones"}, 5))

	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignMiddle.Apply([]string{"Game", "Of", "Thrones"}, 1))
	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignMiddle.Apply([]string{"Game", "Of", "Thrones"}, 3))
	assert.Equal(t, []string{"", "Game", "Of", "Thrones", ""},
		VAlignMiddle.Apply([]string{"Game", "Of", "Thrones"}, 5))

	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignBottom.Apply([]string{"Game", "Of", "Thrones"}, 1))
	assert.Equal(t, []string{"Game", "Of", "Thrones"},
		VAlignBottom.Apply([]string{"Game", "Of", "Thrones"}, 3))
	assert.Equal(t, []string{"", "", "Game", "Of", "Thrones"},
		VAlignBottom.Apply([]string{"Game", "Of", "Thrones"}, 5))
}

func ExampleVAlign_ApplyStr() {
	str := "Game\nOf\nThrones"
	maxLines := 5
	fmt.Printf("VAlignDefault: %#v\n", VAlignDefault.ApplyStr(str, maxLines))
	fmt.Printf("VAlignTop    : %#v\n", VAlignTop.ApplyStr(str, maxLines))
	fmt.Printf("VAlignMiddle : %#v\n", VAlignMiddle.ApplyStr(str, maxLines))
	fmt.Printf("VAlignBottom : %#v\n", VAlignBottom.ApplyStr(str, maxLines))

	// Output: VAlignDefault: []string{"Game", "Of", "Thrones", "", ""}
	// VAlignTop    : []string{"Game", "Of", "Thrones", "", ""}
	// VAlignMiddle : []string{"", "Game", "Of", "Thrones", ""}
	// VAlignBottom : []string{"", "", "Game", "Of", "Thrones"}
}

func TestVAlign_ApplyStr(t *testing.T) {
	assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
		VAlignDefault.ApplyStr("Game\nOf\nThrones", 5))
	assert.Equal(t, []string{"Game", "Of", "Thrones", "", ""},
		VAlignTop.ApplyStr("Game\nOf\nThrones", 5))
	assert.Equal(t, []string{"", "Game", "Of", "Thrones", ""},
		VAlignMiddle.ApplyStr("Game\nOf\nThrones", 5))
	assert.Equal(t, []string{"", "", "Game", "Of", "Thrones"},
		VAlignBottom.ApplyStr("Game\nOf\nThrones", 5))
}

func ExampleVAlign_HTMLProperty() {
	fmt.Printf("VAlignDefault: '%s'\n", VAlignDefault.HTMLProperty())
	fmt.Printf("VAlignTop    : '%s'\n", VAlignTop.HTMLProperty())
	fmt.Printf("VAlignMiddle : '%s'\n", VAlignMiddle.HTMLProperty())
	fmt.Printf("VAlignBottom : '%s'\n", VAlignBottom.HTMLProperty())

	// Output: VAlignDefault: ''
	// VAlignTop    : 'valign="top"'
	// VAlignMiddle : 'valign="middle"'
	// VAlignBottom : 'valign="bottom"'
}

func TestVAlign_HTMLProperty(t *testing.T) {
	vAligns := map[VAlign]string{
		VAlignDefault: "",
		VAlignTop:     "top",
		VAlignMiddle:  "middle",
		VAlignBottom:  "bottom",
	}
	for vAlign, htmlStyle := range vAligns {
		assert.Contains(t, vAlign.HTMLProperty(), htmlStyle)
	}
}