@@ -562,3 +562,67 @@ func TestHeight(t *testing.T) {
562562 }
563563 }
564564}
565+
566+ func TestHyperlink (t * testing.T ) {
567+ tests := []struct {
568+ name string
569+ style Style
570+ expected string
571+ }{
572+ {
573+ name : "hyperlink" ,
574+ style : NewStyle ().Hyperlink ("https://example.com" ).SetString ("https://example.com" ),
575+ expected : "\x1b ]8;;https://example.com\x07 https://example.com\x1b ]8;;\x07 " ,
576+ },
577+ {
578+ name : "hyperlink with text" ,
579+ style : NewStyle ().Hyperlink ("https://example.com" , "id=123" ).SetString ("example" ),
580+ expected : "\x1b ]8;id=123;https://example.com\x07 example\x1b ]8;;\x07 " ,
581+ },
582+ {
583+ name : "hyperlink with text and style" ,
584+ style : NewStyle ().Hyperlink ("https://example.com" , "id=123" ).SetString ("example" ).
585+ Bold (true ).Foreground (Color ("234" )),
586+ expected : "\x1b ]8;id=123;https://example.com\x07 \x1b [1;38;5;234mexample\x1b [m\x1b ]8;;\x07 " ,
587+ },
588+ }
589+ for _ , tc := range tests {
590+ t .Run (tc .name , func (t * testing.T ) {
591+ if tc .style .String () != tc .expected {
592+ t .Fatalf ("got: %q, want: %q" , tc .style .String (), tc .expected )
593+ }
594+ })
595+ }
596+ }
597+
598+ func TestUnsetHyperlink (t * testing.T ) {
599+ tests := []struct {
600+ name string
601+ style Style
602+ expected string
603+ }{
604+ {
605+ name : "unset hyperlink" ,
606+ style : NewStyle ().Hyperlink ("https://example.com" ).SetString ("https://example.com" ).UnsetHyperlink (),
607+ expected : "https://example.com" ,
608+ },
609+ {
610+ name : "unset hyperlink with text" ,
611+ style : NewStyle ().Hyperlink ("https://example.com" , "id=123" ).SetString ("example" ).UnsetHyperlink (),
612+ expected : "example" ,
613+ },
614+ {
615+ name : "unset hyperlink with text and style" ,
616+ style : NewStyle ().Hyperlink ("https://example.com" , "id=123" ).SetString ("example" ).
617+ Bold (true ).Foreground (Color ("234" )).UnsetHyperlink (),
618+ expected : "\x1b [1;38;5;234mexample\x1b [m" ,
619+ },
620+ }
621+ for _ , tc := range tests {
622+ t .Run (tc .name , func (t * testing.T ) {
623+ if tc .style .String () != tc .expected {
624+ t .Fatalf ("got: %q, want: %q" , tc .style .String (), tc .expected )
625+ }
626+ })
627+ }
628+ }
0 commit comments