forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
section_printer_test.go
137 lines (110 loc) · 3.12 KB
/
section_printer_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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package pterm_test
import (
"errors"
"io"
"testing"
"github.com/MarvinJWendt/testza"
"github.com/pterm/pterm"
)
func TestSectionPrinterNilPrint(t *testing.T) {
p := pterm.SectionPrinter{}
p.Println("Hello, World!")
}
func TestSectionPrinterPrintMethods(t *testing.T) {
p := pterm.DefaultSection
t.Run("Print", func(t *testing.T) {
testPrintContains(t, func(w io.Writer, a interface{}) {
p.Print(a)
})
})
t.Run("Printf", func(t *testing.T) {
testPrintfContains(t, func(w io.Writer, format string, a interface{}) {
p.Printf(format, a)
})
})
t.Run("Printfln", func(t *testing.T) {
testPrintflnContains(t, func(w io.Writer, format string, a interface{}) {
p.Printfln(format, a)
})
})
t.Run("Println", func(t *testing.T) {
testPrintlnContains(t, func(w io.Writer, a interface{}) {
p.Println(a)
})
})
t.Run("Sprint", func(t *testing.T) {
testSprintContains(t, func(a interface{}) string {
return p.Sprint(a)
})
})
t.Run("Sprintf", func(t *testing.T) {
testSprintfContains(t, func(format string, a interface{}) string {
return p.Sprintf(format, a)
})
})
t.Run("Sprintfln", func(t *testing.T) {
testSprintflnContains(t, func(format string, a interface{}) string {
return p.Sprintfln(format, a)
})
})
t.Run("Sprintln", func(t *testing.T) {
testSprintlnContains(t, func(a interface{}) string {
return p.Sprintln(a)
})
})
t.Run("PrintOnError", func(t *testing.T) {
result := captureStdout(func(w io.Writer) {
p.PrintOnError(errors.New("hello world"))
})
testza.AssertContains(t, result, "hello world")
})
t.Run("PrintIfError_WithoutError", func(t *testing.T) {
result := captureStdout(func(w io.Writer) {
p.PrintOnError(nil)
})
testza.AssertZero(t, result)
})
t.Run("PrintOnErrorf", func(t *testing.T) {
result := captureStdout(func(w io.Writer) {
p.PrintOnErrorf("wrapping error : %w", errors.New("hello world"))
})
testza.AssertContains(t, result, "hello world")
})
t.Run("PrintIfError_WithoutErrorf", func(t *testing.T) {
result := captureStdout(func(w io.Writer) {
p.PrintOnErrorf("", nil)
})
testza.AssertZero(t, result)
})
}
func TestSectionPrinter_WithBottomPadding(t *testing.T) {
p := pterm.SectionPrinter{}
p2 := p.WithBottomPadding(1337)
testza.AssertEqual(t, 1337, p2.BottomPadding)
testza.AssertZero(t, p.BottomPadding)
}
func TestSectionPrinter_WithLevel(t *testing.T) {
p := pterm.SectionPrinter{}
p2 := p.WithLevel(1337)
testza.AssertEqual(t, 1337, p2.Level)
testza.AssertZero(t, p.Level)
}
func TestSectionPrinter_WithStyle(t *testing.T) {
p := pterm.SectionPrinter{}
s := pterm.NewStyle(pterm.FgRed, pterm.BgRed, pterm.Bold)
p2 := p.WithStyle(s)
testza.AssertEqual(t, s, p2.Style)
testza.AssertZero(t, p.Style)
}
func TestSectionPrinter_WithTopPadding(t *testing.T) {
p := pterm.SectionPrinter{}
p2 := p.WithTopPadding(1337)
testza.AssertEqual(t, 1337, p2.TopPadding)
testza.AssertZero(t, p.TopPadding)
}
func TestSectionPrinter_WithIndentCharacter(t *testing.T) {
p := pterm.SectionPrinter{}
p2 := p.WithIndentCharacter("#")
testza.AssertEqual(t, "#", p2.IndentCharacter)
testza.AssertZero(t, p.IndentCharacter)
}