Skip to content

Commit bd2dbcd

Browse files
author
Jose Quintana
committed
test: provided input flags
tests for following functions: - IsProvidedFlag - IsLongProvidedFlag - IsShortProvidedFlag
1 parent 966d25e commit bd2dbcd

File tree

2 files changed

+191
-1
lines changed

2 files changed

+191
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cline [![Build Status](https://travis-ci.com/joseluisq/cline.svg?branch=master)](https://travis-ci.com/joseluisq/cline) [![codecov](https://codecov.io/gh/joseluisq/cline/branch/master/graph/badge.svg)](https://codecov.io/gh/joseluisq/cline) [![Go Report Card](https://goreportcard.com/badge/github.com/joseluisq/cline)](https://goreportcard.com/report/github.com/joseluisq/cline) [![GoDoc](https://godoc.org/github.com/joseluisq/cline?status.svg)](https://pkg.go.dev/github.com/joseluisq/cline)
1+
# CLIne [![Build Status](https://travis-ci.com/joseluisq/cline.svg?branch=master)](https://travis-ci.com/joseluisq/cline) [![codecov](https://codecov.io/gh/joseluisq/cline/branch/master/graph/badge.svg)](https://codecov.io/gh/joseluisq/cline) [![Go Report Card](https://goreportcard.com/badge/github.com/joseluisq/cline)](https://goreportcard.com/report/github.com/joseluisq/cline) [![GoDoc](https://godoc.org/github.com/joseluisq/cline?status.svg)](https://pkg.go.dev/github.com/joseluisq/cline)
22

33
> A fast and lightweight CLI package for Go without external dependencies.
44

flag_values_test.go

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,193 @@ func TestFlagMapInput_GetProvidedFlags(t *testing.T) {
564564
})
565565
}
566566
}
567+
568+
func TestFlagMapping_IsProvidedFlag(t *testing.T) {
569+
type fields struct {
570+
zFlags []Flag
571+
zFlagsProvided []FlagProvided
572+
}
573+
type args struct {
574+
flagName string
575+
}
576+
tests := []struct {
577+
name string
578+
fields fields
579+
args args
580+
want bool
581+
}{
582+
{
583+
name: "not provided flag",
584+
fields: fields{
585+
zFlags: []Flag{
586+
FlagInt{Name: "int", Aliases: []string{"i"}},
587+
},
588+
},
589+
args: args{
590+
flagName: "int",
591+
},
592+
},
593+
{
594+
name: "provided flag",
595+
fields: fields{
596+
zFlags: []Flag{
597+
FlagBool{Name: "bool", Aliases: []string{"b"}},
598+
},
599+
zFlagsProvided: []FlagProvided{
600+
{Name: "bool"},
601+
},
602+
},
603+
args: args{
604+
flagName: "bool",
605+
},
606+
want: true,
607+
},
608+
}
609+
for _, tt := range tests {
610+
t.Run(tt.name, func(t *testing.T) {
611+
fm := &FlagMapping{
612+
zFlags: tt.fields.zFlags,
613+
zFlagsProvided: tt.fields.zFlagsProvided,
614+
}
615+
if got := fm.IsProvidedFlag(tt.args.flagName); got != tt.want {
616+
t.Errorf("FlagMapping.IsProvidedFlag() = %v, want %v", got, tt.want)
617+
}
618+
})
619+
}
620+
}
621+
622+
func TestFlagMapping_IsLongProvidedFlag(t *testing.T) {
623+
type fields struct {
624+
zFlags []Flag
625+
zFlagsProvided []FlagProvided
626+
}
627+
type args struct {
628+
flagName string
629+
}
630+
tests := []struct {
631+
name string
632+
fields fields
633+
args args
634+
want bool
635+
}{
636+
{
637+
name: "not provided flag",
638+
fields: fields{
639+
zFlags: []Flag{
640+
FlagInt{Name: "int", Aliases: []string{"i"}},
641+
},
642+
},
643+
args: args{
644+
flagName: "int",
645+
},
646+
},
647+
{
648+
name: "provided long name flag",
649+
fields: fields{
650+
zFlags: []Flag{
651+
FlagBool{Name: "bool", Aliases: []string{"b"}},
652+
},
653+
zFlagsProvided: []FlagProvided{
654+
{Name: "bool"},
655+
},
656+
},
657+
args: args{
658+
flagName: "bool",
659+
},
660+
want: true,
661+
},
662+
{
663+
name: "provided short name flag (alias)",
664+
fields: fields{
665+
zFlags: []Flag{
666+
FlagBool{Name: "int", Aliases: []string{"b"}},
667+
},
668+
zFlagsProvided: []FlagProvided{
669+
{Name: "int", IsAlias: true},
670+
},
671+
},
672+
args: args{
673+
flagName: "int",
674+
},
675+
},
676+
}
677+
for _, tt := range tests {
678+
t.Run(tt.name, func(t *testing.T) {
679+
fm := &FlagMapping{
680+
zFlags: tt.fields.zFlags,
681+
zFlagsProvided: tt.fields.zFlagsProvided,
682+
}
683+
if got := fm.IsLongProvidedFlag(tt.args.flagName); got != tt.want {
684+
t.Errorf("FlagMapping.IsLongProvidedFlag() = %v, want %v", got, tt.want)
685+
}
686+
})
687+
}
688+
}
689+
690+
func TestFlagMapping_IsShortProvidedFlag(t *testing.T) {
691+
type fields struct {
692+
zFlags []Flag
693+
zFlagsProvided []FlagProvided
694+
}
695+
type args struct {
696+
flagName string
697+
}
698+
tests := []struct {
699+
name string
700+
fields fields
701+
args args
702+
want bool
703+
}{
704+
{
705+
name: "not provided flag",
706+
fields: fields{
707+
zFlags: []Flag{
708+
FlagStringSlice{Name: "strs", Aliases: []string{"s"}},
709+
},
710+
},
711+
args: args{
712+
flagName: "strs",
713+
},
714+
},
715+
{
716+
name: "provided long name flag",
717+
fields: fields{
718+
zFlags: []Flag{
719+
FlagString{Name: "str", Aliases: []string{"s"}},
720+
},
721+
zFlagsProvided: []FlagProvided{
722+
{Name: "str"},
723+
},
724+
},
725+
args: args{
726+
flagName: "str",
727+
},
728+
},
729+
{
730+
name: "provided short name flag (alias)",
731+
fields: fields{
732+
zFlags: []Flag{
733+
FlagBool{Name: "int", Aliases: []string{"i"}},
734+
},
735+
zFlagsProvided: []FlagProvided{
736+
{Name: "int", IsAlias: true},
737+
},
738+
},
739+
args: args{
740+
flagName: "int",
741+
},
742+
want: true,
743+
},
744+
}
745+
for _, tt := range tests {
746+
t.Run(tt.name, func(t *testing.T) {
747+
fm := &FlagMapping{
748+
zFlags: tt.fields.zFlags,
749+
zFlagsProvided: tt.fields.zFlagsProvided,
750+
}
751+
if got := fm.IsShortProvidedFlag(tt.args.flagName); got != tt.want {
752+
t.Errorf("FlagMapping.IsShortProvidedFlag() = %v, want %v", got, tt.want)
753+
}
754+
})
755+
}
756+
}

0 commit comments

Comments
 (0)