Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,64 @@ let ``Seq.ofAsyncSeq with exception should propagate``() =

#endif

// Additional coverage improvement tests - parameter validation and edge cases
[<Test>]
let ``AsyncSeq.bufferByCount with zero size should throw ArgumentException``() =
let s = asyncSeq { yield 1; yield 2; yield 3 }
Assert.Throws<System.ArgumentException>(fun () ->
s |> AsyncSeq.bufferByCount 0 |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

[<Test>]
let ``AsyncSeq.bufferByCount with negative size should throw ArgumentException``() =
let s = asyncSeq { yield 1; yield 2; yield 3 }
Assert.Throws<System.ArgumentException>(fun () ->
s |> AsyncSeq.bufferByCount -1 |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

[<Test>]
let ``AsyncSeq.replicate with negative count should throw ArgumentException``() =
Assert.Throws<System.ArgumentException>(fun () ->
AsyncSeq.replicate -1 42 |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

[<Test>]
let ``AsyncSeq.init with very large count should work``() =
let result = AsyncSeq.init 3L (fun i -> int i * 2) |> AsyncSeq.toListSynchronously
Assert.AreEqual([0; 2; 4], result)

[<Test>]
let ``AsyncSeq.bufferByCountAndTime with zero count should throw ArgumentException``() =
let s = asyncSeq { yield 1; yield 2; yield 3 }
Assert.Throws<System.ArgumentException>(fun () ->
s |> AsyncSeq.bufferByCountAndTime 0 100 |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

[<Test>]
let ``AsyncSeq.bufferByTime with negative time should throw ArgumentException``() =
let s = asyncSeq { yield 1; yield 2; yield 3 }
Assert.Throws<System.ArgumentException>(fun () ->
s |> AsyncSeq.bufferByTime -1 |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

[<Test>]
let ``AsyncSeq.replicateInfiniteAsync with exception should propagate on enumeration``() =
let exceptionSeq = AsyncSeq.replicateInfiniteAsync (async { failwith "test exception" })
Assert.Throws<System.Exception>(fun () ->
exceptionSeq |> AsyncSeq.take 1 |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

[<Test>]
let ``AsyncSeq.mapAsyncParallel with exception should propagate``() =
let s = asyncSeq { yield 1; yield 2; yield 3 }
let exceptionSeq = s |> AsyncSeq.mapAsyncParallel (fun x -> async {
if x = 2 then return failwith "test exception"
else return x * 2
})
Assert.Throws<System.Exception>(fun () ->
exceptionSeq |> AsyncSeq.toListSynchronously |> ignore
) |> ignore

// ----------------------------------------------------------------------------
// Additional Coverage Tests targeting uncovered edge cases and branches

Expand Down
Loading