Skip to content

Commit 4997610

Browse files
xperiandriclaude
andcommitted
fixup! test: FrozenMap against the map contracts
`yield!` of a `null` array of struct pairs and of a `null` frozen map throws `ArgumentNullException` that names the parameter (`pairs`, `table`) when the expression runs it: one test with a row for each member. The suite has 4296 tests on `net8.0` and 4310 on `net10.0`, 554 and 568 of them for `FrozenMap`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 3e73414 commit 4997610

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎tests/FSharp.Collections.Immutable.Tests/FrozenMap/FrozenMapComputationExpressionTests.fs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ type FrozenMapComputationExpressionTests () =
7272
|> ignore)
7373
|]
7474

75+
/// The expressions that take an array or a frozen map, by name, with the name of the parameter and the expression on a
76+
/// null one. They are not sequences by type, so the contract of the sequences does not reach them. The expression
77+
/// rejects the input when the member runs, and not when the buffer enumerates it.
78+
static let nullCollectionExpressions : Map<string, struct (string * (unit -> unit))> =
79+
Map.ofArray [|
80+
"yield! of an array of struct pairs",
81+
struct ("pairs",
82+
fun () ->
83+
frozenMap { yield! Unchecked.defaultof<struct (int * string) array> }
84+
|> ignore)
85+
"yield! of a frozen map",
86+
struct ("table",
87+
fun () ->
88+
frozenMap { yield! Unchecked.defaultof<FrozenMap<int, string>> }
89+
|> ignore)
90+
|]
91+
7592
/// The expressions that take a sequence, by name, with the name of the sequence parameter and the expression on a
7693
/// default flat list that is given as the sequence. A default flat list converts to a sequence without a check and fails
7794
/// with InvalidOperationException when the sequence is enumerated. The last row gives a sequence of objects, which a
@@ -113,6 +130,9 @@ type FrozenMapComputationExpressionTests () =
113130
/// The names of the expressions that take a sequence and are given a default flat list, as the rows of their test.
114131
static member DefaultSequenceExpressions = defaultSequenceExpressions.Keys
115132

133+
/// The names of the expressions that take an array or a frozen map and are given a null one, as the rows of their test.
134+
static member NullCollectionExpressions = nullCollectionExpressions.Keys
135+
116136
[<TestMethod>]
117137
member _.``an expression without bindings is empty`` () =
118138
let table : FrozenMap<int, string> = frozenMap { () }
@@ -181,6 +201,13 @@ type FrozenMapComputationExpressionTests () =
181201
let struct (paramName, run) = defaultSequenceExpressions[name]
182202
FlatListAssert.RejectsNull ($"frozenMap %s{name}", paramName, run)
183203

204+
[<TestMethod; DynamicData(nameof FrozenMapComputationExpressionTests.NullCollectionExpressions)>]
205+
member _.``yield! rejects a null array and a null frozen map`` (name : string) =
206+
// A null array or frozen map fails with NullReferenceException when the buffer enumerates it; the member rejects it
207+
// as it does a null sequence, when the expression runs it
208+
let struct (paramName, run) = nullCollectionExpressions[name]
209+
FlatListAssert.RejectsNull ($"frozenMap %s{name}", paramName, run)
210+
184211
[<TestMethod>]
185212
member _.``yield! and for take a flat list that is not default as a sequence, also one of strings as objects`` () =
186213
let structPairs = FlatList.ofArray [| struct (1, "one"); struct (2, "two") |] :> seq<_>

0 commit comments

Comments
 (0)