Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Unreleased

* Test coverage: Added tests for `AsyncSeq.zipWithIndexAsync` (obsolete alias for `mapiAsync`) and `AsyncSeq.ofIQueryable`, which previously had no dedicated test coverage. No functional changes.
* Test coverage: Added tests for previously-untested public API functions `AsyncSeq.tryFirst`, `AsyncSeq.firstOrDefault`, `AsyncSeq.zipWithParallel`, `AsyncSeq.combineLatestWithAsync`, and `AsyncSeq.toObservable`. 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.
Expand Down
66 changes: 66 additions & 0 deletions tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#endif
module AsyncSeqTests

#nowarn "44" // suppress Obsolete warnings for intentional tests of obsolete API (e.g. AsyncSeq.zipWithIndexAsync)

open NUnit.Framework
open FSharp.Control
open System
Expand Down Expand Up @@ -5277,3 +5279,67 @@ let ``AsyncSeq.compareWithAsync empty sequences returns 0`` () =
AsyncSeq.empty<int>
|> Async.RunSynchronously
Assert.AreEqual(0, result)

// ===== zipWithIndexAsync (obsolete alias for mapiAsync) =====

[<Test>]
let ``AsyncSeq.zipWithIndexAsync maps elements with their int64 index`` () =
let result =
AsyncSeq.ofSeq ["a"; "b"; "c"]
|> AsyncSeq.zipWithIndexAsync (fun i x -> async { return sprintf "%d:%s" i x })
|> AsyncSeq.toArrayAsync
|> Async.RunSynchronously
Assert.AreEqual([| "0:a"; "1:b"; "2:c" |], result)

[<Test>]
let ``AsyncSeq.zipWithIndexAsync on empty sequence returns empty`` () =
let result =
AsyncSeq.empty<string>
|> AsyncSeq.zipWithIndexAsync (fun i x -> async { return sprintf "%d:%s" i x })
|> AsyncSeq.toArrayAsync
|> Async.RunSynchronously
Assert.AreEqual([||], result)

[<Test>]
let ``AsyncSeq.zipWithIndexAsync matches mapiAsync behavior`` () =
let xs = AsyncSeq.ofSeq [10; 20; 30]
let f i x = async { return int i * x }
let viaZipWithIndexAsync = xs |> AsyncSeq.zipWithIndexAsync f |> AsyncSeq.toArrayAsync |> Async.RunSynchronously
let viaMapiAsync = xs |> AsyncSeq.mapiAsync f |> AsyncSeq.toArrayAsync |> Async.RunSynchronously
Assert.AreEqual(viaMapiAsync, viaZipWithIndexAsync)

#if (NETSTANDARD2_1 || NETCOREAPP3_0)
// ===== ofIQueryable =====

/// Minimal IQueryable<'T> implementation that also implements IAsyncEnumerable<'T>,
/// as required by AsyncSeq.ofIQueryable (which casts its input to IAsyncEnumerable<'T>).
type private FakeAsyncQueryable<'T>(data: 'T[]) =
let inner = data.AsQueryable()
interface System.Collections.IEnumerable with
member _.GetEnumerator() : System.Collections.IEnumerator = (inner :> System.Collections.IEnumerable).GetEnumerator()
interface Collections.Generic.IEnumerable<'T> with
member _.GetEnumerator() : Collections.Generic.IEnumerator<'T> = (inner :> Collections.Generic.IEnumerable<'T>).GetEnumerator()
interface Linq.IQueryable<'T> with
member _.ElementType = inner.ElementType
member _.Expression = inner.Expression
member _.Provider = inner.Provider
interface Collections.Generic.IAsyncEnumerable<'T> with
member _.GetAsyncEnumerator(_ct: CancellationToken) : Collections.Generic.IAsyncEnumerator<'T> =
let e = (data :> Collections.Generic.IEnumerable<'T>).GetEnumerator()
{ new Collections.Generic.IAsyncEnumerator<'T> with
member _.Current = e.Current
member _.MoveNextAsync() = Threading.Tasks.ValueTask<bool>(e.MoveNext())
member _.DisposeAsync() = e.Dispose(); Threading.Tasks.ValueTask() }

[<Test>]
let ``AsyncSeq.ofIQueryable returns elements in order`` () =
let query = FakeAsyncQueryable<int>([| 1; 2; 3 |]) :> Linq.IQueryable<int>
let result = AsyncSeq.ofIQueryable query |> AsyncSeq.toArrayAsync |> Async.RunSynchronously
Assert.AreEqual([| 1; 2; 3 |], result)

[<Test>]
let ``AsyncSeq.ofIQueryable on empty queryable returns empty`` () =
let query = FakeAsyncQueryable<int>([||]) :> Linq.IQueryable<int>
let result = AsyncSeq.ofIQueryable query |> AsyncSeq.toArrayAsync |> Async.RunSynchronously
Assert.AreEqual([||], result)
#endif