11module SeqTests
22
3-
43#if FABLE_ COMPILER_ PYTHON
54open Fable.Pyxpecto
65#endif
@@ -12,60 +11,50 @@ open Expecto
1211#endif
1312open SampleDomain
1413open TestData
15- open TestHelpers
16- open System
1714open FsToolkit.ErrorHandling
1815
19-
2016let sequenceResultMTests =
2117 testList " Seq.sequenceResultM Tests" [
22- testCase " traverseResult with an empty sequence"
18+ testCase " sequenceResult with an empty sequence"
2319 <| fun _ ->
24- let tweets = []
25- let expected = Ok []
20+ let tweets = Seq.empty
21+ let expected = Ok [|| ]
2622
27- let actual =
28- Seq.sequenceResultM ( Seq.map Tweet.TryCreate tweets)
29- |> Result.map Seq.toList
23+ let actual = Seq.sequenceResultM ( Seq.map Tweet.TryCreate tweets)
3024
3125 Expect.equal actual expected " Should have an empty list of valid tweets"
3226
33- testCase " traverseResult with a sequence of valid data"
27+ testCase " sequenceResult with a sequence of valid data"
3428 <| fun _ ->
35- let tweets = [
36- " Hi"
37- " Hello"
38- " Hola"
39- ]
29+ let tweets =
30+ seq {
31+ " Hi"
32+ " Hello"
33+ " Hola"
34+ }
4035
41- let expected =
42- List.map tweet tweets
43- |> Ok
36+ let expected = Ok [| for x in tweets -> tweet x |]
4437
45- let actual =
46- Seq.sequenceResultM ( Seq.map Tweet.TryCreate tweets)
47- |> Result.map Seq.toList
38+ let actual = Seq.sequenceResultM ( Seq.map Tweet.TryCreate tweets)
4839
4940 Expect.equal actual expected " Should have a list of valid tweets"
5041
51- testCase " sequenceResultM with few invalid data"
42+ testCase " sequenceResult with few invalid data"
5243 <| fun _ ->
5344 let tweets =
54- [
45+ seq {
5546 " "
5647 " Hello"
5748 aLongerInvalidTweet
58- ]
59- :> seq<_>
49+ }
50+
51+ let expected = Error emptyTweetErrMsg
6052
6153 let actual = Seq.sequenceResultM ( Seq.map Tweet.TryCreate tweets)
6254
63- Expect.equal
64- actual
65- ( Error emptyTweetErrMsg)
66- " traverse the sequence and return the first error"
55+ Expect.equal actual expected " traverse the sequence and return the first error"
6756
68- testCase " sequenceResultM stops after first invalid data"
57+ testCase " sequenceResult stops after first invalid data"
6958 <| fun _ ->
7059 let mutable counter = 0
7160
@@ -81,12 +70,11 @@ let sequenceResultMTests =
8170 + 1
8271 }
8372
73+ let expected = Error longerTweetErrMsg
74+
8475 let actual = Seq.sequenceResultM ( Seq.map Tweet.TryCreate tweets)
8576
86- Expect.equal
87- actual
88- ( Error longerTweetErrMsg)
89- " traverse the sequence and return the first error"
77+ Expect.equal actual expected " traverse the sequence and return the first error"
9078
9179 Expect.equal counter 0 " evaluation of the sequence stops at the first error"
9280 ]
0 commit comments