@@ -711,3 +711,155 @@ func TestRemoveFromSlice(t *testing.T) {
711711 })
712712 }
713713}
714+
715+ func TestFormatStringSlice (t * testing.T ) {
716+ tests := []struct {
717+ name string
718+ input []string
719+ expected string
720+ }{
721+ {"empty" , nil , "[]" },
722+ {"empty slice" , []string {}, "[]" },
723+ {"single" , []string {"zoxide" }, `["zoxide"]` },
724+ {"multiple" , []string {"zoxide" , "direnv" }, `["zoxide", "direnv"]` },
725+ {"three" , []string {"a" , "b" , "c" }, `["a", "b", "c"]` },
726+ }
727+
728+ for _ , tt := range tests {
729+ t .Run (tt .name , func (t * testing.T ) {
730+ result := formatStringSlice (tt .input )
731+ if result != tt .expected {
732+ t .Errorf ("formatStringSlice(%v) = %q, want %q" , tt .input , result , tt .expected )
733+ }
734+ })
735+ }
736+ }
737+
738+ func TestJoinStrings (t * testing.T ) {
739+ tests := []struct {
740+ name string
741+ input []string
742+ sep string
743+ expected string
744+ }{
745+ {"empty" , nil , ", " , "" },
746+ {"single" , []string {"a" }, ", " , "a" },
747+ {"two" , []string {"a" , "b" }, ", " , "a, b" },
748+ {"custom sep" , []string {"x" , "y" , "z" }, "-" , "x-y-z" },
749+ }
750+
751+ for _ , tt := range tests {
752+ t .Run (tt .name , func (t * testing.T ) {
753+ result := joinStrings (tt .input , tt .sep )
754+ if result != tt .expected {
755+ t .Errorf ("joinStrings(%v, %q) = %q, want %q" , tt .input , tt .sep , result , tt .expected )
756+ }
757+ })
758+ }
759+ }
760+
761+ func TestGenerateHooksSection (t * testing.T ) {
762+ tests := []struct {
763+ name string
764+ selections IntegrationSelections
765+ contains []string
766+ absent []string
767+ }{
768+ {
769+ "no integrations" ,
770+ IntegrationSelections {},
771+ []string {"# [hooks]" , "# post_clone = []" },
772+ []string {"\n [hooks]\n " },
773+ },
774+ {
775+ "zoxide only" ,
776+ IntegrationSelections {Zoxide : true },
777+ []string {"[hooks]\n " , `post_clone = ["zoxide"]` , `post_add = ["zoxide"]` },
778+ []string {"# [hooks]" },
779+ },
780+ {
781+ "github only" ,
782+ IntegrationSelections {GitHub : true },
783+ []string {"[hooks]\n " , `post_clone = ["gh-default"]` , "post_add = []" },
784+ nil ,
785+ },
786+ {
787+ "direnv only" ,
788+ IntegrationSelections {Direnv : true },
789+ []string {"[hooks]\n " , "post_clone = []" , `post_add = ["direnv"]` },
790+ nil ,
791+ },
792+ {
793+ "all integrations" ,
794+ IntegrationSelections {Zoxide : true , GitHub : true , Direnv : true },
795+ []string {`post_clone = ["zoxide", "gh-default"]` , `post_add = ["zoxide", "direnv"]` },
796+ nil ,
797+ },
798+ }
799+
800+ for _ , tt := range tests {
801+ t .Run (tt .name , func (t * testing.T ) {
802+ result := generateHooksSection (tt .selections )
803+ for _ , s := range tt .contains {
804+ if ! strings .Contains (result , s ) {
805+ t .Errorf ("expected %q to contain %q" , result , s )
806+ }
807+ }
808+ for _ , s := range tt .absent {
809+ if strings .Contains (result , s ) {
810+ t .Errorf ("expected %q to NOT contain %q" , result , s )
811+ }
812+ }
813+ })
814+ }
815+ }
816+
817+ func TestGenerateWorkflowsSection (t * testing.T ) {
818+ tests := []struct {
819+ name string
820+ selections IntegrationSelections
821+ contains []string
822+ }{
823+ {
824+ "no extras" ,
825+ IntegrationSelections {},
826+ []string {"[workflows.feature]" , "[workflows.bugfix]" , "github-issue" , "post_add = []" },
827+ },
828+ {
829+ "with direnv and zoxide" ,
830+ IntegrationSelections {Direnv : true , Zoxide : true },
831+ []string {`post_add = ["direnv", "zoxide"]` , "[workflows.feature]" , "[workflows.bugfix]" },
832+ },
833+ }
834+
835+ for _ , tt := range tests {
836+ t .Run (tt .name , func (t * testing.T ) {
837+ result := generateWorkflowsSection (tt .selections )
838+ for _ , s := range tt .contains {
839+ if ! strings .Contains (result , s ) {
840+ t .Errorf ("expected %q to contain %q" , result , s )
841+ }
842+ }
843+ })
844+ }
845+ }
846+
847+ func TestGenerateConfigWithIntegrations (t * testing.T ) {
848+ // No integrations - should have commented hooks, no workflows
849+ plain := GenerateConfigWithIntegrations (IntegrationSelections {})
850+ if ! strings .Contains (plain , "# [hooks]" ) {
851+ t .Error ("expected commented hooks section" )
852+ }
853+ if strings .Contains (plain , "[workflows." ) {
854+ t .Error ("expected no workflows section without GitHub" )
855+ }
856+
857+ // With GitHub - should have workflows section
858+ withGH := GenerateConfigWithIntegrations (IntegrationSelections {GitHub : true })
859+ if ! strings .Contains (withGH , "[workflows.feature]" ) {
860+ t .Error ("expected workflows section with GitHub enabled" )
861+ }
862+ if ! strings .Contains (withGH , "[workflows.bugfix]" ) {
863+ t .Error ("expected bugfix workflow with GitHub enabled" )
864+ }
865+ }
0 commit comments