@@ -264,6 +264,60 @@ func TestSurveyIcons(t *testing.T) {
264264* Example commands
265265 */
266266
267+ func TestStyleFlags (t * testing.T ) {
268+ defer func () {
269+ ToggleStyles (false )
270+ ToggleCharm (false )
271+ }()
272+ ToggleStyles (true )
273+ ToggleCharm (true )
274+
275+ tests := map [string ]struct {
276+ input string
277+ expected string
278+ }{
279+ "short and long flag with type and description" : {
280+ input : " -s, --long string Description text" ,
281+ expected : Yellow (" -s, --long string " ) + Secondary ("Description text" ),
282+ },
283+ "long-only flag with description" : {
284+ input : " --verbose Enable verbose output" ,
285+ expected : Yellow (" --verbose " ) + Secondary ("Enable verbose output" ),
286+ },
287+ "plain text without flag pattern returned unchanged" : {
288+ input : "some plain text" ,
289+ expected : "some plain text" ,
290+ },
291+ "empty string returned unchanged" : {
292+ input : "" ,
293+ expected : "" ,
294+ },
295+ "multiline flag output" : {
296+ input : " -a, --all Show all\n --verbose Enable verbose" ,
297+ expected : Yellow (" -a, --all " ) + Secondary ("Show all" ) + "\n " + Yellow (" --verbose " ) + Secondary ("Enable verbose" ),
298+ },
299+ }
300+ for name , tc := range tests {
301+ t .Run (name , func (t * testing.T ) {
302+ actual := StyleFlags (tc .input )
303+ assert .Equal (t , tc .expected , actual )
304+ })
305+ }
306+ }
307+
308+ func TestStyleFlags_CharmDisabled (t * testing.T ) {
309+ defer func () {
310+ ToggleStyles (false )
311+ ToggleCharm (false )
312+ }()
313+ ToggleStyles (false )
314+ ToggleCharm (false )
315+
316+ input := " -s, --long string Description text"
317+ actual := StyleFlags (input )
318+ assert .Equal (t , input , actual )
319+ }
320+
267321func Test_ExampleCommandsf (t * testing.T ) {
268322 tests := map [string ]struct {
269323 name string
@@ -365,6 +419,67 @@ func Test_ExampleTemplatef(t *testing.T) {
365419 }
366420}
367421
422+ func Test_styleExampleLine (t * testing.T ) {
423+ defer func () {
424+ ToggleStyles (false )
425+ ToggleCharm (false )
426+ }()
427+ ToggleStyles (true )
428+ ToggleCharm (true )
429+
430+ tests := map [string ]struct {
431+ input string
432+ expected string
433+ }{
434+ "full-line comment is styled as secondary" : {
435+ input : "# Create a new project" ,
436+ expected : Secondary ("# Create a new project" ),
437+ },
438+ "command with inline comment splits styling" : {
439+ input : "$ slack create # Create a project" ,
440+ expected : Yellow ("$ " ) + CommandText ("slack create" ) + Secondary (" # Create a project" ),
441+ },
442+ "command without comment is styled as command" : {
443+ input : "$ slack create my-app" ,
444+ expected : Yellow ("$ " ) + CommandText ("slack create my-app" ),
445+ },
446+ "plain text without prefix is returned as-is" : {
447+ input : "some other text" ,
448+ expected : "some other text" ,
449+ },
450+ }
451+ for name , tc := range tests {
452+ t .Run (name , func (t * testing.T ) {
453+ actual := styleExampleLine (tc .input )
454+ assert .Equal (t , tc .expected , actual )
455+ })
456+ }
457+ }
458+
459+ func Test_ExampleTemplatef_Charm (t * testing.T ) {
460+ defer func () {
461+ ToggleStyles (false )
462+ ToggleCharm (false )
463+ }()
464+ ToggleStyles (true )
465+ ToggleCharm (true )
466+
467+ template := []string {
468+ "# Create a new project from a selected template" ,
469+ "$ slack create" ,
470+ "" ,
471+ "$ slack create my-project -t sample/repo-url # Create a named project" ,
472+ }
473+ expected := []string {
474+ fmt .Sprintf (" %s" , Secondary ("# Create a new project from a selected template" )),
475+ fmt .Sprintf (" %s%s" , Yellow ("$ " ), CommandText ("slack create" )),
476+ "" ,
477+ fmt .Sprintf (" %s%s%s" , Yellow ("$ " ), CommandText ("slack create my-project -t sample/repo-url" ), Secondary (" # Create a named project" )),
478+ }
479+ actual := ExampleTemplatef (strings .Join (template , "\n " ))
480+ assert .Equal (t , strings .Join (expected , "\n " ), actual )
481+ }
482+
368483/*
369484* App name formatting
370485 */
0 commit comments