|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using CommandLine.Tests.Fakes; |
| 4 | +using CommandLine.Text; |
| 5 | +using FluentAssertions; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace CommandLine.Tests.Unit.Text |
| 9 | +{ |
| 10 | + public class HelpTextAutoBuildFix |
| 11 | + { |
| 12 | + |
| 13 | + [Fact] |
| 14 | + public void HelpText_wit_AdditionalNewLineAfterOption_true_should_have_newline() |
| 15 | + { |
| 16 | + // Fixture setup |
| 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>())); |
| 21 | + |
| 22 | + // Verify outcome |
| 23 | + |
| 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 |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public void HelpText_wit_AdditionalNewLineAfterOption_false_should_not_have_newline() |
| 40 | + { |
| 41 | + // Fixture setup |
| 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>())); |
| 46 | + |
| 47 | + // Verify outcome |
| 48 | + |
| 49 | + var lines = sut.ToString().ToLines(); |
| 50 | + |
| 51 | + lines[2].Should().BeEquivalentTo(" stringvalue Define a string value here."); |
| 52 | + |
| 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 | + } |
| 57 | + [Fact] |
| 58 | + public void HelpText_wit_by_default_should_include_help_version_option() |
| 59 | + { |
| 60 | + // Fixture setup |
| 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 |
| 73 | + } |
| 74 | + |
| 75 | + [Fact] |
| 76 | + public void HelpText_wit_AutoHelp_false_should_hide_help_option() |
| 77 | + { |
| 78 | + // Fixture setup |
| 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 |
| 85 | + |
| 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 |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments