|
1 | 1 | // Copyright (c) Nate McMaster. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.IO; |
5 | 6 | using System.Text; |
6 | 7 | using McMaster.Extensions.CommandLineUtils.HelpText; |
@@ -37,5 +38,40 @@ public void ItListOptions() |
37 | 38 | Assert.Contains("--option <OPTION>", helpText); |
38 | 39 | Assert.DoesNotContain("-|--option <OPTION>", helpText); |
39 | 40 | } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void OrderCommandsByName() |
| 44 | + { |
| 45 | + var app = new CommandLineApplication<EmptyShortName>(); |
| 46 | + app.Conventions.UseDefaultConventions(); |
| 47 | + app.Command("b", null); |
| 48 | + app.Command("a", null); |
| 49 | + var sb = new StringBuilder(); |
| 50 | + DefaultHelpTextGenerator.Singleton.Generate(app, new StringWriter(sb)); |
| 51 | + var helpText = sb.ToString(); |
| 52 | + _output.WriteLine(helpText); |
| 53 | + |
| 54 | + int indexOfA = helpText.IndexOf(" a", StringComparison.InvariantCulture); |
| 55 | + int indexOfB = helpText.IndexOf(" b", StringComparison.InvariantCulture); |
| 56 | + Assert.True(indexOfA < indexOfB); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void DontOrderCommandsByName() |
| 61 | + { |
| 62 | + DefaultHelpTextGenerator.Singleton.SortCommandsByName = false; |
| 63 | + var app = new CommandLineApplication<EmptyShortName>(); |
| 64 | + app.Conventions.UseDefaultConventions(); |
| 65 | + app.Command("b", null); |
| 66 | + app.Command("a", null); |
| 67 | + var sb = new StringBuilder(); |
| 68 | + DefaultHelpTextGenerator.Singleton.Generate(app, new StringWriter(sb)); |
| 69 | + var helpText = sb.ToString(); |
| 70 | + _output.WriteLine(helpText); |
| 71 | + |
| 72 | + int indexOfA = helpText.IndexOf(" a", StringComparison.InvariantCulture); |
| 73 | + int indexOfB = helpText.IndexOf(" b", StringComparison.InvariantCulture); |
| 74 | + Assert.True(indexOfA > indexOfB); |
| 75 | + } |
40 | 76 | } |
41 | 77 | } |
0 commit comments