33using System ;
44using System . Collections . Generic ;
55using System . Globalization ;
6- using CommandLine . Core ;
76using System . Linq ;
87using System . Reflection ;
8+ using System . Text ;
9+
10+ using CommandLine . Core ;
911using CommandLine . Infrastructure ;
1012using CommandLine . Tests . Fakes ;
1113using CommandLine . Text ;
14+
1215using FluentAssertions ;
16+
1317using Xunit ;
14- using System . Text ;
1518
1619namespace CommandLine . Tests . Unit . Text
1720{
1821 public class HelpTextTests : IDisposable
1922 {
23+ private readonly HeadingInfo headingInfo = new HeadingInfo ( "CommandLine.Tests.dll" , "1.9.4.131" ) ;
24+
2025 public void Dispose ( )
2126 {
2227 ReflectionHelper . SetAttributeOverride ( null ) ;
@@ -143,7 +148,7 @@ public void When_help_text_is_longer_than_width_it_will_wrap_around_as_if_in_a_c
143148 {
144149 // Fixture setup
145150 // Exercize system
146- var sut = new HelpText ( new HeadingInfo ( "CommandLine.Tests.dll" , "1.9.4.131" ) ) ;
151+ var sut = new HelpText ( headingInfo ) ;
147152 sut . MaximumDisplayWidth = 40 ;
148153 sut . AddOptions (
149154 new NotParsed < Simple_Options_With_HelpText_Set_To_Long_Description > (
@@ -166,7 +171,7 @@ public void When_help_text_is_longer_than_width_it_will_wrap_around_as_if_in_a_c
166171 {
167172 // Fixture setup
168173 // Exercize system
169- var sut = new HelpText ( new HeadingInfo ( "CommandLine.Tests.dll" , "1.9.4.131" ) ) { MaximumDisplayWidth = 100 } ;
174+ var sut = new HelpText ( headingInfo ) { MaximumDisplayWidth = 100 } ;
170175 sut . AddOptions (
171176 new NotParsed < Simple_Options_With_HelpText_Set_To_Long_Description > (
172177 TypeInfo . Create ( typeof ( Simple_Options_With_HelpText_Set_To_Long_Description ) ) ,
@@ -185,7 +190,7 @@ public void When_help_text_has_hidden_option_it_should_not_be_added_to_help_text
185190 {
186191 // Fixture setup
187192 // Exercize system
188- var sut = new HelpText ( new HeadingInfo ( "CommandLine.Tests.dll" , "1.9.4.131" ) ) ;
193+ var sut = new HelpText ( headingInfo ) ;
189194 sut . MaximumDisplayWidth = 80 ;
190195 sut . AddOptions (
191196 new NotParsed < Simple_Options_With_HelpText_Set_To_Long_Description > (
@@ -205,7 +210,7 @@ public void Long_help_text_without_spaces()
205210 {
206211 // Fixture setup
207212 // Exercize system
208- var sut = new HelpText ( new HeadingInfo ( "CommandLine.Tests.dll" , "1.9.4.131" ) ) ;
213+ var sut = new HelpText ( headingInfo ) ;
209214 sut . MaximumDisplayWidth = 40 ;
210215 sut . AddOptions (
211216 new NotParsed < Simple_Options_With_HelpText_Set_To_Long_Description_Without_Spaces > (
@@ -739,5 +744,66 @@ public void Options_should_be_separated_by_spaces()
739744
740745 // Teardown
741746 }
747+
748+ [ Fact ]
749+ public void Options_Should_Render_OptionGroup_In_Parenthesis_When_Available ( )
750+ {
751+ var sut = new HelpText ( headingInfo ) { AddDashesToOption = true , MaximumDisplayWidth = 100 }
752+ . AddOptions (
753+ new NotParsed < Simple_Options_With_OptionGroup > ( TypeInfo . Create ( typeof ( Simple_Options_With_OptionGroup ) ) , Enumerable . Empty < Error > ( ) ) ) ;
754+
755+ var text = sut . ToString ( ) ;
756+ var lines = text . ToLines ( ) . TrimStringArray ( ) ;
757+
758+
759+ lines [ 0 ] . Should ( ) . BeEquivalentTo ( headingInfo . ToString ( ) ) ;
760+ lines [ 1 ] . Should ( ) . BeEmpty ( ) ;
761+ lines [ 2 ] . Should ( ) . BeEquivalentTo ( "--stringvalue (Group: string-group) Define a string value here." ) ;
762+ lines [ 3 ] . Should ( ) . BeEquivalentTo ( "-s, --shortandlong (Group: string-group) Example with both short and long name." ) ;
763+ lines [ 4 ] . Should ( ) . BeEquivalentTo ( "-x Define a boolean or switch value here." ) ;
764+ lines [ 5 ] . Should ( ) . BeEquivalentTo ( "--help Display this help screen." ) ;
765+ lines [ 6 ] . Should ( ) . BeEquivalentTo ( "--version Display version information." ) ;
766+ }
767+
768+ [ Fact ]
769+ public void Options_Should_Render_OptionGroup_When_Available_And_Should_Not_Render_Required ( )
770+ {
771+ var sut = new HelpText ( headingInfo ) { AddDashesToOption = true , MaximumDisplayWidth = 100 }
772+ . AddOptions (
773+ new NotParsed < Simple_Options_With_Required_OptionGroup > ( TypeInfo . Create ( typeof ( Simple_Options_With_Required_OptionGroup ) ) , Enumerable . Empty < Error > ( ) ) ) ;
774+
775+ var text = sut . ToString ( ) ;
776+ var lines = text . ToLines ( ) . TrimStringArray ( ) ;
777+
778+
779+ lines [ 0 ] . Should ( ) . BeEquivalentTo ( headingInfo . ToString ( ) ) ;
780+ lines [ 1 ] . Should ( ) . BeEmpty ( ) ;
781+ lines [ 2 ] . Should ( ) . BeEquivalentTo ( "--stringvalue (Group: string-group) Define a string value here." ) ;
782+ lines [ 3 ] . Should ( ) . BeEquivalentTo ( "-s, --shortandlong (Group: string-group) Example with both short and long name." ) ;
783+ lines [ 4 ] . Should ( ) . BeEquivalentTo ( "-x Define a boolean or switch value here." ) ;
784+ lines [ 5 ] . Should ( ) . BeEquivalentTo ( "--help Display this help screen." ) ;
785+ lines [ 6 ] . Should ( ) . BeEquivalentTo ( "--version Display version information." ) ;
786+ }
787+
788+ [ Fact ]
789+ public void Options_Should_Render_Multiple_OptionGroups_When_Available ( )
790+ {
791+ var sut = new HelpText ( headingInfo ) { AddDashesToOption = true , MaximumDisplayWidth = 100 }
792+ . AddOptions (
793+ new NotParsed < Simple_Options_With_Multiple_OptionGroups > ( TypeInfo . Create ( typeof ( Simple_Options_With_Multiple_OptionGroups ) ) , Enumerable . Empty < Error > ( ) ) ) ;
794+
795+ var text = sut . ToString ( ) ;
796+ var lines = text . ToLines ( ) . TrimStringArray ( ) ;
797+
798+
799+ lines [ 0 ] . Should ( ) . BeEquivalentTo ( headingInfo . ToString ( ) ) ;
800+ lines [ 1 ] . Should ( ) . BeEmpty ( ) ;
801+ lines [ 2 ] . Should ( ) . BeEquivalentTo ( "--stringvalue (Group: string-group) Define a string value here." ) ;
802+ lines [ 3 ] . Should ( ) . BeEquivalentTo ( "-s, --shortandlong (Group: string-group) Example with both short and long name." ) ;
803+ lines [ 4 ] . Should ( ) . BeEquivalentTo ( "-x (Group: second-group) Define a boolean or switch value here." ) ;
804+ lines [ 5 ] . Should ( ) . BeEquivalentTo ( "-i (Group: second-group) Define a int sequence here." ) ;
805+ lines [ 6 ] . Should ( ) . BeEquivalentTo ( "--help Display this help screen." ) ;
806+ lines [ 7 ] . Should ( ) . BeEquivalentTo ( "--version Display version information." ) ;
807+ }
742808 }
743809}
0 commit comments