forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
area_printer_test.go
127 lines (88 loc) · 3.28 KB
/
area_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
package pterm_test
import (
"os"
"testing"
"github.com/MarvinJWendt/testza"
"github.com/pterm/pterm"
)
func TestAreaPrinter_NilPrint(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
p := pterm.AreaPrinter{}
p.Update("asd")
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_GenericStart(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
p := pterm.DefaultArea
p.GenericStart()
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_GenericStartRawOutput(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
pterm.DisableStyling()
p := pterm.DefaultArea
p.GenericStart()
pterm.EnableStyling()
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_GenericStop(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
p := pterm.DefaultArea
p.GenericStop()
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_RemoveWhenDone(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
a, _ := pterm.DefaultArea.WithRemoveWhenDone().Start()
a.Update("asd")
a.Stop()
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_CenterFullscreen(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
a, _ := pterm.DefaultArea.WithRemoveWhenDone().WithFullscreen().WithCenter().Start()
a.Update("asd")
a.Stop()
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_GetContent(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
a, _ := pterm.DefaultArea.Start()
for _, printable := range printables {
a.Update(printable)
testza.AssertEqual(t, a.GetContent(), pterm.Sprint(printable))
}
a.Stop()
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_WithRemoveWhenDone(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
p := pterm.AreaPrinter{}
p2 := p.WithRemoveWhenDone()
testza.AssertTrue(t, p2.RemoveWhenDone)
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_WithFullscreen(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
p := pterm.AreaPrinter{}
p2 := p.WithFullscreen()
testza.AssertTrue(t, p2.Fullscreen)
os.Stdout = originalStdout // Restore original os.Stdout
}
func TestAreaPrinter_Clear(t *testing.T) {
originalStdout := os.Stdout
os.Stdout = os.NewFile(0, os.DevNull) // Set os.Stdout to DevNull to hide output from cursor.Area
p := pterm.AreaPrinter{}
p.Update("asd")
p.Clear()
os.Stdout = originalStdout // Restore original os.Stdout
}