/
table_printer_test.go
83 lines (66 loc) · 1.78 KB
/
table_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
package pterm
import (
"encoding/csv"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTablePrinter_NilPrint(t *testing.T) {
p := TablePrinter{}
p.Render()
}
func TestTablePrinter_Render(t *testing.T) {
proxyToDevNull()
DefaultTable.WithHasHeader().WithData(TableData{
{"Firstname", "Lastname", "Email"},
{"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"},
{"Callie", "Mckay", "egestas.nunc.sed@est.com"},
{"Libby", "Camacho", "aliquet.lobortis@semper.com"},
}).Render()
}
func TestTablePrinter_WithCSVReader(t *testing.T) {
r := csv.NewReader(os.Stdin)
p := TablePrinter{}
p2 := p.WithCSVReader(r)
p2.Srender()
}
func TestTablePrinter_WithData(t *testing.T) {
proxyToDevNull()
d := TableData{
{"Firstname", "Lastname", "Email"},
{"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"},
{"Callie", "Mckay", "egestas.nunc.sed@est.com"},
{"Libby", "Camacho", "aliquet.lobortis@semper.com"},
}
p := TablePrinter{}
p2 := p.WithData(d)
assert.Equal(t, d, p2.Data)
}
func TestTablePrinter_WithHasHeader(t *testing.T) {
p := TablePrinter{}
p2 := p.WithHasHeader()
assert.True(t, p2.HasHeader)
}
func TestTablePrinter_WithHeaderStyle(t *testing.T) {
s := NewStyle(FgRed, BgBlue, Bold)
p := TablePrinter{}
p2 := p.WithHeaderStyle(s)
assert.Equal(t, s, p2.HeaderStyle)
}
func TestTablePrinter_WithSeparator(t *testing.T) {
p := TablePrinter{}
p2 := p.WithSeparator("-")
assert.Equal(t, "-", p2.Separator)
}
func TestTablePrinter_WithSeparatorStyle(t *testing.T) {
s := NewStyle(FgRed, BgBlue, Bold)
p := TablePrinter{}
p2 := p.WithSeparatorStyle(s)
assert.Equal(t, s, p2.SeparatorStyle)
}
func TestTablePrinter_WithStyle(t *testing.T) {
s := NewStyle(FgRed, BgBlue, Bold)
p := TablePrinter{}
p2 := p.WithStyle(s)
assert.Equal(t, s, p2.Style)
}