@@ -210,6 +210,136 @@ func TestAddText_Indent(t *testing.T) {
210
210
assert .Equal (t , status , cliargs .ITER_NO_MORE )
211
211
}
212
212
213
+ func TestAddTexts_zeroText (t * testing.T ) {
214
+ help := cliargs .NewHelp ()
215
+ help .AddTexts ([]string {})
216
+ iter := help .Iter ()
217
+
218
+ line , status := iter .Next ()
219
+ assert .Equal (t , line , "" )
220
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
221
+
222
+ help = cliargs .NewHelp ()
223
+ help .AddTexts ([]string (nil ))
224
+ iter = help .Iter ()
225
+
226
+ line , status = iter .Next ()
227
+ assert .Equal (t , line , "" )
228
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
229
+ }
230
+
231
+ func TestAddTexts_oneText (t * testing.T ) {
232
+ help := cliargs .NewHelp ()
233
+ help .AddTexts ([]string {
234
+ "a12345678 b12345678 c12345678 d12345678 " +
235
+ "e12345678 f12345678 g12345678 h12345678 i123" })
236
+ iter := help .Iter ()
237
+
238
+ line , status := iter .Next ()
239
+ assert .Equal (t , line , "a12345678 b12345678 c12345678 d12345678 " +
240
+ "e12345678 f12345678 g12345678 h12345678 " )
241
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
242
+
243
+ line , status = iter .Next ()
244
+ assert .Equal (t , line , "i123" )
245
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
246
+
247
+ line , status = iter .Next ()
248
+ assert .Equal (t , line , "" )
249
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
250
+ }
251
+
252
+ func TestAddTexts_multipleTexts (t * testing.T ) {
253
+ help := cliargs .NewHelp ()
254
+ help .AddTexts ([]string {
255
+ "a12345678 b12345678 c12345678 d12345678 " +
256
+ "e12345678 f12345678 g12345678 h12345678 i123" ,
257
+ "j12345678 k12345678 l12345678 m12345678 " +
258
+ "n12345678 o12345678 p12345678 q12345678 r123" ,
259
+ })
260
+ iter := help .Iter ()
261
+
262
+ line , status := iter .Next ()
263
+ assert .Equal (t , line , "a12345678 b12345678 c12345678 d12345678 " +
264
+ "e12345678 f12345678 g12345678 h12345678 " )
265
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
266
+
267
+ line , status = iter .Next ()
268
+ assert .Equal (t , line , "i123" )
269
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
270
+
271
+ line , status = iter .Next ()
272
+ assert .Equal (t , line , "j12345678 k12345678 l12345678 m12345678 " +
273
+ "n12345678 o12345678 p12345678 q12345678 " )
274
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
275
+
276
+ line , status = iter .Next ()
277
+ assert .Equal (t , line , "r123" )
278
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
279
+
280
+ line , status = iter .Next ()
281
+ assert .Equal (t , line , "" )
282
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
283
+ }
284
+
285
+ func TestAddTexts_withIndent (t * testing.T ) {
286
+ help := cliargs .NewHelp ()
287
+ help .AddTexts ([]string {
288
+ "a12345678 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" ,
289
+ "b1234 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" ,
290
+ }, 11 )
291
+ iter := help .Iter ()
292
+
293
+ line , status := iter .Next ()
294
+ assert .Equal (t , line , "a12345678 123456789 123456789 123456789 123456789 123456789 123456789 123456789" )
295
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
296
+
297
+ line , status = iter .Next ()
298
+ assert .Equal (t , line , " 123456789 123456789" )
299
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
300
+
301
+ line , status = iter .Next ()
302
+ assert .Equal (t , line , "b1234 123456789 123456789 123456789 123456789 123456789 123456789 123456789" )
303
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
304
+
305
+ line , status = iter .Next ()
306
+ assert .Equal (t , line , " 123456789 123456789" )
307
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
308
+
309
+ line , status = iter .Next ()
310
+ assert .Equal (t , line , "" )
311
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
312
+ }
313
+
314
+ func TestAddTexts_withMargins (t * testing.T ) {
315
+ help := cliargs .NewHelp (2 , 2 )
316
+ help .AddTexts ([]string {
317
+ "a12345678 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" ,
318
+ "b1234 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789" ,
319
+ }, 11 , 5 , 3 )
320
+ iter := help .Iter ()
321
+
322
+ line , status := iter .Next ()
323
+ assert .Equal (t , line , " a12345678 123456789 123456789 123456789 123456789 123456789 " )
324
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
325
+
326
+ line , status = iter .Next ()
327
+ assert .Equal (t , line , " 123456789 123456789 123456789 123456789" )
328
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
329
+
330
+ line , status = iter .Next ()
331
+ assert .Equal (t , line , " b1234 123456789 123456789 123456789 123456789 123456789 " )
332
+ assert .Equal (t , status , cliargs .ITER_HAS_MORE )
333
+
334
+ line , status = iter .Next ()
335
+ assert .Equal (t , line , " 123456789 123456789 123456789 123456789" )
336
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
337
+
338
+ line , status = iter .Next ()
339
+ assert .Equal (t , line , "" )
340
+ assert .Equal (t , status , cliargs .ITER_NO_MORE )
341
+ }
342
+
213
343
func TestAddOpts_zeroOpts (t * testing.T ) {
214
344
help := cliargs .NewHelp ()
215
345
help .AddOpts ([]cliargs.OptCfg {})
0 commit comments