1
- using CommandLine . Tests . Fakes ;
1
+ using System ;
2
+ using System . Linq ;
2
3
using CommandLine . Text ;
3
4
using FluentAssertions ;
4
5
using Xunit ;
@@ -11,110 +12,120 @@ private string NormalizeLineBreaks(string str)
11
12
{
12
13
return str . Replace ( "\r " , "" ) ;
13
14
}
14
- private void EnsureEquivalent ( string a , string b )
15
+
16
+ private void EnsureEquivalent ( string a , string b )
15
17
{
16
18
//workaround build system line-end inconsistencies
17
19
NormalizeLineBreaks ( a ) . Should ( ) . Be ( NormalizeLineBreaks ( b ) ) ;
18
20
}
19
21
20
-
22
+
21
23
[ Fact ]
22
- public void IndentWorksCorrectly ( )
24
+ public void ExtraSpacesAreTreatedAsNonBreaking ( )
23
25
{
26
+ var input =
27
+ "here is some text with some extra spacing" ;
28
+ var expected = @"here is some text
29
+ with some extra
30
+ spacing" ;
31
+ var wrapper = new TextWrapper ( input ) ;
32
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
33
+ }
24
34
35
+
36
+ [ Fact ]
37
+ public void IndentWorksCorrectly ( )
38
+ {
25
39
var input =
26
40
@"line1
27
41
line2" ;
28
42
var expected = @" line1
29
43
line2" ;
30
44
var wrapper = new TextWrapper ( input ) ;
31
- EnsureEquivalent ( wrapper . Indent ( 2 ) . ToText ( ) , expected ) ;
32
-
45
+ EnsureEquivalent ( wrapper . Indent ( 2 ) . ToText ( ) , expected ) ;
33
46
}
34
47
35
48
[ Fact ]
36
- public void SimpleWrappingIsAsExpected ( )
49
+ public void LongWordsAreBroken ( )
37
50
{
38
-
39
51
var input =
40
- @ "here is some text that needs wrapping ";
41
- var expected = @"here is
42
- some text
43
- that needs
44
- wrapping ";
52
+ "here is some text that contains a veryLongWordThatWontFitOnASingleLine " ;
53
+ var expected = @"here is some text
54
+ that contains a
55
+ veryLongWordThatWont
56
+ FitOnASingleLine ";
45
57
var wrapper = new TextWrapper ( input ) ;
46
- EnsureEquivalent ( wrapper . WordWrap ( 10 ) . ToText ( ) , expected ) ;
47
-
58
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
48
59
}
49
60
50
61
[ Fact ]
51
- public void WrappingAvoidsBreakingWords ( )
62
+ public void NegativeColumnWidthStillProducesOutput ( )
52
63
{
53
-
54
- var input =
55
- @"here hippopotamus is some text that needs wrapping" ;
56
- var expected = @"here
57
- hippopotamus is
58
- some text that
59
- needs wrapping" ;
64
+ var input = @"test" ;
65
+ var expected = string . Join ( Environment . NewLine , input . Select ( c => c . ToString ( ) ) ) ;
60
66
var wrapper = new TextWrapper ( input ) ;
61
- EnsureEquivalent ( wrapper . WordWrap ( 15 ) . ToText ( ) , expected ) ;
62
-
67
+ EnsureEquivalent ( wrapper . WordWrap ( - 1 ) . ToText ( ) , expected ) ;
63
68
}
64
69
65
70
[ Fact ]
66
- public void WrappingObeysLineBreaksOfAllStyles ( )
71
+ public void SimpleWrappingIsAsExpected ( )
67
72
{
68
-
69
73
var input =
70
- "here is some text\n that needs\r \n wrapping" ;
71
- var expected = @"here is some text
74
+ @"here is some text that needs wrapping" ;
75
+ var expected = @"here is
76
+ some text
72
77
that needs
73
78
wrapping" ;
74
79
var wrapper = new TextWrapper ( input ) ;
75
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
76
-
80
+ EnsureEquivalent ( wrapper . WordWrap ( 10 ) . ToText ( ) , expected ) ;
77
81
}
78
82
79
-
80
83
[ Fact ]
81
- public void WrappingPreservesSubIndentation ( )
84
+ public void SingleColumnStillProducesOutputForSubIndentation ( )
82
85
{
83
-
84
- var input =
85
- "here is some text\n that needs wrapping where we want the wrapped part to preserve indentation\n and this part to not be indented" ;
86
- var expected = @"here is some text
87
- that needs
88
- wrapping where we
89
- want the wrapped
90
- part to preserve
91
- indentation
92
- and this part to not
93
- be indented" ;
86
+ var input = @"test
87
+ ind" ;
88
+
89
+ var expected = @"t
90
+ e
91
+ s
92
+ t
93
+ i
94
+ n
95
+ d" ;
94
96
var wrapper = new TextWrapper ( input ) ;
95
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
96
-
97
+ EnsureEquivalent ( wrapper . WordWrap ( - 1 ) . ToText ( ) , expected ) ;
97
98
}
98
99
99
100
[ Fact ]
100
- public void LongWordsAreBroken ( )
101
+ public void SpacesWithinStringAreRespected ( )
101
102
{
102
-
103
103
var input =
104
- "here is some text that contains a veryLongWordThatWontFitOnASingleLine" ;
105
- var expected = @"here is some text
106
- that contains a
107
- veryLongWordThatWont
108
- FitOnASingleLine" ;
104
+ "here is some text with some extra spacing" ;
105
+ var expected = @"here is some
106
+ text with some extra
107
+ spacing" ;
109
108
var wrapper = new TextWrapper ( input ) ;
110
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
109
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
110
+ }
111
111
112
+ [ Fact ]
113
+ public void SubIndentationCorrectlyWrapsWhenColumnWidthRequiresIt ( )
114
+ {
115
+ var input = @"test
116
+ indented" ;
117
+ var expected = @"test
118
+ in
119
+ de
120
+ nt
121
+ ed" ;
122
+ var wrapper = new TextWrapper ( input ) ;
123
+ EnsureEquivalent ( wrapper . WordWrap ( 6 ) . ToText ( ) , expected ) ;
112
124
}
113
125
114
126
[ Fact ]
115
127
public void SubIndentationIsPreservedWhenBreakingWords ( )
116
128
{
117
-
118
129
var input =
119
130
"here is some text that contains \n a veryLongWordThatWontFitOnASingleLine" ;
120
131
var expected = @"here is some text
@@ -123,59 +134,64 @@ that contains
123
134
veryLongWordThatWo
124
135
ntFitOnASingleLine" ;
125
136
var wrapper = new TextWrapper ( input ) ;
126
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
127
-
137
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
128
138
}
129
139
130
140
[ Fact ]
131
- public void SpacesWithinStringAreRespected ( )
141
+ public void WrappingAvoidsBreakingWords ( )
132
142
{
133
-
134
143
var input =
135
- "here is some text with some extra spacing" ;
136
- var expected = @"here is some
137
- text with some extra
138
- spacing" ;
144
+ @"here hippopotamus is some text that needs wrapping" ;
145
+ var expected = @"here
146
+ hippopotamus is
147
+ some text that
148
+ needs wrapping" ;
139
149
var wrapper = new TextWrapper ( input ) ;
140
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
141
-
150
+ EnsureEquivalent ( wrapper . WordWrap ( 15 ) . ToText ( ) , expected ) ;
142
151
}
143
152
144
-
145
- [ Fact ]
146
- public void ExtraSpacesAreTreatedAsNonBreaking ( )
147
- {
148
153
149
- var input =
150
- "here is some text with some extra spacing" ;
151
- var expected = @"here is some text
152
- with some extra
153
- spacing" ;
154
- var wrapper = new TextWrapper ( input ) ;
155
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
156
-
157
- }
158
-
159
-
160
154
[ Fact ]
161
155
public void WrappingExtraSpacesObeySubIndent ( )
162
156
{
163
-
164
157
var input =
165
158
"here is some\n text with some extra spacing" ;
166
159
var expected = @"here is some
167
160
text
168
161
with some extra
169
162
spacing" ;
170
163
var wrapper = new TextWrapper ( input ) ;
171
- EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
172
-
164
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
173
165
}
174
166
167
+ [ Fact ]
168
+ public void WrappingObeysLineBreaksOfAllStyles ( )
169
+ {
170
+ var input =
171
+ "here is some text\n that needs\r \n wrapping" ;
172
+ var expected = @"here is some text
173
+ that needs
174
+ wrapping" ;
175
+ var wrapper = new TextWrapper ( input ) ;
176
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
177
+ }
175
178
176
179
180
+ [ Fact ]
181
+ public void WrappingPreservesSubIndentation ( )
182
+ {
183
+ var input =
184
+ "here is some text\n that needs wrapping where we want the wrapped part to preserve indentation\n and this part to not be indented" ;
185
+ var expected = @"here is some text
186
+ that needs
187
+ wrapping where we
188
+ want the wrapped
189
+ part to preserve
190
+ indentation
191
+ and this part to not
192
+ be indented" ;
193
+ var wrapper = new TextWrapper ( input ) ;
194
+ EnsureEquivalent ( wrapper . WordWrap ( 20 ) . ToText ( ) , expected ) ;
195
+ }
177
196
}
178
-
179
-
180
-
181
197
}
0 commit comments