forked from olekukonko/tablewriter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtable_with_color_test.go
88 lines (69 loc) · 2.4 KB
/
table_with_color_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
// Copyright 2014 Oleku Konko All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
// This module is a Table Writer API for the Go Programming Language.
// The protocols were written in pure Go and works on windows and unix systems
package tablewriter
import (
"os"
"testing"
)
func TestSetHeaderColorNonTTY(t *testing.T) {
data := [][]string{
{"A", "The Good", "500"},
{"B", "The Very very Bad Man", "288"},
{"C", "The Ugly", "120"},
{"D", "The Gopher", "800"},
}
os.Stdout = nil
table := NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Sign", "Rating"})
want := table.headerParams
table.SetHeaderColor(Colors{Bold, FgHiYellowColor}, Colors{Bold, FgHiYellowColor}, Colors{Bold, FgHiYellowColor})
table.AppendBulk(data)
table.SetAutoMergeCells(true)
table.SetRowLine(true)
table.Render()
// The color codes are not added in case of non TTY output.
got := table.headerParams
checkEqual(t, got, want, "SetHeaderColor when TTY is not attached failed")
}
func TestSetColumnColorNonTTY(t *testing.T) {
data := [][]string{
{"A", "The Good", "500"},
{"B", "The Very very Bad Man", "288"},
{"C", "The Ugly", "120"},
{"D", "The Gopher", "800"},
}
os.Stdout = nil
table := NewWriter(os.Stdout)
want := table.columnsParams
table.SetColumnColor(Colors{Bold, FgHiYellowColor}, Colors{Bold, FgHiYellowColor}, Colors{Bold, FgHiYellowColor})
table.AppendBulk(data)
table.SetAutoMergeCells(true)
table.SetRowLine(true)
table.Render()
// The color codes are not added in case of non TTY output.
got := table.columnsParams
checkEqual(t, got, want, "SetColumnColor when TTY is not attached failed")
}
func TestSetFooterColorNonTTY(t *testing.T) {
data := [][]string{
{"Regular", "regular line", "1"},
{"Thick", "particularly thick line", "2"},
{"Double", "double line", "3"},
}
// Set stdout to nil to simulate not being a terminal
os.Stdout = nil
table := NewWriter(os.Stdout)
table.SetFooter([]string{"Constant", "Meaning", "Seq"})
want := table.footerParams
table.SetFooterColor(Colors{Bold, FgHiYellowColor}, Colors{Bold, FgHiYellowColor}, Colors{Bold, FgHiYellowColor})
table.AppendBulk(data)
table.SetAutoMergeCells(true)
table.SetRowLine(true)
table.Render()
// The color codes are added in case of TTY output.
got := table.footerParams
checkEqual(t, got, want, "SetHeaderColor when TTY is not attached failed")
}