From ab8f18333f5ec224c80980fd9770ad510ec82bd7 Mon Sep 17 00:00:00 2001 From: KitsuneSemCalda Date: Sun, 25 Aug 2024 16:41:22 -0300 Subject: [PATCH] impl (Argparse): Enable goanime compatibility --- internal/Argparse/parser.go | 3 +- internal/Argparse/parser_test.go | 51 ++++++++++++++++++++++---------- internal/Argparse/types.go | 3 +- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/internal/Argparse/parser.go b/internal/Argparse/parser.go index 6f70294..a0fd47f 100644 --- a/internal/Argparse/parser.go +++ b/internal/Argparse/parser.go @@ -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:]) diff --git a/internal/Argparse/parser_test.go b/internal/Argparse/parser_test.go index 15a7ac7..df0dd61 100644 --- a/internal/Argparse/parser_test.go +++ b/internal/Argparse/parser_test.go @@ -7,10 +7,11 @@ 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 @@ -18,22 +19,39 @@ func MockParse(fs *flag.FlagSet, args []string) (argparse.Args, error) { 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, }, } @@ -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) } }) } diff --git a/internal/Argparse/types.go b/internal/Argparse/types.go index ef69af8..5e5cee3 100644 --- a/internal/Argparse/types.go +++ b/internal/Argparse/types.go @@ -1,5 +1,6 @@ package argparse type Args struct { - Debug bool + Debug bool + Gac bool }