@@ -25,6 +25,7 @@ module With =
25
25
| true , false -> TaskSeq.takeWhileInclusive
26
26
| true , true -> fun pred -> TaskSeq.takeWhileInclusiveAsync ( pred >> Task.fromResult)
27
27
28
+ /// adds '@' to each number and concatenates the chars before calling 'should equal'
28
29
let verifyAsString expected =
29
30
TaskSeq.map char
30
31
>> TaskSeq.map ((+) '@' )
@@ -46,61 +47,80 @@ module With =
46
47
47
48
module EmptySeq =
48
49
[<Theory; ClassData( typeof< TestEmptyVariants>) >]
49
- let ``TaskSeq - takeWhile has no effect`` variant =
50
- Gen.getEmptyVariant variant
51
- |> TaskSeq.takeWhile ((=) 12 )
52
- |> verifyEmpty
50
+ let ``TaskSeq - takeWhile + A has no effect`` variant = task {
51
+ do ! Gen.getEmptyVariant variant
52
+ |> TaskSeq.takeWhile ((=) 12 )
53
+ |> verifyEmpty
54
+
55
+ do ! Gen.getEmptyVariant variant
56
+ |> TaskSeq.takeWhileAsync ((=) 12 >> Task.fromResult)
57
+ |> verifyEmpty
58
+ }
53
59
54
60
[<Theory; ClassData( typeof< TestEmptyVariants>) >]
55
- let ``TaskSeq - takeWhileAsync has no effect`` variant =
56
- Gen.getEmptyVariant variant
57
- |> TaskSeq.takeWhileAsync ( fun x -> task { return x = 12 })
58
- |> verifyEmpty
59
-
60
- module Other =
61
- [<Theory>]
62
- [<InlineData( false , false ) >]
63
- [<InlineData( false , true ) >]
64
- [<InlineData( true , false ) >]
65
- [<InlineData( true , true ) >]
66
- let ``TaskSeq - takeWhileXXX exclude all items after predicate fails`` ( inclusive , isAsync ) =
67
- let functionToTest = With.getFunction inclusive isAsync
68
-
69
- [ 1 ; 2 ; 2 ; 3 ; 3 ; 2 ; 1 ]
70
- |> TaskSeq.ofSeq
71
- |> functionToTest ( fun x -> x <= 2 )
72
- |> verifyAsString ( if inclusive then " ABBC" else " ABB" )
73
-
74
- [<Theory>]
75
- [<InlineData( false , false ) >]
76
- [<InlineData( false , true ) >]
77
- [<InlineData( true , false ) >]
78
- [<InlineData( true , true ) >]
79
- let ``TaskSeq - takeWhileXXX stops consuming after predicate fails`` ( inclusive , isAsync ) =
80
- let functionToTest = With.getFunction inclusive isAsync
61
+ let ``TaskSeq - takeWhileInclusive + A has no effect`` variant = task {
62
+ do ! Gen.getEmptyVariant variant
63
+ |> TaskSeq.takeWhileInclusive ((=) 12 )
64
+ |> verifyEmpty
65
+
66
+ do ! Gen.getEmptyVariant variant
67
+ |> TaskSeq.takeWhileInclusiveAsync ((=) 12 >> Task.fromResult)
68
+ |> verifyEmpty
69
+ }
81
70
82
- seq {
83
- yield ! [ 1 ; 2 ; 2 ; 3 ; 3 ]
84
- yield failwith " Too far"
85
- }
86
- |> TaskSeq.ofSeq
87
- |> functionToTest ( fun x -> x <= 2 )
88
- |> verifyAsString ( if inclusive then " ABBC" else " ABB" )
71
+ module Immutable =
89
72
73
+ [<Theory; ClassData( typeof< TestImmTaskSeq>) >]
74
+ let ``TaskSeq - takeWhile + A filters correctly`` variant = task {
75
+ do !
76
+ Gen.getSeqImmutable variant
77
+ |> TaskSeq.takeWhile condWithGuard
78
+ |> verifyAsString " ABCDE"
79
+
80
+ do !
81
+ Gen.getSeqImmutable variant
82
+ |> TaskSeq.takeWhileAsync ( fun x -> task { return condWithGuard x })
83
+ |> verifyAsString " ABCDE"
84
+ }
90
85
91
- module Immutable =
86
+ [<Theory; ClassData( typeof< TestImmTaskSeq>) >]
87
+ let ``TaskSeq - takeWhile + A does not pick first item when false`` variant = task {
88
+ do !
89
+ Gen.getSeqImmutable variant
90
+ |> TaskSeq.takeWhile ((=) 0 )
91
+ |> verifyAsString " "
92
+
93
+ do !
94
+ Gen.getSeqImmutable variant
95
+ |> TaskSeq.takeWhileAsync ((=) 0 >> Task.fromResult)
96
+ |> verifyAsString " "
97
+ }
92
98
93
99
[<Theory; ClassData( typeof< TestImmTaskSeq>) >]
94
- let ``TaskSeq - takeWhile filters correctly`` variant =
95
- Gen.getSeqImmutable variant
96
- |> TaskSeq.takeWhile condWithGuard
97
- |> verifyAsString " ABCDE"
100
+ let ``TaskSeq - takeWhileInclusive + A filters correctly`` variant = task {
101
+ do !
102
+ Gen.getSeqImmutable variant
103
+ |> TaskSeq.takeWhileInclusive condWithGuard
104
+ |> verifyAsString " ABCDEF"
105
+
106
+ do !
107
+ Gen.getSeqImmutable variant
108
+ |> TaskSeq.takeWhileInclusiveAsync ( fun x -> task { return condWithGuard x })
109
+ |> verifyAsString " ABCDEF"
110
+ }
98
111
99
112
[<Theory; ClassData( typeof< TestImmTaskSeq>) >]
100
- let ``TaskSeq - takeWhileAsync filters correctly`` variant =
101
- Gen.getSeqImmutable variant
102
- |> TaskSeq.takeWhileAsync ( fun x -> task { return condWithGuard x })
103
- |> verifyAsString " ABCDE"
113
+ let ``TaskSeq - takeWhileInclusive + A always pick at least the first item`` variant = task {
114
+ do !
115
+ Gen.getSeqImmutable variant
116
+ |> TaskSeq.takeWhileInclusive ((=) 0 )
117
+ |> verifyAsString " A"
118
+
119
+ do !
120
+ Gen.getSeqImmutable variant
121
+ |> TaskSeq.takeWhileInclusiveAsync ((=) 0 >> Task.fromResult)
122
+ |> verifyAsString " A"
123
+ }
104
124
105
125
module SideEffects =
106
126
[<Theory; ClassData( typeof< TestSideEffectTaskSeq>) >]
@@ -206,3 +226,33 @@ module SideEffects =
206
226
207
227
repeat |> should not' ( equal expected)
208
228
}
229
+
230
+ module Other =
231
+ [<Theory>]
232
+ [<InlineData( false , false ) >]
233
+ [<InlineData( false , true ) >]
234
+ [<InlineData( true , false ) >]
235
+ [<InlineData( true , true ) >]
236
+ let ``TaskSeq - takeWhileXXX exclude all items after predicate fails`` ( inclusive , isAsync ) =
237
+ let functionToTest = With.getFunction inclusive isAsync
238
+
239
+ [ 1 ; 2 ; 2 ; 3 ; 3 ; 2 ; 1 ]
240
+ |> TaskSeq.ofSeq
241
+ |> functionToTest ( fun x -> x <= 2 )
242
+ |> verifyAsString ( if inclusive then " ABBC" else " ABB" )
243
+
244
+ [<Theory>]
245
+ [<InlineData( false , false ) >]
246
+ [<InlineData( false , true ) >]
247
+ [<InlineData( true , false ) >]
248
+ [<InlineData( true , true ) >]
249
+ let ``TaskSeq - takeWhileXXX stops consuming after predicate fails`` ( inclusive , isAsync ) =
250
+ let functionToTest = With.getFunction inclusive isAsync
251
+
252
+ seq {
253
+ yield ! [ 1 ; 2 ; 2 ; 3 ; 3 ]
254
+ yield failwith " Too far"
255
+ }
256
+ |> TaskSeq.ofSeq
257
+ |> functionToTest ( fun x -> x <= 2 )
258
+ |> verifyAsString ( if inclusive then " ABBC" else " ABB" )
0 commit comments