-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexttable_test.go
More file actions
88 lines (80 loc) · 1.91 KB
/
texttable_test.go
File metadata and controls
88 lines (80 loc) · 1.91 KB
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
package texttable
import (
"fmt"
)
func createTestTable(titles, rows, emptyRow bool) *Table {
t := new(Table)
if titles {
t.SetTitles(Row{
{"Fruit", 0, 0, AlignLeft},
{"Price", 0, 0, AlignLeft},
{"Notes", 0, 0, AlignLeft},
})
}
if rows {
t.AddRow(Row{
{"Äpple", 0, 0, AlignRight}, // Use UTF-8 character to test padding and alignment
{"10", 0, 5, AlignRight},
})
if emptyRow {
t.AddRow(Row{})
} else {
t.AddRow(Row{
{"Banana", 0, 0, AlignCenter},
{"5", 5, 0, AlignRight},
{"Overripe", 0, 0, AlignLeft},
})
}
t.AddRow(Row{
{"Red Grapes", 0, 0, AlignLeft},
{"17", 0, 0, AlignCenter},
{"", 0, 0, AlignLeft},
{"Extra column", 0, 0, AlignLeft},
})
}
return t
}
func ExampleTitlesAndRows() {
fmt.Printf("%s", createTestTable(true, true, false))
// Output:
// Fruit | Price | Notes |
// -----------+---------+----------+-------------
// Äpple | 10 | |
// Banana | 5 | Overripe |
// Red Grapes | 17 | | Extra column
}
func ExampleTitlesOnly() {
fmt.Printf("%s", createTestTable(true, false, false))
// Output:
// Fruit | Price | Notes
// ------+-------+------
}
func ExampleRowsOnly() {
fmt.Printf("!\n%s", createTestTable(false, true, false))
// Output:
// !
// Äpple | 10 | |
// Banana | 5 | Overripe |
// Red Grapes | 17 | | Extra column
}
func ExampleEmptyRow() {
fmt.Printf("%s", createTestTable(true, true, true))
// Output:
// Fruit | Price | Notes |
// -----------+---------+-------+-------------
// Äpple | 10 | |
// | | |
// Red Grapes | 17 | | Extra column
}
func ExampleSingleColumn() {
t := new(Table)
t.SetTitles(Row{{Content: "Fruit"}})
t.AddRow(Row{{Content: "Äpple"}})
t.AddRow(Row{{Content: "Banana"}})
fmt.Printf("%s", t)
// Output:
// Fruit
// ------
// Äpple
// Banana
}