Skip to content

Commit

Permalink
Show that the NRE can also occur in synchronous versions of taskSeq
Browse files Browse the repository at this point in the history
  • Loading branch information
abelbraaksma committed Oct 24, 2022
1 parent 10a2eae commit 9b8a459
Showing 1 changed file with 145 additions and 2 deletions.
147 changes: 145 additions & 2 deletions src/FSharpy.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ let ``CE taskSeq, call GetAsyncEnumerator twice -- random mixed iteration`` () =
}

[<Fact>]
let ``CE taskSeq with two items, call map multiple times over its own result`` () = task {
let ``CE taskSeq, call map multiple times over its own result`` () = task {
let tskSeq = taskSeq {
yield 1
yield 2
Expand All @@ -333,7 +333,150 @@ let ``CE taskSeq with two items, call map multiple times over its own result`` (
}

[<Fact>]
let ``CE taskSeq with two items, call mapAsync multiple times over its own result`` () = task {
let ``CE taskSeq, call map multiple times over its own result - alternative #1`` () = task {
let tskSeq1 = taskSeq {
yield 1
yield 2
}

// [ 2; 3]
let tskSeq2 = taskSeq {
for i in tskSeq1 do
yield i + 1
}

// [ 3; 4]
let tskSeq3 = taskSeq {
for i in tskSeq2 do
yield i + 1
}

let result3 = TaskSeq.toArray tskSeq3

result3 |> should equal [| 3; 4 |]
}

[<Fact>]
let ``CE taskSeq, call map multiple times over its own result - alternative #2`` () = task {
let tskSeq1 = taskSeq {
yield 1
yield 2
}

let result1 = TaskSeq.toArray tskSeq1
result1 |> should equal [| 1; 2 |]

// [ 2; 3]
let tskSeq2 = taskSeq {
for i in tskSeq1 do
yield i + 1
}

let result2 = TaskSeq.toArray tskSeq2
result2 |> should equal [| 2; 3 |]

// [ 3; 4]
let tskSeq3 = taskSeq {
for i in tskSeq2 do
yield i + 1
}

let result3 = TaskSeq.toArray tskSeq3
result3 |> should equal [| 3; 4 |]
}

[<Fact>]
let ``CE taskSeq, call map multiple times over its own result - alternative #3`` () = task {
let tskSeq1 = taskSeq {
yield 1
yield 2
}

let result1 = TaskSeq.toArray tskSeq1
result1 |> should equal [| 1; 2 |]

// [ 2; 3]
let tskSeq2 = taskSeq {
yield! taskSeq {
for i in tskSeq1 do
yield i + 1
}
}

let result2 = TaskSeq.toArray tskSeq2
result2 |> should equal [| 2; 3 |]

// [ 3; 4]
let tskSeq3 = taskSeq {
yield! taskSeq {
for i in tskSeq2 do
yield i + 1
}
}

let result3 = TaskSeq.toArray tskSeq3
result3 |> should equal [| 3; 4 |]
}

[<Fact>]
let ``CE taskSeq, call map multiple times over its own result - alternative #4`` () = task {
let sequence = seq {
yield 1
yield 2
}

// [ 2; 3]
let tskSeq2 = taskSeq {
for i in sequence do
yield i + 1
}

let result2 = TaskSeq.toArray tskSeq2
result2 |> should equal [| 2; 3 |]

// [ 3; 4]
let tskSeq3 = taskSeq {
for i in tskSeq2 do
yield i + 1
}

let result3 = TaskSeq.toArray tskSeq3
result3 |> should equal [| 3; 4 |]
}

[<Fact>]
let ``CE taskSeq, call map multiple times over its own result - alternative #5`` () = task {
let sequence = seq {
yield 1
yield 2
}

// [ 2; 3]
let tskSeq2 = taskSeq {
yield! taskSeq {
for i in sequence do
yield i + 1
}
}

let result2 = TaskSeq.toArray tskSeq2
result2 |> should equal [| 2; 3 |]

// [ 3; 4]
let tskSeq3 = taskSeq {
yield! taskSeq {
for i in tskSeq2 do
yield i + 1
}
}

let result3 = TaskSeq.toArray tskSeq3
result3 |> should equal [| 3; 4 |]
}


[<Fact>]
let ``CE taskSeq, call mapAsync multiple times over its own result`` () = task {
let tskSeq = taskSeq {
yield 1
yield 2
Expand Down

0 comments on commit 9b8a459

Please sign in to comment.