summaryrefslogtreecommitdiff
path: root/sequence_test.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2021-04-19 13:48:07 -0700
committerAlex Flint <[email protected]>2021-04-19 13:48:07 -0700
commit0100c0a411486a0a26c0d7bb5504c5f371aaf6b0 (patch)
treed835b18323c76cbb220ac501b17f7d7e9607d6a8 /sequence_test.go
parentbb4e7fd4b043a52259d517c8ad6b068466b55f08 (diff)
push code coverage up
Diffstat (limited to 'sequence_test.go')
-rw-r--r--sequence_test.go44
1 files changed, 42 insertions, 2 deletions
diff --git a/sequence_test.go b/sequence_test.go
index 446bc42..dd866c6 100644
--- a/sequence_test.go
+++ b/sequence_test.go
@@ -16,7 +16,7 @@ func TestSetSliceWithoutClearing(t *testing.T) {
assert.Equal(t, []int{10, 1, 2, 3}, xs)
}
-func TestSetSliceWithClear(t *testing.T) {
+func TestSetSliceAfterClearing(t *testing.T) {
xs := []int{100}
entries := []string{"1", "2", "3"}
err := setSlice(reflect.ValueOf(&xs).Elem(), entries, true)
@@ -24,6 +24,13 @@ func TestSetSliceWithClear(t *testing.T) {
assert.Equal(t, []int{1, 2, 3}, xs)
}
+func TestSetSliceInvalid(t *testing.T) {
+ xs := []int{100}
+ entries := []string{"invalid"}
+ err := setSlice(reflect.ValueOf(&xs).Elem(), entries, true)
+ assert.Error(t, err)
+}
+
func TestSetSlicePtr(t *testing.T) {
var xs []*int
entries := []string{"1", "2", "3"}
@@ -58,7 +65,7 @@ func TestSetMapWithoutClearing(t *testing.T) {
assert.Equal(t, 10, m["foo"])
}
-func TestSetMapWithClear(t *testing.T) {
+func TestSetMapAfterClearing(t *testing.T) {
m := map[string]int{"foo": 10}
entries := []string{"a=1", "b=2"}
err := setMap(reflect.ValueOf(&m).Elem(), entries, true)
@@ -68,6 +75,25 @@ func TestSetMapWithClear(t *testing.T) {
assert.Equal(t, 2, m["b"])
}
+func TestSetMapWithKeyPointer(t *testing.T) {
+ // textUnmarshaler is a struct that captures the length of the string passed to it
+ var m map[*string]int
+ entries := []string{"abc=123"}
+ err := setMap(reflect.ValueOf(&m).Elem(), entries, true)
+ require.NoError(t, err)
+ require.Len(t, m, 1)
+}
+
+func TestSetMapWithValuePointer(t *testing.T) {
+ // textUnmarshaler is a struct that captures the length of the string passed to it
+ var m map[string]*int
+ entries := []string{"abc=123"}
+ err := setMap(reflect.ValueOf(&m).Elem(), entries, true)
+ require.NoError(t, err)
+ require.Len(t, m, 1)
+ assert.Equal(t, 123, *m["abc"])
+}
+
func TestSetMapTextUnmarshaller(t *testing.T) {
// textUnmarshaler is a struct that captures the length of the string passed to it
var m map[textUnmarshaler]*textUnmarshaler
@@ -80,6 +106,20 @@ func TestSetMapTextUnmarshaller(t *testing.T) {
assert.Equal(t, &textUnmarshaler{1}, m[textUnmarshaler{3}])
}
+func TestSetMapInvalidKey(t *testing.T) {
+ var m map[int]int
+ entries := []string{"invalid=123"}
+ err := setMap(reflect.ValueOf(&m).Elem(), entries, true)
+ assert.Error(t, err)
+}
+
+func TestSetMapInvalidValue(t *testing.T) {
+ var m map[int]int
+ entries := []string{"123=invalid"}
+ err := setMap(reflect.ValueOf(&m).Elem(), entries, true)
+ assert.Error(t, err)
+}
+
func TestSetMapMalformed(t *testing.T) {
// textUnmarshaler is a struct that captures the length of the string passed to it
var m map[string]string