Skip to content

Commit ce86656

Browse files
authored
Merge pull request fsprojects#184 from fsprojects/feature/test-coverage-asyncseqextensions-seq
Daily Test Coverage Improver: Add comprehensive tests for AsyncSeqExtensions module
2 parents cea3af5 + a74591b commit ce86656

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,63 @@ let ``AsyncSeq.sortByDescending should work``() =
17621762
let actual = input |> AsyncSeq.sortByDescending fn
17631763
Assert.AreEqual(expected, actual)
17641764

1765+
[<Test>]
1766+
let ``async.For with AsyncSeq should work``() =
1767+
async {
1768+
let mutable results = []
1769+
let source = asyncSeq {
1770+
yield 1
1771+
yield 2
1772+
yield 3
1773+
}
1774+
1775+
do! async {
1776+
for item in source do
1777+
results <- item :: results
1778+
}
1779+
1780+
Assert.AreEqual([3; 2; 1], results)
1781+
}
1782+
|> Async.RunSynchronously
1783+
1784+
[<Test>]
1785+
let ``async.For with empty AsyncSeq should work``() =
1786+
async {
1787+
let mutable count = 0
1788+
let source = AsyncSeq.empty
1789+
1790+
do! async {
1791+
for item in source do
1792+
count <- count + 1
1793+
}
1794+
1795+
Assert.AreEqual(0, count)
1796+
}
1797+
|> Async.RunSynchronously
1798+
1799+
[<Test>]
1800+
let ``async.For with exception in AsyncSeq should propagate``() =
1801+
async {
1802+
let source = asyncSeq {
1803+
yield 1
1804+
failwith "test exception"
1805+
yield 2
1806+
}
1807+
1808+
try
1809+
do! async {
1810+
for item in source do
1811+
()
1812+
}
1813+
Assert.Fail("Expected exception to be thrown")
1814+
with
1815+
| ex when ex.Message = "test exception" ->
1816+
() // Expected
1817+
| ex ->
1818+
Assert.Fail($"Unexpected exception: {ex.Message}")
1819+
}
1820+
|> Async.RunSynchronously
1821+
17651822
// ----------------------------------------------------------------------------
17661823
// Tests for previously uncovered modules to improve coverage
17671824

@@ -1940,4 +1997,39 @@ let ``AsyncSeq.toAsyncEnum can be cancelled``() : unit =
19401997
}
19411998
|> Async.RunSynchronously
19421999

2000+
[<Test>]
2001+
let ``Seq.ofAsyncSeq should work``() =
2002+
let source = asyncSeq {
2003+
yield 1
2004+
yield 2
2005+
yield 3
2006+
}
2007+
2008+
let result = Seq.ofAsyncSeq source |> Seq.toList
2009+
Assert.AreEqual([1; 2; 3], result)
2010+
2011+
[<Test>]
2012+
let ``Seq.ofAsyncSeq with empty AsyncSeq should work``() =
2013+
let source = AsyncSeq.empty
2014+
let result = Seq.ofAsyncSeq source |> Seq.toList
2015+
Assert.AreEqual([], result)
2016+
2017+
[<Test>]
2018+
let ``Seq.ofAsyncSeq with exception should propagate``() =
2019+
let source = asyncSeq {
2020+
yield 1
2021+
failwith "test exception"
2022+
yield 2
2023+
}
2024+
2025+
try
2026+
let _ = Seq.ofAsyncSeq source |> Seq.toList
2027+
Assert.Fail("Expected exception to be thrown")
2028+
with
2029+
| ex when ex.Message = "test exception" ->
2030+
() // Expected
2031+
| ex ->
2032+
Assert.Fail($"Unexpected exception: {ex.Message}")
2033+
19432034
#endif
2035+

0 commit comments

Comments
 (0)