-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab_test.go
141 lines (132 loc) · 4.53 KB
/
tab_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright ©2022 Foolin. All rights reserved.
package gotab
import (
"os"
"testing"
)
const summaryEn = "Gotab is a go library for align text"
const summaryCn = "Gotab是控制台对齐的go库"
func TestPrintTable(t *testing.T) {
println("============================================")
writer := NewWriter()
writer.Config.Pad = "-"
writer.Config.Split = "|"
writer.AddLine("Hello, World", summaryEn)
writer.AddLine("Hello,世A界B", summaryEn)
writer.AddLine("您好,NI世界ABC", summaryCn)
writer.AddDivider()
data := [][]any{
{"node2.example.com", "Ready", "1.12", "1.12"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
}
writer.AddLines(data...)
writer.AddDividerWithValue("----")
writer.AddLine("Ready", "ABC", summaryEn)
writer.AddLine("NotReady", summaryCn, "EDF")
writer.Print()
}
func TestPrintTableUseTab(t *testing.T) {
println("============================================")
writer := NewWriter()
writer.Config.Pad = "-"
writer.Config.Split = "|"
writer.Config.UseTab = true
writer.AddLine("Hello, World", summaryEn)
writer.AddLine("Hello,世A界B", summaryEn)
writer.AddLine("您好,NI世界ABC", summaryCn)
writer.AddDivider()
data := [][]any{
{"node2.example.com", "Ready", "1.12", "1.12"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
}
writer.AddLines(data...)
writer.AddDividerWithValue("----")
writer.AddLine("Ready", "ABC", summaryEn)
writer.AddLine("NotReady", summaryCn, "EDF")
writer.Print()
}
func TestPrintTable2(t *testing.T) {
println("============================================")
writer := NewWriter()
writer.Config.Split = "|"
writer.AddDivider()
data := [][]any{
{"node2.example.com", "Ready", "1.12", "1.12"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
}
writer.AddLines(data...)
writer.AddDividerWithValue("----")
writer.AddLine("NotReady2", "ABC", summaryEn)
writer.AddLine("NotReady2", summaryCn, "EDF")
writer.Print()
}
func TestPrintTable3(t *testing.T) {
println("============================================")
writer := NewWriter()
writer.Config.Split = "|"
writer.AddLine("A", summaryEn)
writer.AddLine("Hello, 世界", summaryEn)
writer.AddLine("您好, 世界", summaryEn)
//writer.AddDivider()
data := [][]any{
{"node2.example.com", "Ready", "1.12", "1.12"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
}
writer.AddLines(data...)
writer.AddDividerWithValue("----")
writer.AddLine("您好,世界", "ABC", summaryEn)
writer.AddLine("Hello, 世界", "ABC", summaryEn)
writer.AddLine("A", summaryEn, "Hello World")
writer.Print()
}
func TestPrintTable4(t *testing.T) {
println("============================================")
config := DefaultConfig
config.Split = "|"
config.MinWiths = []int{100}
//config.MinWith = 20
//config.MaxWith = 30
writer := NewWriterWithConfig(config)
writer.AddLine("A", summaryEn)
writer.AddLine("Hello, 世界", summaryEn)
writer.AddLine("您好, 世界", summaryEn)
writer.AddDividerWithValue("----")
data := [][]any{
{"node2.example.com", "Ready", "1.12", "1.12"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
}
writer.AddLines(data...)
writer.AddDividerWithValue("-----------------")
writer.AddLine("Hello, 世界", "ABC", summaryEn)
writer.AddLine("A", summaryEn, "Hello World")
result := writer.String()
println(result)
}
func TestPrintTable5(t *testing.T) {
println("============================================")
data := [][]any{
{"node1.example.com", summaryEn, "A"},
{"----"},
{"node2.example.com", "Ready", "1.12", "1.12"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
{"node3.example.com", "Ready", "compute", "1.13"},
{"node4.example.com", "NotReady", "compute", "1.11"},
}
Print(os.Stdout, data...)
}