BadScript 2
Loading...
Searching...
No Matches
Issue482Tests.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
6using Xunit;
7using FluentAssertions;
8
10{
11 public class Issue482Tests
12 {
13 [Fact]
15 {
16 string expectedCompany = "Company";
17
18
19 var parser = Parser.Default;
21 new[] { "verb1", "--help" })
22 .WithNotParsed(errors => { ; })
23 .WithParsed(args => {; });
24
25 var message = HelpText.AutoBuild(parseResult,
26 error =>error,
27 ex => ex
28 );
29
30 string helpMessage = message.ToString();
31 var helps = helpMessage.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(2).ToList<string>();
32 List<string> expected = new List<string>()
33 {
34 " -a, --alpha Required.",
35 " -b, --alpha2 Required.",
36 " -d, --charlie",
37 " -c, --bravo",
38 "-f, --foxtrot",
39 "-e, --echo",
40 "--help Display this help screen.",
41 "--version Display version information.",
42 "value pos. 0"
43 };
44 expected.Count.Should().Be(helps.Count);
45 int i = 0;
46 foreach (var expect in expected)
47 {
48 expect.Trim().Should().Be(helps[i].Trim());
49 i++;
50 }
51
52 ;
53 }
54
55 [Fact]
57 {
58 string expectedCompany = "Company";
59
60
61 var parser = Parser.Default;
63 new[] { "verb1", "--help" })
64 .WithNotParsed(errors => { ; })
65 .WithParsed(args => {; });
66
67 Comparison<ComparableOption> comparison = HelpText.RequiredThenAlphaComparison;
68
69 string message = HelpText.AutoBuild(parseResult,
70 error =>
71 {
72 error.OptionComparison = HelpText.RequiredThenAlphaComparison;
73 return error;
74 },
75 ex => ex);
76
77
78 string helpMessage = message.ToString();
79 var helps = helpMessage.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(2).ToList<string>();
80 List<string> expected = new List<string>()
81 {
82 " -a, --alpha Required.",
83 " -b, --alpha2 Required.",
84 " -c, --bravo",
85 " -d, --charlie",
86 "-e, --echo",
87 "-f, --foxtrot",
88 "--help Display this help screen.",
89 "--version Display version information.",
90 "value pos. 0"
91 };
92 expected.Count.Should().Be(helps.Count);
93 int i = 0;
94 foreach (var expect in expected)
95 {
96 expect.Trim().Should().Be(helps[i].Trim());
97 i++;
98 }
99
100 ;
101 }
102
103 [Fact]
105 {
106 string expectedCompany = "Company";
107
108
109 var parser = Parser.Default;
111 new[] { "verb1", "--help" })
112 .WithNotParsed(errors => { ; })
113 .WithParsed(args => {; });
114
115 Comparison<ComparableOption> orderOnShortName = (ComparableOption attr1, ComparableOption attr2) =>
116 {
117 if (attr1.IsOption && attr2.IsOption)
118 {
119 if (attr1.Required && !attr2.Required)
120 {
121 return -1;
122 }
123 else if (!attr1.Required && attr2.Required)
124 {
125 return 1;
126 }
127 else
128 {
129 if (string.IsNullOrEmpty(attr1.ShortName) && !string.IsNullOrEmpty(attr2.ShortName))
130 {
131 return 1;
132 }
133 else if (!string.IsNullOrEmpty(attr1.ShortName) && string.IsNullOrEmpty(attr2.ShortName))
134 {
135 return -1;
136 }
137 return String.Compare(attr1.ShortName, attr2.ShortName, StringComparison.Ordinal);
138 }
139 }
140 else if (attr1.IsOption && attr2.IsValue)
141 {
142 return -1;
143 }
144 else
145 {
146 return 1;
147 }
148 };
149
150 string message = HelpText.AutoBuild(parseResult,
151 error =>
152 {
153 error.OptionComparison = orderOnShortName;
154 return error;
155 },
156 ex => ex,
157 false,
158 80
159 );
160
161
162 var helps = message.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(2).ToList<string>();
163 List<string> expected = new List<string>()
164 {
165 " -a, --alpha Required.",
166 " -b, --alpha2 Required.",
167 " -c, --bravo",
168 " -d, --charlie",
169 "-e, --echo",
170 "-f, --foxtrot",
171 "--help Display this help screen.",
172 "--version Display version information.",
173 "value pos. 0"
174 };
175 expected.Count.Should().Be(helps.Count);
176 int i = 0;
177 foreach (var expect in expected)
178 {
179 expect.Trim().Should().Be(helps[i].Trim());
180 i++;
181 }
182 }
183
184
185 }
186}
Provides methods to parse command line arguments.
Definition Parser.cs:21
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
Definition Parser.cs:216
static Parser Default
Gets the singleton instance created with basic defaults.
Definition Parser.cs:75
static Comparison< ComparableOption > RequiredThenAlphaComparison
Definition HelpText.cs:1322
override string ToString()
Returns the help screen as a System.String.
Definition HelpText.cs:830
Provides means to format an help screen. You can assign it in place of a System.String instance.
Definition HelpText.cs:23