Skip to content

Commit b8169cd

Browse files
committed
Add tests for AutoBuild overload method in the HelpText class.
1 parent a282612 commit b8169cd

File tree

2 files changed

+168
-70
lines changed

2 files changed

+168
-70
lines changed

src/CommandLine/Text/HelpText.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public bool AdditionalNewLineAfterOption
266266
/// </summary>
267267
public bool AddNewLineBetweenHelpSections
268268
{
269-
get { return addNewLineBetweenHelpSections; }
269+
get { return addNewLineBetweenHelpSections; }
270270
set { addNewLineBetweenHelpSections = value; }
271271
}
272272

@@ -416,7 +416,7 @@ public static HelpText AutoBuild<T>(ParserResult<T> parserResult, int maxDisplay
416416
/// </returns>
417417
/// <remarks>This feature is meant to be invoked automatically by the parser, setting the HelpWriter property
418418
/// of <see cref="CommandLine.ParserSettings"/>.</remarks>
419-
public static HelpText AutoBuild<T>(ParserResult<T> parserResult, Func<HelpText, HelpText> onError,int maxDisplayWidth = DefaultMaximumLength)
419+
public static HelpText AutoBuild<T>(ParserResult<T> parserResult, Func<HelpText, HelpText> onError, int maxDisplayWidth = DefaultMaximumLength)
420420
{
421421
if (parserResult.Tag != ParserResultType.NotParsed)
422422
throw new ArgumentException("Excepting NotParsed<T> type.", "parserResult");
@@ -434,9 +434,9 @@ public static HelpText AutoBuild<T>(ParserResult<T> parserResult, Func<HelpText,
434434
}, e => e, maxDisplayWidth: maxDisplayWidth);
435435

436436
var err = errors.OfType<HelpVerbRequestedError>().Single();
437-
var pr = new NotParsed<object>(TypeInfo.Create(err.Type), Enumerable.Empty<Error>());
437+
var pr = new NotParsed<object>(TypeInfo.Create(err.Type), new Error[] { err });
438438
return err.Matched
439-
? AutoBuild(pr, current =>
439+
? AutoBuild(pr, current =>
440440
{
441441
onError?.Invoke(current);
442442
return DefaultParsingErrorsHandler(pr, current);
@@ -460,7 +460,6 @@ public static HelpText DefaultParsingErrorsHandler<T>(ParserResult<T> parserResu
460460

461461
if (((NotParsed<T>)parserResult).Errors.OnlyMeaningfulOnes().Empty())
462462
return current;
463-
464463
var errors = RenderParsingErrorsTextAsLines(parserResult,
465464
current.SentenceBuilder.FormatError,
466465
current.SentenceBuilder.FormatMutuallyExclusiveSetErrors,
@@ -761,8 +760,8 @@ public override string ToString()
761760
var result = new StringBuilder(sbLength);
762761

763762
result.Append(heading)
764-
.AppendWhen(!string.IsNullOrEmpty(copyright),
765-
Environment.NewLine,
763+
.AppendWhen(!string.IsNullOrEmpty(copyright),
764+
Environment.NewLine,
766765
copyright)
767766
.AppendWhen(preOptionsHelp.SafeLength() > 0,
768767
NewLineIfNeededBefore(preOptionsHelp),
@@ -772,15 +771,15 @@ public override string ToString()
772771
Environment.NewLine,
773772
Environment.NewLine,
774773
optionsHelp.SafeToString())
775-
.AppendWhen(postOptionsHelp.SafeLength() > 0,
774+
.AppendWhen(postOptionsHelp.SafeLength() > 0,
776775
NewLineIfNeededBefore(postOptionsHelp),
777776
Environment.NewLine,
778777
postOptionsHelp.ToString());
779778

780779
string NewLineIfNeededBefore(StringBuilder sb)
781780
{
782-
if (AddNewLineBetweenHelpSections
783-
&& result.Length > 0
781+
if (AddNewLineBetweenHelpSections
782+
&& result.Length > 0
784783
&& !result.SafeEndsWith(Environment.NewLine)
785784
&& !sb.SafeStartsWith(Environment.NewLine))
786785
return Environment.NewLine;
@@ -981,7 +980,7 @@ specification is OptionSpecification optionSpecification &&
981980

982981
if (optionGroupSpecification != null)
983982
{
984-
optionHelpText = "({0}: {1}) ".FormatInvariant(optionGroupWord, optionGroupSpecification.Group) + optionHelpText;
983+
optionHelpText = "({0}: {1}) ".FormatInvariant(optionGroupWord, optionGroupSpecification.Group) + optionHelpText;
985984
}
986985

987986
//note that we need to indent trim the start of the string because it's going to be

0 commit comments

Comments
 (0)