Skip to content

Commit 2b4ebe8

Browse files
committed
tests: do a sequence lookup to test the iterator
1 parent 22065e3 commit 2b4ebe8

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

cli_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,37 @@ func TestOptLookups(t *testing.T) {
929929
}()
930930
}
931931
}
932+
933+
// with a bunch of option 'a' provided
934+
{
935+
c := in.ParseTheseOrExit("-a1", "-a2", "-a3")
936+
// use the iterator to break on "2" which should put
937+
// i at index 2 because option a has a default
938+
{
939+
var i int
940+
for v := range GetAllSeq[string](c, "a") {
941+
if v == "2" {
942+
break
943+
}
944+
i++
945+
}
946+
if i != 2 {
947+
t.Fatalf(`expected to break on "2" and be at index because of default`)
948+
}
949+
}
950+
// trying to cast the first one to anything but a string should panic
951+
{
952+
func() {
953+
defer func() {
954+
gotPanicVal := recover()
955+
if gotPanicVal == nil {
956+
t.Fatalf("didn't panic when trying to cast a string arg to an int")
957+
}
958+
}()
959+
_ = Get[int](c, "a")
960+
}()
961+
}
962+
}
932963
}
933964

934965
func TestArgLookups(t *testing.T) {

0 commit comments

Comments
 (0)