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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
package pterm_test
import (
"os"
"testing"
"github.com/MarvinJWendt/testza"
"github.com/pterm/pterm"
)
func TestHeatmapPrinter_NilPrint(t *testing.T) {
p := pterm.HeatmapPrinter{}
p.Render()
}
func TestHeatmapPrinter_SRender(t *testing.T) {
d := [][]float32{
{-1, -0.9, -0.8},
{-1, -0.9, -0.8},
{-1, -0.9, -0.8},
}
hd := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c"},
YAxis: []string{"1", "2", "3"},
}
// WithGrid
printer := pterm.DefaultHeatmap.WithAxisData(hd).WithData(d)
content, err := printer.Srender()
testza.AssertNoError(t, err)
testza.AssertNotNil(t, content)
// WithoutGrid
printer = pterm.DefaultHeatmap.WithAxisData(hd).WithData(d).WithGrid(false)
content, err = printer.Srender()
testza.AssertNoError(t, err)
testza.AssertNotNil(t, content)
// WithColouredCells
printer = pterm.DefaultHeatmap.WithAxisData(hd).WithData(d).WithOnlyColoredCells()
content, err = printer.Srender()
testza.AssertNoError(t, err)
testza.AssertNotNil(t, content)
// WithoutStyle
printer = pterm.DefaultHeatmap.WithAxisData(hd).WithData(d).WithAxisStyle(nil)
content, err = printer.Srender()
testza.AssertNoError(t, err)
testza.AssertNotNil(t, content)
// WithoutSeparatorStyle
printer = pterm.DefaultHeatmap.WithAxisData(hd).WithData(d).WithSeparatorStyle(nil)
content, err = printer.Srender()
testza.AssertNoError(t, err)
testza.AssertNotNil(t, content)
// WithEnableRGB
printer = pterm.DefaultHeatmap.WithAxisData(hd).WithData(d).WithEnableRGB(true)
content, err = printer.Srender()
testza.AssertNoError(t, err)
testza.AssertNotNil(t, content)
}
func TestHeatmapPrinter_WithAxisData(t *testing.T) {
hd := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c"},
YAxis: []string{"1", "2", "3"},
}
h := pterm.DefaultHeatmap.WithAxisData(hd)
testza.AssertTrue(t, h.HasHeader)
testza.AssertEqual(t, hd, h.Axis)
}
func TestHeatmapPrinter_WithAxisStyle(t *testing.T) {
s := pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold)
p := pterm.HeatmapPrinter{}
p2 := p.WithAxisStyle(s)
testza.AssertEqual(t, s, p2.AxisStyle)
}
func TestHeatmapPrinter_WithSeparatorStyle(t *testing.T) {
s := pterm.NewStyle(pterm.FgRed, pterm.BgBlue, pterm.Bold)
h := pterm.HeatmapPrinter{}
h2 := h.WithSeparatorStyle(s)
testza.AssertEqual(t, s, h2.SeparatorStyle)
}
func TestHeatmapPrinter_WithData(t *testing.T) {
proxyToDevNull()
d := [][]float32{
{-1, -0.9, -0.8, -0.7, -0.6},
{-1, -0.9, -0.8, -0.7, -0.6},
}
h := pterm.HeatmapPrinter{}
h2 := h.WithData(d)
testza.AssertEqualValues(t, d, h2.Data)
}
func TestHeatmapPrinter_WithBoxed(t *testing.T) {
h := pterm.HeatmapPrinter{}
h2 := h.WithBoxed(true)
testza.AssertTrue(t, h2.Boxed)
}
func TestHeatmapPrinter_WithGrid(t *testing.T) {
h := pterm.HeatmapPrinter{}
h2 := h.WithGrid(true)
testza.AssertTrue(t, h2.Grid)
}
func TestHeatmapPrinter_WithoutGrid(t *testing.T) {
h := pterm.DefaultHeatmap
h2 := h.WithGrid(false)
testza.AssertFalse(t, h2.Grid)
testza.AssertFalse(t, h2.Boxed)
}
func TestHeatmapPrinter_WithRGB(t *testing.T) {
h := pterm.HeatmapPrinter{}
h2 := h.WithEnableRGB(true)
testza.AssertTrue(t, h2.EnableRGB)
}
func TestHeatmapPrinter_WithOnlyColoredCells(t *testing.T) {
h := pterm.HeatmapPrinter{}
h2 := h.WithOnlyColoredCells(true)
testza.AssertTrue(t, h2.OnlyColoredCells)
}
func TestHeatmapPrinter_WithCellSize(t *testing.T) {
h := pterm.HeatmapPrinter{}
h2 := h.WithCellSize(1)
testza.AssertEqual(t, 1, h2.CellSize)
}
func TestHeatmapPrinter_WithWriter(t *testing.T) {
h := pterm.HeatmapPrinter{}
s := os.Stderr
h2 := h.WithWriter(s)
testza.AssertEqual(t, s, h2.Writer)
testza.AssertZero(t, h.Writer)
}
|