This commit is contained in:
Samuel Berthe
2026-03-01 22:19:36 +01:00
parent 7f0c2e0297
commit 6a9f881ae1
4 changed files with 142 additions and 142 deletions
+44 -44
View File
@@ -1040,7 +1040,7 @@ func ExampleFindErr() {
result, err = FindErr([]string{"a", "b", "c"}, func(i string) (bool, error) {
if i == "b" {
return false, fmt.Errorf("b is not allowed")
return false, errors.New("b is not allowed")
}
return i == "b", nil
})
@@ -1251,7 +1251,7 @@ func ExampleFindDuplicatesByErr() {
result, err := FindDuplicatesByErr(users, func(user User) (int, error) {
if user.Name == "Charlie" {
return 0, fmt.Errorf("charlie is not allowed")
return 0, errors.New("charlie is not allowed")
}
return user.Age, nil
})
@@ -1330,7 +1330,7 @@ func ExampleMinByErr() {
result, err := MinByErr(users, func(a, b User) (bool, error) {
if a.Name == "Bob" {
return false, fmt.Errorf("bob is not allowed")
return false, errors.New("bob is not allowed")
}
return a.Age < b.Age, nil
})
@@ -1373,7 +1373,7 @@ func ExampleMinIndexByErr() {
result, _, err := MinIndexByErr(users, func(a, b User) (bool, error) {
if a.Name == "Bob" {
return false, fmt.Errorf("bob is not allowed")
return false, errors.New("bob is not allowed")
}
return a.Age < b.Age, nil
})
@@ -1429,7 +1429,7 @@ func ExampleEarliestByErr() {
_, err := EarliestByErr(events, func(event Event) (time.Time, error) {
if event.Name == "Event B" {
return time.Time{}, fmt.Errorf("event b is not allowed")
return time.Time{}, errors.New("event b is not allowed")
}
return event.Time, nil
})
@@ -1508,7 +1508,7 @@ func ExampleMaxByErr() {
_, err := MaxByErr(users, func(a, b User) (bool, error) {
if b.Name == "Bob" {
return false, fmt.Errorf("bob is not allowed")
return false, errors.New("bob is not allowed")
}
return a.Age > b.Age, nil
})
@@ -1551,7 +1551,7 @@ func ExampleMaxIndexByErr() {
_, _, err := MaxIndexByErr(users, func(a, b User) (bool, error) {
if b.Name == "Bob" {
return false, fmt.Errorf("bob is not allowed")
return false, errors.New("bob is not allowed")
}
return a.Age > b.Age, nil
})
@@ -1602,7 +1602,7 @@ func ExampleLatestByErr() {
now := time.Now()
events := []Event{
{Name: "Event A", Time: now.Add(time.Hour), Err: nil},
{Name: "Event B", Time: now, Err: fmt.Errorf("event b error")},
{Name: "Event B", Time: now, Err: errors.New("event b error")},
{Name: "Event C", Time: now.Add(-time.Hour), Err: nil},
}
@@ -1835,7 +1835,7 @@ func ExampleWithoutByErr() {
// extract function to get the user ID
extractID := func(user User) (int, error) {
if user.ID == 2 {
return 0, fmt.Errorf("user 2 extraction failed")
return 0, errors.New("user 2 extraction failed")
}
return user.ID, nil
}
@@ -1917,7 +1917,7 @@ func ExamplePickByErr() {
_, err := PickByErr(kv, func(key string, value int) (bool, error) {
if key == "bar" {
return false, fmt.Errorf("key bar is not allowed")
return false, errors.New("key bar is not allowed")
}
return value%2 == 1, nil
})
@@ -1960,7 +1960,7 @@ func ExampleOmitByErr() {
_, err := OmitByErr(kv, func(key string, value int) (bool, error) {
if key == "bar" {
return false, fmt.Errorf("key bar is not allowed")
return false, errors.New("key bar is not allowed")
}
return value%2 == 1, nil
})
@@ -2074,7 +2074,7 @@ func ExampleMapKeysErr() {
_, err := MapKeysErr(kv, func(_, k int) (string, error) {
if k == 3 {
return "", fmt.Errorf("key 3 is not allowed")
return "", errors.New("key 3 is not allowed")
}
return strconv.FormatInt(int64(k), 10), nil
})
@@ -2099,7 +2099,7 @@ func ExampleMapValuesErr() {
_, err := MapValuesErr(kv, func(v, _ int) (string, error) {
if v == 3 {
return "", fmt.Errorf("value 3 is not allowed")
return "", errors.New("value 3 is not allowed")
}
return strconv.FormatInt(int64(v), 10), nil
})
@@ -2124,7 +2124,7 @@ func ExampleMapEntriesErr() {
_, err := MapEntriesErr(kv, func(k string, v int) (int, string, error) {
if k == "foo" {
return 0, "", fmt.Errorf("entry foo is not allowed")
return 0, "", errors.New("entry foo is not allowed")
}
return v, k, nil
})
@@ -2150,7 +2150,7 @@ func ExampleMapToSliceErr() {
_, err := MapToSliceErr(kv, func(k int, v int64) (string, error) {
if k == 3 {
return "", fmt.Errorf("key 3 is not allowed")
return "", errors.New("key 3 is not allowed")
}
return fmt.Sprintf("%d_%d", k, v), nil
})
@@ -2176,7 +2176,7 @@ func ExampleFilterMapToSliceErr() {
_, err := FilterMapToSliceErr(kv, func(k int, v int64) (string, bool, error) {
if k == 3 {
return "", false, fmt.Errorf("key 3 is not allowed")
return "", false, errors.New("key 3 is not allowed")
}
return fmt.Sprintf("%d_%d", k, v), k%2 == 0, nil
})
@@ -2212,7 +2212,7 @@ func ExampleFilterKeysErr() {
result, err := FilterKeysErr(kv, func(k int, v string) (bool, error) {
if k == 3 {
return false, fmt.Errorf("key 3 not allowed")
return false, errors.New("key 3 not allowed")
}
return v == "foo", nil
})
@@ -2232,7 +2232,7 @@ func ExampleFilterValuesErr() {
result, err := FilterValuesErr(kv, func(k int, v string) (bool, error) {
if k == 3 {
return false, fmt.Errorf("key 3 not allowed")
return false, errors.New("key 3 not allowed")
}
return v == "foo", nil
})
@@ -2315,7 +2315,7 @@ func ExampleSumByErr() {
_, err := SumByErr(list, func(item string) (int, error) {
if item == "bar" {
return 0, fmt.Errorf("bar is not allowed")
return 0, errors.New("bar is not allowed")
}
return len(item), nil
})
@@ -2349,7 +2349,7 @@ func ExampleProductByErr() {
_, err := ProductByErr(list, func(item string) (int, error) {
if item == "bar" {
return 0, fmt.Errorf("bar is not allowed")
return 0, errors.New("bar is not allowed")
}
return len(item), nil
})
@@ -2383,7 +2383,7 @@ func ExampleMeanByErr() {
_, err := MeanByErr(list, func(item string) (int, error) {
if item == "bar" {
return 0, fmt.Errorf("bar is not allowed")
return 0, errors.New("bar is not allowed")
}
return len(item), nil
})
@@ -2408,7 +2408,7 @@ func ExampleFilterErr() {
result, err := FilterErr(list, func(nbr int64, index int) (bool, error) {
if nbr == 3 {
return false, fmt.Errorf("number 3 is not allowed")
return false, errors.New("number 3 is not allowed")
}
return nbr%2 == 0, nil
})
@@ -2439,7 +2439,7 @@ func ExampleMapErr() {
_, err := MapErr(list, func(nbr int64, index int) (string, error) {
if nbr == 3 {
return "", fmt.Errorf("number 3 is not allowed")
return "", errors.New("number 3 is not allowed")
}
return strconv.FormatInt(nbr*2, 10), nil
})
@@ -2495,7 +2495,7 @@ func ExampleFlatMapErr() {
_, err := FlatMapErr(list, func(nbr int64, index int) ([]string, error) {
if nbr == 3 {
return nil, fmt.Errorf("number 3 is not allowed")
return nil, errors.New("number 3 is not allowed")
}
return []string{
strconv.FormatInt(nbr, 10), // base 10
@@ -2523,7 +2523,7 @@ func ExampleReduceErr() {
_, err := ReduceErr(list, func(agg, item int64, index int) (int64, error) {
if item == 3 {
return 0, fmt.Errorf("number 3 is not allowed")
return 0, errors.New("number 3 is not allowed")
}
return agg + item, nil
}, 0)
@@ -2548,7 +2548,7 @@ func ExampleReduceRightErr() {
_, err := ReduceRightErr(list, func(agg, item []int, index int) ([]int, error) {
if index == 0 {
return nil, fmt.Errorf("index 0 is not allowed")
return nil, errors.New("index 0 is not allowed")
}
return append(agg, item...), nil
}, []int{})
@@ -2621,7 +2621,7 @@ func ExampleUniqByErr() {
_, err := UniqByErr(list, func(i int) (int, error) {
if i == 3 {
return 0, fmt.Errorf("number 3 is not allowed")
return 0, errors.New("number 3 is not allowed")
}
return i % 3, nil
})
@@ -2651,7 +2651,7 @@ func ExampleGroupByErr() {
_, err := GroupByErr(list, func(i int) (int, error) {
if i == 3 {
return 0, fmt.Errorf("number 3 is not allowed")
return 0, errors.New("number 3 is not allowed")
}
return i % 3, nil
})
@@ -2681,7 +2681,7 @@ func ExampleGroupByMapErr() {
_, err := GroupByMapErr(list, func(i int) (int, int, error) {
if i == 3 {
return 0, 0, fmt.Errorf("number 3 is not allowed")
return 0, 0, errors.New("number 3 is not allowed")
}
return i % 3, i * 2, nil
})
@@ -2765,7 +2765,7 @@ func ExamplePartitionByErr() {
_, err := PartitionByErr(list, func(x int) (string, error) {
if x == 0 {
return "", fmt.Errorf("zero is not allowed")
return "", errors.New("zero is not allowed")
}
if x < 0 {
return "negative", nil
@@ -2856,7 +2856,7 @@ func ExampleRepeatBy() {
func ExampleRepeatByErr() {
result, err := RepeatByErr(5, func(i int) (string, error) {
if i == 3 {
return "", fmt.Errorf("index 3 is not allowed")
return "", errors.New("index 3 is not allowed")
}
return fmt.Sprintf("item-%d", i), nil
})
@@ -2881,7 +2881,7 @@ func ExampleKeyByErr() {
_, err := KeyByErr(list, func(str string) (int, error) {
if str == "aa" {
return 0, fmt.Errorf("aa is not allowed")
return 0, errors.New("aa is not allowed")
}
return len(str), nil
})
@@ -3026,7 +3026,7 @@ func ExampleRejectErr() {
result, err := RejectErr(list, func(x int64, index int) (bool, error) {
if x == 3 {
return false, fmt.Errorf("number 3 is not allowed")
return false, errors.New("number 3 is not allowed")
}
return x%2 == 0, nil
})
@@ -3066,7 +3066,7 @@ func ExampleCountByErr() {
_, err := CountByErr(list, func(i int) (bool, error) {
if i == 3 {
return false, fmt.Errorf("number 3 is not allowed")
return false, errors.New("number 3 is not allowed")
}
return i < 4, nil
})
@@ -3631,7 +3631,7 @@ func ExampleUnzip9() {
func ExampleUnzipByErr2() {
a, b, err := UnzipByErr2([]string{"hello", "error", "world"}, func(str string) (string, int, error) {
if str == "error" {
return "", 0, fmt.Errorf("error string not allowed")
return "", 0, errors.New("error string not allowed")
}
return str, len(str), nil
})
@@ -3642,7 +3642,7 @@ func ExampleUnzipByErr2() {
func ExampleUnzipByErr3() {
a, b, c, err := UnzipByErr3([]string{"hello", "error", "world"}, func(str string) (string, int, bool, error) {
if str == "error" {
return "", 0, false, fmt.Errorf("error string not allowed")
return "", 0, false, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, nil
})
@@ -3653,7 +3653,7 @@ func ExampleUnzipByErr3() {
func ExampleUnzipByErr4() {
a, b, c, d, err := UnzipByErr4([]string{"hello", "error", "world"}, func(str string) (string, int, bool, float32, error) {
if str == "error" {
return "", 0, false, 0, fmt.Errorf("error string not allowed")
return "", 0, false, 0, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, float32(len(str)), nil
})
@@ -3664,7 +3664,7 @@ func ExampleUnzipByErr4() {
func ExampleUnzipByErr5() {
a, b, c, d, e, err := UnzipByErr5([]string{"hello", "error", "world"}, func(str string) (string, int, bool, float32, float64, error) {
if str == "error" {
return "", 0, false, 0, 0, fmt.Errorf("error string not allowed")
return "", 0, false, 0, 0, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, float32(len(str)), float64(len(str)), nil
})
@@ -3675,7 +3675,7 @@ func ExampleUnzipByErr5() {
func ExampleUnzipByErr6() {
a, b, c, d, e, f, err := UnzipByErr6([]string{"hello", "error", "world"}, func(str string) (string, int, bool, float32, float64, int8, error) {
if str == "error" {
return "", 0, false, 0, 0, 0, fmt.Errorf("error string not allowed")
return "", 0, false, 0, 0, 0, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, float32(len(str)), float64(len(str)), int8(len(str)), nil
})
@@ -3686,7 +3686,7 @@ func ExampleUnzipByErr6() {
func ExampleUnzipByErr7() {
a, b, c, d, e, f, g, err := UnzipByErr7([]string{"hello", "error", "world"}, func(str string) (string, int, bool, float32, float64, int8, int16, error) {
if str == "error" {
return "", 0, false, 0, 0, 0, 0, fmt.Errorf("error string not allowed")
return "", 0, false, 0, 0, 0, 0, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, float32(len(str)), float64(len(str)), int8(len(str)), int16(len(str)), nil
})
@@ -3697,7 +3697,7 @@ func ExampleUnzipByErr7() {
func ExampleUnzipByErr8() {
a, b, c, d, e, f, g, h, err := UnzipByErr8([]string{"hello", "error", "world"}, func(str string) (string, int, bool, float32, float64, int8, int16, int32, error) {
if str == "error" {
return "", 0, false, 0, 0, 0, 0, 0, fmt.Errorf("error string not allowed")
return "", 0, false, 0, 0, 0, 0, 0, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, float32(len(str)), float64(len(str)), int8(len(str)), int16(len(str)), int32(len(str)), nil
})
@@ -3708,7 +3708,7 @@ func ExampleUnzipByErr8() {
func ExampleUnzipByErr9() {
a, b, c, d, e, f, g, h, i, err := UnzipByErr9([]string{"hello", "error", "world"}, func(str string) (string, int, bool, float32, float64, int8, int16, int32, int64, error) {
if str == "error" {
return "", 0, false, 0, 0, 0, 0, 0, 0, fmt.Errorf("error string not allowed")
return "", 0, false, 0, 0, 0, 0, 0, 0, errors.New("error string not allowed")
}
return str, len(str), len(str) > 4, float32(len(str)), float64(len(str)), int8(len(str)), int16(len(str)), int32(len(str)), int64(len(str)), nil
})
@@ -4103,7 +4103,7 @@ func ExampleCrossJoinBy9() {
func ExampleCrossJoinByErr2() {
result, err := CrossJoinByErr2([]string{"a", "b"}, []int{1, 2}, func(a string, b int) (string, error) {
if a == "b" {
return "", fmt.Errorf("b not allowed")
return "", errors.New("b not allowed")
}
return fmt.Sprintf("%v-%v", a, b), nil
})
@@ -4121,7 +4121,7 @@ func ExampleCrossJoinByErr2() {
func ExampleZipByErr2() {
result, err := ZipByErr2([]string{"a", "b", "c"}, []int{1, 2, 3}, func(a string, b int) (string, error) {
if a == "b" {
return "", fmt.Errorf("b is not allowed")
return "", errors.New("b is not allowed")
}
return fmt.Sprintf("%v-%v", a, b), nil
})
+14 -14
View File
@@ -1239,11 +1239,11 @@ func TestFilterKeysErr(t *testing.T) {
is := assert.New(t)
tests := []struct {
name string
input map[int]string
name string
input map[int]string
predicate func(int, string) (bool, error)
want []int
wantErr string
want []int
wantErr string
}{
{
name: "filter by value",
@@ -1254,8 +1254,8 @@ func TestFilterKeysErr(t *testing.T) {
want: []int{1},
},
{
name: "empty map",
input: map[int]string{},
name: "empty map",
input: map[int]string{},
predicate: func(k int, v string) (bool, error) {
return true, nil
},
@@ -1282,7 +1282,7 @@ func TestFilterKeysErr(t *testing.T) {
input: map[int]string{1: "foo", 2: "bar", 3: "baz"},
predicate: func(k int, v string) (bool, error) {
if k == 2 {
return false, fmt.Errorf("key 2 not allowed")
return false, errors.New("key 2 not allowed")
}
return true, nil
},
@@ -1314,11 +1314,11 @@ func TestFilterValuesErr(t *testing.T) {
is := assert.New(t)
tests := []struct {
name string
input map[int]string
name string
input map[int]string
predicate func(int, string) (bool, error)
want []string
wantErr string
want []string
wantErr string
}{
{
name: "filter by value",
@@ -1329,8 +1329,8 @@ func TestFilterValuesErr(t *testing.T) {
want: []string{"foo"},
},
{
name: "empty map",
input: map[int]string{},
name: "empty map",
input: map[int]string{},
predicate: func(k int, v string) (bool, error) {
return true, nil
},
@@ -1357,7 +1357,7 @@ func TestFilterValuesErr(t *testing.T) {
input: map[int]string{1: "foo", 2: "bar", 3: "baz"},
predicate: func(k int, v string) (bool, error) {
if k == 2 {
return false, fmt.Errorf("key 2 not allowed")
return false, errors.New("key 2 not allowed")
}
return true, nil
},
+33 -33
View File
@@ -41,7 +41,7 @@ func TestFilterErr(t *testing.T) {
tests := []struct {
name string
input []int
predicate func(item int, index int) (bool, error)
predicate func(item, index int) (bool, error)
want []int
wantErr string
callbacks int // Number of predicates called before error/finish
@@ -49,7 +49,7 @@ func TestFilterErr(t *testing.T) {
{
name: "filter even numbers",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return x%2 == 0, nil
},
want: []int{2, 4},
@@ -58,7 +58,7 @@ func TestFilterErr(t *testing.T) {
{
name: "empty slice",
input: []int{},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return true, nil
},
want: []int{},
@@ -67,7 +67,7 @@ func TestFilterErr(t *testing.T) {
{
name: "filter all out",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return false, nil
},
want: []int{},
@@ -76,7 +76,7 @@ func TestFilterErr(t *testing.T) {
{
name: "filter all in",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return true, nil
},
want: []int{1, 2, 3, 4},
@@ -85,9 +85,9 @@ func TestFilterErr(t *testing.T) {
{
name: "error on specific index",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
if x == 3 {
return false, fmt.Errorf("number 3 is not allowed")
return false, errors.New("number 3 is not allowed")
}
return x%2 == 0, nil
},
@@ -102,7 +102,7 @@ func TestFilterErr(t *testing.T) {
t.Parallel()
var callbacks int
wrappedPredicate := func(item int, index int) (bool, error) {
wrappedPredicate := func(item, index int) (bool, error) {
callbacks++
return tt.predicate(item, index)
}
@@ -1667,11 +1667,11 @@ func TestRepeatByErr(t *testing.T) {
// Table-driven tests
tests := []struct {
name string
count int
callback func(index int) (int, error)
wantResult []int
wantErr bool
name string
count int
callback func(index int) (int, error)
wantResult []int
wantErr bool
expectedCallbackCount int
}{
{
@@ -1680,8 +1680,8 @@ func TestRepeatByErr(t *testing.T) {
callback: func(i int) (int, error) {
return i * i, nil
},
wantResult: []int{0, 1, 4, 9, 16},
wantErr: false,
wantResult: []int{0, 1, 4, 9, 16},
wantErr: false,
expectedCallbackCount: 5,
},
{
@@ -1693,8 +1693,8 @@ func TestRepeatByErr(t *testing.T) {
}
return i * i, nil
},
wantResult: nil,
wantErr: true,
wantResult: nil,
wantErr: true,
expectedCallbackCount: 1,
},
{
@@ -1706,8 +1706,8 @@ func TestRepeatByErr(t *testing.T) {
}
return i * i, nil
},
wantResult: nil,
wantErr: true,
wantResult: nil,
wantErr: true,
expectedCallbackCount: 3,
},
{
@@ -1719,8 +1719,8 @@ func TestRepeatByErr(t *testing.T) {
}
return i * i, nil
},
wantResult: nil,
wantErr: true,
wantResult: nil,
wantErr: true,
expectedCallbackCount: 5,
},
{
@@ -1729,8 +1729,8 @@ func TestRepeatByErr(t *testing.T) {
callback: func(i int) (int, error) {
return i * i, nil
},
wantResult: []int{},
wantErr: false,
wantResult: []int{},
wantErr: false,
expectedCallbackCount: 0,
},
{
@@ -1739,8 +1739,8 @@ func TestRepeatByErr(t *testing.T) {
callback: func(i int) (int, error) {
return 42, nil
},
wantResult: []int{42},
wantErr: false,
wantResult: []int{42},
wantErr: false,
expectedCallbackCount: 1,
},
}
@@ -2353,7 +2353,7 @@ func TestRejectErr(t *testing.T) {
tests := []struct {
name string
input []int
predicate func(item int, index int) (bool, error)
predicate func(item, index int) (bool, error)
want []int
wantErr string
callbacks int // Number of predicates called before error/finish
@@ -2361,7 +2361,7 @@ func TestRejectErr(t *testing.T) {
{
name: "reject even numbers",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return x%2 == 0, nil
},
want: []int{1, 3},
@@ -2370,7 +2370,7 @@ func TestRejectErr(t *testing.T) {
{
name: "empty slice",
input: []int{},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return true, nil
},
want: []int{},
@@ -2379,7 +2379,7 @@ func TestRejectErr(t *testing.T) {
{
name: "reject all out",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return false, nil
},
want: []int{1, 2, 3, 4},
@@ -2388,7 +2388,7 @@ func TestRejectErr(t *testing.T) {
{
name: "reject all in",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
return true, nil
},
want: []int{},
@@ -2397,9 +2397,9 @@ func TestRejectErr(t *testing.T) {
{
name: "error on specific index",
input: []int{1, 2, 3, 4},
predicate: func(x int, _ int) (bool, error) {
predicate: func(x, _ int) (bool, error) {
if x == 3 {
return false, fmt.Errorf("number 3 is not allowed")
return false, errors.New("number 3 is not allowed")
}
return x%2 == 0, nil
},
@@ -2414,7 +2414,7 @@ func TestRejectErr(t *testing.T) {
t.Parallel()
var callbacks int
wrappedPredicate := func(item int, index int) (bool, error) {
wrappedPredicate := func(item, index int) (bool, error) {
callbacks++
return tt.predicate(item, index)
}
+51 -51
View File
@@ -536,9 +536,9 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount int
}{
{
name: "successful transformation",
a: []string{"a", "b"},
b: []int{1, 2},
name: "successful transformation",
a: []string{"a", "b"},
b: []int{1, 2},
iteratee: func(a string, b int) (string, error) {
return a + "-" + strconv.Itoa(b), nil
},
@@ -547,9 +547,9 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 2,
},
{
name: "error at second element stops iteration",
a: []string{"a", "b"},
b: []int{1, 2},
name: "error at second element stops iteration",
a: []string{"a", "b"},
b: []int{1, 2},
iteratee: func(a string, b int) (string, error) {
if b == 2 {
return "", errors.New("number 2 is not allowed")
@@ -562,9 +562,9 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 2,
},
{
name: "error at first element stops iteration immediately",
a: []string{"a", "b"},
b: []int{1, 2},
name: "error at first element stops iteration immediately",
a: []string{"a", "b"},
b: []int{1, 2},
iteratee: func(a string, b int) (string, error) {
return "", errors.New("first error")
},
@@ -574,9 +574,9 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 1,
},
{
name: "empty input slices",
a: []string{},
b: []int{},
name: "empty input slices",
a: []string{},
b: []int{},
iteratee: func(a string, b int) (string, error) {
return a + "-" + strconv.Itoa(b), nil
},
@@ -585,9 +585,9 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 0,
},
{
name: "unequal slice lengths - zero value filled",
a: []string{"a", "b", "c"},
b: []int{1},
name: "unequal slice lengths - zero value filled",
a: []string{"a", "b", "c"},
b: []int{1},
iteratee: func(a string, b int) (string, error) {
if b == 0 {
return "", errors.New("zero value not allowed")
@@ -644,10 +644,10 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount int
}{
{
name: "successful transformation",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
name: "successful transformation",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
iteratee: func(a string, b int, c bool) (string, error) {
return a + "-" + strconv.Itoa(b) + "-" + strconv.FormatBool(c), nil
},
@@ -656,10 +656,10 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 2,
},
{
name: "error at second element stops iteration",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
name: "error at second element stops iteration",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
iteratee: func(a string, b int, c bool) (string, error) {
if b == 2 {
return "", errors.New("number 2 is not allowed")
@@ -672,10 +672,10 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 2,
},
{
name: "error at first element",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
name: "error at first element",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
iteratee: func(a string, b int, c bool) (string, error) {
return "", errors.New("first error")
},
@@ -685,10 +685,10 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 1,
},
{
name: "empty input slices",
a: []string{},
b: []int{},
c: []bool{},
name: "empty input slices",
a: []string{},
b: []int{},
c: []bool{},
iteratee: func(a string, b int, c bool) (string, error) {
return a + "-" + strconv.Itoa(b) + "-" + strconv.FormatBool(c), nil
},
@@ -742,11 +742,11 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount int
}{
{
name: "successful transformation",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
d: []float32{1.1, 2.2},
name: "successful transformation",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
d: []float32{1.1, 2.2},
iteratee: func(a string, b int, c bool, d float32) (string, error) {
return a + "-" + strconv.Itoa(b), nil
},
@@ -755,11 +755,11 @@ func TestZipByErr(t *testing.T) {
expectedCallbackCount: 2,
},
{
name: "error stops iteration",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
d: []float32{1.1, 2.2},
name: "error stops iteration",
a: []string{"a", "b"},
b: []int{1, 2},
c: []bool{true, false},
d: []float32{1.1, 2.2},
iteratee: func(a string, b int, c bool, d float32) (string, error) {
if b == 2 {
return "", errors.New("error")
@@ -1029,10 +1029,10 @@ func TestCrossJoinByErr(t *testing.T) {
expectedCallbackCount: 3, // a-1, a-2, then b-1 errors
},
{
name: "empty list returns empty result",
listA: []string{},
listB: []int{1, 2},
transform: func(a string, b int) (string, error) { return a + "-" + strconv.Itoa(b), nil },
name: "empty list returns empty result",
listA: []string{},
listB: []int{1, 2},
transform: func(a string, b int) (string, error) { return a + "-" + strconv.Itoa(b), nil },
wantResult: []string{},
wantErr: false,
expectedCallbackCount: 0,
@@ -1150,7 +1150,7 @@ func TestCrossJoinByErr(t *testing.T) {
},
)
is.Equal(4, len(result))
is.Len(result, 4)
is.NoError(err)
is.Equal(4, callbackCount)
})
@@ -1173,7 +1173,7 @@ func TestCrossJoinByErr(t *testing.T) {
},
)
is.Equal(2, len(result))
is.Len(result, 2)
is.NoError(err)
is.Equal(2, callbackCount)
})
@@ -1197,7 +1197,7 @@ func TestCrossJoinByErr(t *testing.T) {
},
)
is.Equal(1, len(result))
is.Len(result, 1)
is.NoError(err)
is.Equal(1, callbackCount)
})
@@ -1222,7 +1222,7 @@ func TestCrossJoinByErr(t *testing.T) {
},
)
is.Equal(1, len(result))
is.Len(result, 1)
is.NoError(err)
is.Equal(1, callbackCount)
})
@@ -1248,7 +1248,7 @@ func TestCrossJoinByErr(t *testing.T) {
},
)
is.Equal(1, len(result))
is.Len(result, 1)
is.NoError(err)
is.Equal(1, callbackCount)
})
@@ -1275,7 +1275,7 @@ func TestCrossJoinByErr(t *testing.T) {
},
)
is.Equal(1, len(result))
is.Len(result, 1)
is.NoError(err)
is.Equal(1, callbackCount)
})