From c1e642508f3bedf0a2677256b92955f093d6c20b Mon Sep 17 00:00:00 2001 From: halprin Date: Sat, 24 Aug 2024 13:25:04 -0600 Subject: [PATCH] Add more tests --- internal/generator/generator_test.go | 25 ++++++++++++++++++++++++- internal/helper/type.go | 7 ------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/internal/generator/generator_test.go b/internal/generator/generator_test.go index f4e8bac..3bdc28e 100644 --- a/internal/generator/generator_test.go +++ b/internal/generator/generator_test.go @@ -2,6 +2,7 @@ package generator import ( "github.com/stretchr/testify/assert" + "slices" "testing" ) @@ -120,7 +121,7 @@ func TestMapNotPanicsGivenMap(t *testing.T) { assert.NotPanics(t, func() { FromMap(map[string]int{ "DogCow": 1, - "Moof": 1976, + "Moof": 1976, }) }) } @@ -145,6 +146,28 @@ func TestMapEndsWithError(t *testing.T) { assert.ErrorIs(err, Exhausted) } +func TestFromIteratorWithLastTimeError(t *testing.T) { + assert := assert.New(t) + + generator := FromIterator(slices.Values([]interface{}{9})) + + _, err := generator() + + assert.NoError(err) + + _, err = generator() + + assert.ErrorIs(err, Exhausted) +} + +func TestFromIteratorEmpty(t *testing.T) { + generator := FromIterator(slices.Values([]interface{}{})) + + _, err := generator() + + assert.ErrorIs(t, err, Exhausted) +} + func createTestChannel(size int) chan interface{} { intChannel := make(chan interface{}) diff --git a/internal/helper/type.go b/internal/helper/type.go index d42d88a..5c40b4a 100644 --- a/internal/helper/type.go +++ b/internal/helper/type.go @@ -1,7 +1,6 @@ package helper import ( - "iter" "reflect" ) @@ -24,9 +23,3 @@ func IsMap(value interface{}) bool { concreteValue := reflect.ValueOf(value) return concreteValue.Kind() == reflect.Map } - -func IsIterator(value interface{}) bool { - _, ok := value.(iter.Seq[any]) - - return ok -}