Skip to content

Commit

Permalink
impl (Argparse): Enable goanime compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneSemCalda committed Aug 25, 2024
1 parent 083e8c6 commit ab8f183
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
3 changes: 2 additions & 1 deletion internal/Argparse/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
func Parse(fs *flag.FlagSet) (Args, error) {
argv := Args{}

fs.BoolVar(&argv.Debug, "debug", false, "this flag is used enable debug mode")
fs.BoolVar(&argv.Debug, "debug", false, "this flag is used to enable debug mode")
fs.BoolVar(&argv.Gac, "gac", false, "this flag is used to enable goanime compatibility")

err := fs.Parse(os.Args[1:])

Expand Down
51 changes: 36 additions & 15 deletions internal/Argparse/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,51 @@ import (
"animatic-v2/internal/Argparse"
)

// Parse is used to create a testable interface from load arguments from CLI
// MockParse é usado para criar uma interface testável a partir dos argumentos da CLI
func MockParse(fs *flag.FlagSet, args []string) (argparse.Args, error) {
argv := argparse.Args{}
fs.BoolVar(&argv.Debug, "debug", false, "use this flag to enable debug mode")
fs.BoolVar(&argv.Gac, "gac", false, "use this flag to enable goanime compatibility")

err := fs.Parse(args)
return argv, err
}

func TestParse(t *testing.T) {
tests := []struct {
name string
args []string
want bool
wantErr bool
name string
args []string
wantDebug bool
wantGac bool
wantErr bool
}{
{
name: "Test with debug flag set to true",
args: []string{"-debug"},
want: true,
wantErr: false,
name: "Test with debug flag set to true",
args: []string{"-debug"},
wantDebug: true,
wantGac: false,
wantErr: false,
},
{
name: "Test with debug flag set to false",
args: []string{},
want: false,
wantErr: false,
name: "Test with debug flag set to false",
args: []string{},
wantDebug: false,
wantGac: false,
wantErr: false,
},
{
name: "Test with gac flag set to true",
args: []string{"-gac"},
wantDebug: false,
wantGac: true,
wantErr: false,
},
{
name: "Test with gac flag set to false",
args: []string{},
wantDebug: false,
wantGac: false,
wantErr: false,
},
}

Expand All @@ -45,8 +63,11 @@ func TestParse(t *testing.T) {
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got.Debug != tt.want {
t.Errorf("Parse() got = %v, want %v", got.Debug, tt.want)
if got.Debug != tt.wantDebug {
t.Errorf("Parse() got.Debug = %v, want %v", got.Debug, tt.wantDebug)
}
if got.Gac != tt.wantGac {
t.Errorf("Parse() got.Gac = %v, want %v", got.Gac, tt.wantGac)
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion internal/Argparse/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package argparse

type Args struct {
Debug bool
Debug bool
Gac bool
}

0 comments on commit ab8f183

Please sign in to comment.