Skip to content

Commit b25e949

Browse files
committed
fix: fix until and while test function logic error.
1 parent 1b7a7c8 commit b25e949

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

until.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func until(parent context.Context, testFn, fn AsyncFn) ([]any, error) {
4848
return out, testErr
4949
}
5050

51-
isDone := testOut[0].(bool)
52-
if isDone {
51+
isContinue := testOut[0].(bool)
52+
if !isContinue {
5353
return out, nil
5454
}
5555
}

until_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestUntil(t *testing.T) {
1414
count := 0
1515

1616
out, err := Until(func(c int) bool {
17-
return c == 5
17+
return c < 5
1818
}, func() int {
1919
count++
2020
return count
@@ -39,22 +39,22 @@ func TestUntilInvalidParameters(t *testing.T) {
3939
Until(func() {}, func() {})
4040
}, ErrInvalidTestFunc)
4141
a.NotPanicNow(func() {
42-
Until(func() bool { return true }, func() {})
42+
Until(func() bool { return false }, func() {})
4343
})
4444
a.NotPanicNow(func() {
45-
Until(func(err error) bool { return true }, func() error { return nil })
45+
Until(func(err error) bool { return false }, func() error { return nil })
4646
})
4747
a.NotPanicNow(func() {
48-
Until(func(ctx context.Context, err error) bool { return true }, func() error { return nil })
48+
Until(func(ctx context.Context, err error) bool { return false }, func() error { return nil })
4949
})
5050
a.NotPanicNow(func() {
51-
Until(func(ctx context.Context) bool { return true }, func() error { return nil })
51+
Until(func(ctx context.Context) bool { return false }, func() error { return nil })
5252
})
5353
a.PanicOfNow(func() {
54-
Until(func(ctx context.Context, i int) bool { return true }, func() error { return nil })
54+
Until(func(ctx context.Context, i int) bool { return false }, func() error { return nil })
5555
}, ErrInvalidTestFunc)
5656
a.PanicOfNow(func() {
57-
Until(func(ctx context.Context, i int) bool { return true }, func() {})
57+
Until(func(ctx context.Context, i int) bool { return false }, func() {})
5858
}, ErrInvalidTestFunc)
5959
}
6060

@@ -64,7 +64,7 @@ func TestUntilWithFunctionError(t *testing.T) {
6464
unexpectedErr := errors.New("unexpected error")
6565

6666
out, err := Until(func(c int, err error) bool {
67-
return c == 5
67+
return c < 5
6868
}, func() (int, error) {
6969
count++
7070
return count, unexpectedErr
@@ -96,9 +96,9 @@ func TestUntilWithContext(t *testing.T) {
9696
out, err := UntilWithContext(ctx, func(ctx context.Context) bool {
9797
select {
9898
case <-ctx.Done():
99-
return true
100-
default:
10199
return false
100+
default:
101+
return true
102102
}
103103
}, func() {
104104
})

while.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func while(parent context.Context, testFn, fn AsyncFn) ([]any, error) {
4141
return out, testErr
4242
}
4343

44-
isDone := testOut[0].(bool)
45-
if isDone {
44+
isContinue := testOut[0].(bool)
45+
if !isContinue {
4646
return out, nil
4747
}
4848

while_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestWhile(t *testing.T) {
1414
count := 0
1515

1616
out, err := While(func() bool {
17-
return count == 5
17+
return count < 5
1818
}, func() int {
1919
count++
2020
return count
@@ -39,13 +39,13 @@ func TestWhileInvalidParameters(t *testing.T) {
3939
While(func() {}, func() {})
4040
}, ErrInvalidTestFunc)
4141
a.NotPanicNow(func() {
42-
While(func() bool { return true }, func() {})
42+
While(func() bool { return false }, func() {})
4343
})
4444
a.NotPanicNow(func() {
45-
While(func(ctx context.Context) bool { return true }, func() {})
45+
While(func(ctx context.Context) bool { return false }, func() {})
4646
})
4747
a.PanicOfNow(func() {
48-
While(func(ctx context.Context, i int) bool { return true }, func() {})
48+
While(func(ctx context.Context, i int) bool { return false }, func() {})
4949
}, ErrInvalidTestFunc)
5050
}
5151

@@ -68,7 +68,7 @@ func TestWhileWithFunctionError(t *testing.T) {
6868
expectedErr := errors.New("expected error")
6969

7070
out, err := While(func() bool {
71-
return false
71+
return true
7272
}, func() (int, error) {
7373
return 0, expectedErr
7474
})
@@ -86,9 +86,9 @@ func TestWhileWithContext(t *testing.T) {
8686
out, err := WhileWithContext(ctx, func(ctx context.Context) bool {
8787
select {
8888
case <-ctx.Done():
89-
return true
90-
default:
9189
return false
90+
default:
91+
return true
9292
}
9393
}, func() {
9494
})

0 commit comments

Comments
 (0)