diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d96928c..ea4a2b6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,7 @@ ### Unreleased * Test coverage: Added tests for previously-untested public API functions `AsyncSeq.tryFirst`, `AsyncSeq.firstOrDefault`, `AsyncSeq.zipWithParallel`, `AsyncSeq.combineLatestWithAsync`, and `AsyncSeq.toObservable`. No functional changes. +* Test coverage: Added tests for `AsyncSeq.bufferByCount` (obsolete alias of `chunkBySize`) and `Seq.ofAsyncSeq`, which previously had no dedicated test coverage. No functional changes. * Fixed Fable CI build: `Microsoft.Bcl.AsyncInterfaces` was pinned to a specific version (`10.0.7`) that was older than the version resolved transitively via `System.Threading.Channels`, causing a `NU1605` package downgrade error that made Fable's project cracker fail during `dotnet fable`. The reference now uses `Version="*"` (matching `System.Threading.Channels`) so both resolve consistently. (#334) * Tests: Added comprehensive tests for `AsyncSeq.zapp`, `AsyncSeq.zappAsync`, and `AsyncSeq.compareWithAsync`, which previously had no dedicated test coverage. diff --git a/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs b/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs index 03f8dc0..464e502 100644 --- a/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs +++ b/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs @@ -6,6 +6,8 @@ #endif module AsyncSeqTests +#nowarn "44" // suppress Obsolete warnings for intentional tests of obsolete API (e.g. AsyncSeq.bufferByCount) + open NUnit.Framework open FSharp.Control open System @@ -5179,6 +5181,50 @@ let ``AsyncSeq.toObservable on empty sequence emits nothing`` () = Assert.IsTrue(completedEvent.Wait(2000)) Assert.AreEqual([||], received.ToArray()) +// ===== bufferByCount (obsolete alias for chunkBySize) ===== + +#if !FABLE_COMPILER +[] +let ``AsyncSeq.bufferByCount chunks elements into buffers of specified size`` () = + let result = + AsyncSeq.ofSeq [1;2;3;4;5] + |> AsyncSeq.bufferByCount 2 + |> AsyncSeq.toListSynchronously + Assert.AreEqual([ [|1;2|]; [|3;4|]; [|5|] ], result) + +[] +let ``AsyncSeq.bufferByCount on empty sequence returns empty`` () = + let result = + AsyncSeq.empty + |> AsyncSeq.bufferByCount 3 + |> AsyncSeq.toListSynchronously + Assert.AreEqual([], result) + +[] +let ``AsyncSeq.bufferByCount matches chunkBySize behavior`` () = + let xs = AsyncSeq.ofSeq [1..7] + let viaBufferByCount = xs |> AsyncSeq.bufferByCount 3 |> AsyncSeq.toListSynchronously + let viaChunkBySize = xs |> AsyncSeq.chunkBySize 3 |> AsyncSeq.toListSynchronously + Assert.AreEqual(viaChunkBySize, viaBufferByCount) +#pragma warning restore 0044 + +// ===== Seq.ofAsyncSeq ===== + +[] +let ``Seq.ofAsyncSeq converts async sequence to blocking sequence`` () = + let result = AsyncSeq.ofSeq [1;2;3;4] |> Seq.ofAsyncSeq |> Seq.toList + Assert.AreEqual([1;2;3;4], result) + +[] +let ``Seq.ofAsyncSeq on empty async sequence returns empty seq`` () = + let result = AsyncSeq.empty |> Seq.ofAsyncSeq |> Seq.toList + Assert.AreEqual([], result) + +[] +let ``Seq.ofAsyncSeq consumes elements lazily`` () = + let result = AsyncSeq.ofSeq [1;2;3] |> Seq.ofAsyncSeq |> Seq.take 2 |> Seq.toList + Assert.AreEqual([1;2], result) +#endif // ===== zapp / zappAsync ===== []