BadScript 2
Loading...
Searching...
No Matches
Issue104Tests.cs
Go to the documentation of this file.
1using System.Linq;
2using Xunit;
3using FluentAssertions;
6
7//Issue #104
8//When outputting HelpText, the code will correctly list valid values for enum type options. However, if the option is a nullable enum type, then it will not list the valid values.
9
11{
12 public class Issue104Tests
13 {
14
15 [Fact]
17 {
18 // Fixture setup
19 // Exercize system
20 var sut = new HelpText { AddDashesToOption = true, AddEnumValuesToHelpText = true, MaximumDisplayWidth = 80 }
21 .AddPreOptionsLine("pre-options")
23 .AddPostOptionsLine("post-options");
24
25 // Verify outcome
26
27 var lines = sut.ToString().ToNotEmptyLines().TrimStringArray();
28 lines[0].Should().BeEquivalentTo("pre-options");
29 lines[1].Should().BeEquivalentTo("--stringvalue Define a string value here.");
30 lines[2].Should().BeEquivalentTo("--shape Define a enum value here. Valid values: Circle, Square,");
31 lines[3].Should().BeEquivalentTo("Triangle");
32 lines[4].Should().BeEquivalentTo("--help Display this help screen.");
33 lines[5].Should().BeEquivalentTo("--version Display version information.");
34 lines[6].Should().BeEquivalentTo("post-options");
35 // Teardown
36 }
37
38 [Fact]
40 {
41 // Fixture setup
42 // Exercize system
43 var args = "--help".Split();
44 var sut = new Parser(config => config.HelpWriter = null);
45 var parserResult = sut.ParseArguments<Options_With_Nullable_Enum_Having_HelpText>(args);
46 HelpText helpText = null;
47 parserResult.WithNotParsed(errors =>
48 {
49 // Use custom help text to ensure valid enum values are displayed
50 helpText = HelpText.AutoBuild(parserResult);
51 helpText.AddEnumValuesToHelpText = true;
52 helpText.AddOptions(parserResult);
53 });
54
55 // Verify outcome
56
57 var lines = helpText.ToString().ToNotEmptyLines().TrimStringArray();
58 lines[2].Should().BeEquivalentTo("--stringvalue Define a string value here.");
59 lines[3].Should().BeEquivalentTo("--shape Define a enum value here. Valid values: Circle, Square,");
60 lines[4].Should().BeEquivalentTo("Triangle");
61 lines[5].Should().BeEquivalentTo("--help Display this help screen.");
62 lines[6].Should().BeEquivalentTo("--version Display version information.");
63 // Teardown
64 }
65 }
66
67}
Base type of all errors.
Definition Error.cs:110
It contains a sequence of CommandLine.Error.
Provides methods to parse command line arguments.
Definition Parser.cs:21
void Create_instance_with_enum_options_enabled_and_nullable_enum()
HelpText AddPreOptionsLine(string value)
Adds a text line after copyright and before options usage strings.
Definition HelpText.cs:494
HelpText AddPostOptionsLine(string value)
Adds a text line at the bottom, after options usage string.
Definition HelpText.cs:505
override string ToString()
Returns the help screen as a System.String.
Definition HelpText.cs:830
static TypeInfo Create(Type current)