forked from johnmikee/pterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pterm_test.go
68 lines (58 loc) · 2.16 KB
/
pterm_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
package pterm_test
import (
"github.com/MarvinJWendt/testza"
"github.com/gemini/pterm"
"testing"
"github.com/MarvinJWendt/testza"
"github.com/gemini/pterm"
)
func TestDisableDebugMessages(t *testing.T) {
pterm.PrintDebugMessages = true
pterm.DisableDebugMessages()
testza.AssertFalse(t, pterm.PrintDebugMessages)
}
func TestEnableDebugMessages(t *testing.T) {
pterm.EnableDebugMessages()
testza.AssertTrue(t, pterm.PrintDebugMessages)
}
func TestDisableOutput(t *testing.T) {
pterm.DisableOutput()
testza.AssertFalse(t, pterm.Output)
}
func TestEnableOutput(t *testing.T) {
pterm.DisableOutput()
pterm.EnableOutput()
testza.AssertTrue(t, pterm.Output)
}
func TestDisableStyling(t *testing.T) {
pterm.RawOutput = false
pterm.DisableStyling()
testza.AssertTrue(t, pterm.RawOutput)
}
func TestEnableStyling(t *testing.T) {
pterm.RawOutput = true
pterm.EnableStyling()
testza.AssertFalse(t, pterm.RawOutput)
}
func TestInterfaceImplementation(t *testing.T) {
// If a printer doesn't fit into the slice, the printer doesn't has the right interface anymore.
_ = []pterm.TextPrinter{&pterm.DefaultBasicText, pterm.DefaultBox, pterm.DefaultCenter, &pterm.DefaultHeader, &pterm.DefaultParagraph, &pterm.Info, &pterm.DefaultSection, pterm.FgRed, pterm.NewRGB(0, 0, 0)}
_ = []pterm.LivePrinter{pterm.DefaultProgressbar, &pterm.DefaultSpinner}
_ = []pterm.RenderPrinter{pterm.DefaultBarChart, pterm.DefaultBigText, pterm.DefaultBulletList, pterm.DefaultPanel, pterm.DefaultTable, pterm.DefaultTree}
}
func TestRecalculateTerminalSize(t *testing.T) {
// save existing values
prevBarChartWidth := pterm.DefaultBarChart.Width
prevBarChartHeight := pterm.DefaultBarChart.Height
prevParagraphMaxWidth := pterm.DefaultParagraph.MaxWidth
w := pterm.GetTerminalWidth()
h := pterm.GetTerminalHeight()
// double the terminal size
pterm.SetForcedTerminalSize(w*2, h*2)
// assert the values doubled
testza.AssertEqual(t, prevBarChartWidth*2, pterm.DefaultBarChart.Width)
testza.AssertEqual(t, prevBarChartHeight*2, pterm.DefaultBarChart.Height)
testza.AssertEqual(t, prevParagraphMaxWidth*2, pterm.DefaultParagraph.MaxWidth)
// revert the terminal size
pterm.SetForcedTerminalSize(w, h)
}