-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
126 lines (113 loc) · 4.63 KB
/
main_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
package fluit
import (
"fmt"
"testing"
)
var testOptions = []Option{
{"--hello", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in mattis leo. Integer eu tortor ut libero aliquet dignissim. Etiam nisi metus, consectetur eu luctus vel, malesuada id arcu"},
{"-a, --abcd", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in mattis leo. "},
{"-b, --bcde=STRING", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in mattis leo. "},
{"-c", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in mattis leo. "},
{"--if-the-arguments-is-longer-than-specified-max-size", "It will used up the entire line and the desc will use the line after it while still keeping the margin. "},
}
var testOptionsWants = []string{
` --hello Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Sed in mattis leo.
Integer eu tortor ut libero aliquet
dignissim. Etiam nisi metus, consectetur
eu luctus vel, malesuada id arcu
`,
` -a, --abcd Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Sed in mattis leo.
`,
` -b, --bcde=STRING
Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Sed in mattis leo.
`,
` -c Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Sed in mattis leo.
`,
` --if-the-arguments-is-longer-than-specified-max-size
It will used up the entire line and the
desc will use the line after it while
still keeping the margin.
`,
}
// TODO:
// This test is bound to fail because gofmt replace the spaces to tabs.
// Best to ignore it for now.
func TestSprintUsage(t *testing.T) {
UserBreakpoint = 80
for i := range testOptions {
if SprintUsage(15, testOptions[i].Argument, testOptions[i].Description) != testOptionsWants[i] {
t.Error("Formatted usage not equal to predefined output")
}
}
}
const (
lorem string = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in mattis leo. Integer eu tortor ut libero aliquet dignissim. Etiam nisi metus, consectetur eu luctus vel, malesuada id arcu. Integer egestas velit a velit sollicitudin venenatis. In volutpat nunc posuere ex lobortis maximus. Vivamus fringilla lacinia nisi nec hendrerit. Duis ipsum tortor, congue ut est eu, volutpat pharetra orci.`
loremHashLike string = `LoremipsumdolorsitametconsecteturadipiscingelitSedinmattisleoIntegereutortorutliberoaliquetdignissimEtiamnisimetusconsectetureuluctusvelmalesuadaidarcuIntegeregestasvelitavelitsollicitudinvenenatisInvolutpatnuncposuereexlobortismaximusVivamusfringillalacinianisinechendreritDuisipsumtortorcongueutesteuvolutpatpharetraorci`
)
func TestSprintwrap(t *testing.T) {
var got, want string
UserBreakpoint = 60
got = Wrap(0, lorem)
want = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
in mattis leo. Integer eu tortor ut libero aliquet
dignissim. Etiam nisi metus, consectetur eu luctus vel,
malesuada id arcu. Integer egestas velit a velit
sollicitudin venenatis. In volutpat nunc posuere ex lobortis
maximus. Vivamus fringilla lacinia nisi nec hendrerit. Duis
ipsum tortor, congue ut est eu, volutpat pharetra orci.`
if got != want {
t.Error("Invalid output on 0 margin")
}
got = Wrap(0, loremHashLike)
want = `LoremipsumdolorsitametconsecteturadipiscingelitSedinmattisle
oIntegereutortorutliberoaliquetdignissimEtiamnisimetusconsec
tetureuluctusvelmalesuadaidarcuIntegeregestasvelitavelitsoll
icitudinvenenatisInvolutpatnuncposuereexlobortismaximusVivam
usfringillalacinianisinechendreritDuisipsumtortorcongueutest
euvolutpatpharetraorci`
if got != want {
t.Error("Invalid output on 0 margin and hashlike input")
}
UserBreakpoint = 30
got = Wrap(3, lorem)
want = ` Lorem ipsum dolor sit amet,
consectetur adipiscing
elit. Sed in mattis leo.
Integer eu tortor ut libero
aliquet dignissim. Etiam
nisi metus, consectetur eu
luctus vel, malesuada id
arcu. Integer egestas velit
a velit sollicitudin
venenatis. In volutpat nunc
posuere ex lobortis
maximus. Vivamus fringilla
lacinia nisi nec hendrerit.
Duis ipsum tortor, congue
ut est eu, volutpat
pharetra orci.`
if got != want {
t.Error("Invalid output")
}
got = Wrap(3, loremHashLike)
want = ` Loremipsumdolorsitametconse
cteturadipiscingelitSedinma
ttisleoIntegereutortorutlib
eroaliquetdignissimEtiamnis
imetusconsectetureuluctusve
lmalesuadaidarcuIntegereges
tasvelitavelitsollicitudinv
enenatisInvolutpatnuncposue
reexlobortismaximusVivamusf
ringillalacinianisinechendr
eritDuisipsumtortorcongueut
esteuvolutpatpharetraorci`
if got != want {
fmt.Println(got)
t.Error("invalid output on hashlike input")
}
}