44 "os"
55 "testing"
66
7- base "github.com/fabianoflorentino/aprendago/pkg/base_content "
7+ "github.com/fabianoflorentino/aprendago/pkg/format "
88)
99
1010func TestMenu (t * testing.T ) {
@@ -23,38 +23,16 @@ func TestMenu(t *testing.T) {
2323
2424 t .Run ("TestMenuOptionsLengthAndContent" , func (t * testing.T ) {
2525 // Create a slice of MenuOptions.
26- menuOptions := Menu (
27- []string {
28- flagArray ,
29- flagSliceLiteralComposta ,
30- flagSliceForRange ,
31- flagSliceFatiandoOuDeletando ,
32- flagSliceAnexando ,
33- flagSliceMake ,
34- flagSliceMultiDimensional ,
35- flagSliceSurpresaArraySubjacente ,
36- flagMapsIntroducao ,
37- })
26+ mo := menuOptions (topics )
3827
3928 // Check if the menuOptions slice has the expected length.
40- if len (menuOptions ) != 10 {
41- t .Errorf ("Expected menuOptions length of 10, got %v" , len (menuOptions ))
29+ if len (mo ) != 10 {
30+ t .Errorf ("Expected menuOptions length of 10, got %v" , len (mo ))
4231 }
4332 })
4433
4534 t .Run ("TestMenuOptionsContent" , func (t * testing.T ) {
46- menuOptions := Menu (
47- []string {
48- flagArray ,
49- flagSliceLiteralComposta ,
50- flagSliceForRange ,
51- flagSliceFatiandoOuDeletando ,
52- flagSliceAnexando ,
53- flagSliceMake ,
54- flagSliceMultiDimensional ,
55- flagSliceSurpresaArraySubjacente ,
56- flagMapsIntroducao ,
57- })
35+ mo := menuOptions (topics )
5836
5937 expectedOptions := []string {
6038 "--array" ,
@@ -69,54 +47,28 @@ func TestMenu(t *testing.T) {
6947 "--maps-range-e-deletando" ,
7048 }
7149
72- for i , option := range menuOptions {
50+ for i , option := range mo {
7351 if option .Options != expectedOptions [i ] {
7452 t .Errorf ("Expected option %v to be %v, got %v" , i , expectedOptions [i ], option .Options )
7553 }
7654 }
7755 })
7856
79- t .Run ("TestMenuOptionsExecutionFunctions" , func (t * testing.T ) {
80- menuOptions := Menu (
81- []string {
82- flagArray ,
83- flagSliceLiteralComposta ,
84- flagSliceForRange ,
85- flagSliceFatiandoOuDeletando ,
86- flagSliceAnexando ,
87- flagSliceMake ,
88- flagSliceMultiDimensional ,
89- flagSliceSurpresaArraySubjacente ,
90- flagMapsIntroducao ,
91- })
57+ t .Run ("TestMenuOptionsExecFunc" , func (t * testing.T ) {
58+ mo := menuOptions (topics )
9259
93- for i , option := range menuOptions {
94- if option .ExecFunc == nil {
95- t .Errorf ("Expected option %v to have a non-nil execution function" , i )
96- }
97- }
98-
99- m := base .New ()
100- newExecFunc := []func (){
101- func () { m .SectionFormat (array , m .SectionFactory (rootDir )) },
102- func () { m .SectionFormat (sliceLiteralComposta , m .SectionFactory (rootDir )) },
103- func () { m .SectionFormat (sliceForRange , m .SectionFactory (rootDir )) },
104- func () { m .SectionFormat (sliceFatiandoOuDeletando , m .SectionFactory (rootDir )) },
105- func () { m .SectionFormat (sliceAnexando , m .SectionFactory (rootDir )) },
106- func () { m .SectionFormat (sliceMake , m .SectionFactory (rootDir )) },
107- func () { m .SectionFormat (sliceMultiDimensional , m .SectionFactory (rootDir )) },
108- func () { m .SectionFormat (sliceSurpresaArraySubjacente , m .SectionFactory (rootDir )) },
109- func () { m .SectionFormat (mapsIntroducao , m .SectionFactory (rootDir )) },
110- func () { m .SectionFormat (mapsRangeEDeletando , m .SectionFactory (rootDir )) },
60+ if len (mo ) != 10 {
61+ t .Fatalf ("Expected menuOptions length of 10, got %v" , len (mo ))
11162 }
11263
113- for i , execFunc := range newExecFunc {
114- if menuOptions [i ].ExecFunc == nil || execFunc == nil {
115- t .Errorf ("Execution function for option %v is nil" , i )
116- } else {
117- menuOptions [i ].ExecFunc ()
118- execFunc ()
64+ for i , option := range mo {
65+ if option .ExecFunc == nil {
66+ t .Errorf ("Expected ExecFunc for option %v to be non-nil" , i )
11967 }
12068 }
12169 })
12270}
71+
72+ func menuOptions (listMenu []string ) []format.MenuOptions {
73+ return Menu (listMenu )
74+ }
0 commit comments