|
1 | | -using CommandLine.Tests.Fakes; |
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using CommandLine.Tests.Fakes; |
2 | 4 | using CommandLine.Text; |
3 | 5 | using FluentAssertions; |
4 | 6 | using Xunit; |
5 | 7 |
|
6 | 8 | namespace CommandLine.Tests.Unit.Text |
7 | 9 | { |
8 | | - public class HelpTextTests2 |
| 10 | + public class HelpTextAutoBuildFix |
9 | 11 | { |
10 | | - [Fact] |
11 | | - public static void error_ishelp() |
12 | | - { |
13 | | - // Fixture setup |
14 | | - // Exercize system |
15 | | - var parser = new Parser(x => x.HelpWriter = null); |
16 | | - var result = parser.ParseArguments<Simple_Options>(new[]{"--help"}); |
17 | 12 |
|
18 | | - result .WithNotParsed(errs => |
19 | | - { |
20 | | - errs.IsHelp().Should().BeTrue(); |
21 | | - errs.IsVersion().Should().BeFalse(); |
22 | | - }); |
23 | | - } |
24 | 13 | [Fact] |
25 | | - public static void error_isVersion() |
| 14 | + public void HelpText_wit_AdditionalNewLineAfterOption_true_should_have_newline() |
26 | 15 | { |
27 | 16 | // Fixture setup |
28 | | - // Exercize system |
29 | | - var parser = new Parser(x => x.HelpWriter = null); |
30 | | - var result = parser.ParseArguments<Simple_Options>(new[]{"--version"}); |
| 17 | + // Exercize system |
| 18 | + var sut = new HelpText { AdditionalNewLineAfterOption = true } |
| 19 | + .AddOptions(new NotParsed<Simple_Options>(TypeInfo.Create(typeof(Simple_Options)), |
| 20 | + Enumerable.Empty<Error>())); |
31 | 21 |
|
32 | | - result .WithNotParsed(errs => |
33 | | - { |
34 | | - errs.IsHelp().Should().BeFalse(); |
35 | | - errs.IsVersion().Should().BeTrue(); |
36 | | - }); |
37 | | - } |
38 | | - |
39 | | - [Fact] |
40 | | - public static void custom_helptext_with_AdditionalNewLineAfterOption_false() |
41 | | - { |
42 | | - // Fixture setup |
43 | | - // Exercize system |
44 | | - var parser = new Parser(x => x.HelpWriter = null); |
45 | | - var result = parser.ParseArguments<Simple_Options>(new[]{"--help"}); |
| 22 | + // Verify outcome |
46 | 23 |
|
47 | | - result .WithNotParsed(errs => |
48 | | - { |
49 | | - |
50 | | - var sut = HelpText.AutoBuild(result, |
51 | | - h => |
52 | | - { |
53 | | - h.AdditionalNewLineAfterOption = false; |
54 | | - return h; |
55 | | - } |
56 | | - , e => e); |
57 | | - //Assert |
58 | | - var expected = new[] |
59 | | - { |
60 | | - " --help Display this help screen.", |
61 | | - " --version Display version information." |
62 | | - }; |
63 | | - var lines = sut.ToString().ToLines(); |
64 | | - lines.Should().ContainInOrder(expected); |
65 | | - }); |
| 24 | + var lines = sut.ToString().ToLines(); |
| 25 | + |
| 26 | + lines[2].Should().BeEquivalentTo(" stringvalue Define a string value here."); |
| 27 | + lines[3].Should().BeEquivalentTo(String.Empty); |
| 28 | + lines[4].Should().BeEquivalentTo(" s, shortandlong Example with both short and long name."); |
| 29 | + lines[5].Should().BeEquivalentTo(String.Empty); |
| 30 | + lines[7].Should().BeEquivalentTo(String.Empty); |
| 31 | + lines[9].Should().BeEquivalentTo(String.Empty); |
| 32 | + lines[11].Should().BeEquivalentTo(String.Empty); |
| 33 | + lines[13].Should().BeEquivalentTo(String.Empty); |
| 34 | + lines[14].Should().BeEquivalentTo(" value pos. 0 Define a long value here."); |
| 35 | + // Teardown |
66 | 36 | } |
67 | 37 |
|
68 | 38 | [Fact] |
69 | | - public static void custom_helptext_with_AdditionalNewLineAfterOption_true() |
| 39 | + public void HelpText_wit_AdditionalNewLineAfterOption_false_should_not_have_newline() |
70 | 40 | { |
71 | 41 | // Fixture setup |
72 | | - // Exercize system |
73 | | - var parser = new Parser(x => x.HelpWriter = null); |
74 | | - var result = parser.ParseArguments<Simple_Options>(new[]{"--help"}); |
| 42 | + // Exercize system |
| 43 | + var sut = new HelpText { AdditionalNewLineAfterOption = false } |
| 44 | + .AddOptions(new NotParsed<Simple_Options>(TypeInfo.Create(typeof(Simple_Options)), |
| 45 | + Enumerable.Empty<Error>())); |
75 | 46 |
|
76 | | - result .WithNotParsed(errs => |
77 | | - { |
78 | | - |
79 | | - var sut = HelpText.AutoBuild(result, |
80 | | - h =>h //AdditionalNewLineAfterOption =true by default |
81 | | - , e => e); |
82 | | - |
83 | | - //Assert |
84 | | - var expected = new[] |
85 | | - { |
86 | | - string.Empty, |
87 | | - " --help Display this help screen.", |
88 | | - string.Empty, |
89 | | - " --version Display version information." |
90 | | - }; |
91 | | - var lines = sut.ToString().ToLines(); |
92 | | - lines.Should().ContainInOrder(expected); |
93 | | - }); |
94 | | - } |
| 47 | + // Verify outcome |
| 48 | + |
| 49 | + var lines = sut.ToString().ToLines(); |
| 50 | + |
| 51 | + lines[2].Should().BeEquivalentTo(" stringvalue Define a string value here."); |
95 | 52 |
|
96 | | - |
| 53 | + lines[3].Should().BeEquivalentTo(" s, shortandlong Example with both short and long name."); |
| 54 | + lines[8].Should().BeEquivalentTo(" value pos. 0 Define a long value here."); |
| 55 | + // Teardown |
| 56 | + } |
97 | 57 | [Fact] |
98 | | - public static void custom_helptext_with_parser_autohelp_false_and_AdditionalNewLineAfterOption_false() |
| 58 | + public void HelpText_wit_by_default_should_include_help_version_option() |
99 | 59 | { |
100 | 60 | // Fixture setup |
101 | | - // Exercize system |
102 | | - var parser = new Parser(x => |
103 | | - { |
104 | | - x.HelpWriter = null; |
105 | | - x.AutoHelp=false; |
106 | | - //x.AutoVersion=false; |
107 | | - }); |
108 | | - var result = parser.ParseArguments<Simple_Options>(new[]{"--help"}); |
109 | | - //you could generate help even parser.AutoHelp is disabled |
110 | | - result .WithNotParsed(errs => |
111 | | - { |
112 | | - errs.IsHelp().Should().BeTrue(); |
113 | | - var sut = HelpText.AutoBuild(result, |
114 | | - h => |
115 | | - { |
116 | | - h.AdditionalNewLineAfterOption = false; |
117 | | - return h; |
118 | | - } |
119 | | - , e => e); |
120 | | - |
121 | | - //Assert |
122 | | - var expected = new[] |
123 | | - { |
124 | | - " --help Display this help screen.", |
125 | | - " --version Display version information." |
126 | | - }; |
127 | | - var lines = sut.ToString().ToLines(); |
128 | | - lines.Should().ContainInOrder(expected); |
129 | | - }); |
| 61 | + // Exercize system |
| 62 | + var sut = new HelpText () |
| 63 | + .AddOptions(new NotParsed<Simple_Options>(TypeInfo.Create(typeof(Simple_Options)), |
| 64 | + Enumerable.Empty<Error>())); |
| 65 | + |
| 66 | + // Verify outcome |
| 67 | + |
| 68 | + var lines = sut.ToString().ToNotEmptyLines(); |
| 69 | + lines.Should().HaveCount(c => c ==7); |
| 70 | + lines.Should().Contain(" help Display more information on a specific command."); |
| 71 | + lines.Should().Contain(" version Display version information."); |
| 72 | + // Teardown |
130 | 73 | } |
131 | 74 |
|
132 | 75 | [Fact] |
133 | | - public static void custom_helptext_with_autohelp_false() |
| 76 | + public void HelpText_wit_AutoHelp_false_should_hide_help_option() |
134 | 77 | { |
135 | 78 | // Fixture setup |
136 | | - // Exercize system |
137 | | - var parser = new Parser(x => |
138 | | - { |
139 | | - x.HelpWriter = null; |
140 | | - x.AutoHelp=false; |
141 | | - //x.AutoVersion=false; |
142 | | - }); |
143 | | - var result = parser.ParseArguments<Simple_Options>(new[]{"--help"}); |
| 79 | + // Exercize system |
| 80 | + var sut = new HelpText { AutoHelp = false,AutoVersion = false} |
| 81 | + .AddOptions(new NotParsed<Simple_Options>(TypeInfo.Create(typeof(Simple_Options)), |
| 82 | + Enumerable.Empty<Error>())); |
| 83 | + |
| 84 | + // Verify outcome |
144 | 85 |
|
145 | | - result .WithNotParsed(errs => |
146 | | - { |
147 | | - errs.IsHelp().Should().BeTrue(); |
148 | | - var sut = HelpText.AutoBuild(result, |
149 | | - h =>h,e => e); |
150 | | - |
151 | | - //Assert |
152 | | - var expected = new[] |
153 | | - { |
154 | | - string.Empty, |
155 | | - " --help Display this help screen.", |
156 | | - string.Empty, |
157 | | - " --version Display version information." |
158 | | - }; |
159 | | - var lines = sut.ToString().ToLines(); |
160 | | - lines.Should().ContainInOrder(expected); |
161 | | - }); |
| 86 | + var lines = sut.ToString().ToNotEmptyLines(); |
| 87 | + lines.Should().HaveCount(c => c ==5); |
| 88 | + lines.Should().NotContain(" help Display more information on a specific command."); |
| 89 | + lines.Should().NotContain(" version Display version information."); |
| 90 | + // Teardown |
162 | 91 | } |
163 | 92 | } |
164 | 93 | } |
0 commit comments