Skip to content

Commit 3e234e8

Browse files
xperiandriclaude
andcommitted
fixup! test: shared contracts of the map modules, run for HashMap and IMap
The tests of the computation expression get a row for `yield!` of a null array of struct pairs and of a null hash map, which must throw `ArgumentNullException` that names `pairs` or `table` when the expression runs the member. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 6fc99a0 commit 3e234e8

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapComputationExpressionTests.fs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,30 @@ type HashMapComputationExpressionTests () =
105105
|> ignore)
106106
|]
107107

108+
/// The expressions that take an array or a hash map, by name, with the name of the parameter and the expression on a null
109+
/// one. A null array or hash map is not a sequence for the member, which would fail with NullReferenceException when
110+
/// the buffer runs; the expression rejects it when the member runs.
111+
static let nullCollectionExpressions : Map<string, struct (string * (unit -> unit))> =
112+
Map.ofArray [|
113+
"yield! of an array of struct pairs",
114+
struct ("pairs",
115+
fun () ->
116+
hashMap { yield! Unchecked.defaultof<struct (int * string) array> }
117+
|> ignore)
118+
"yield! of a hash map",
119+
struct ("table",
120+
fun () ->
121+
hashMap { yield! Unchecked.defaultof<HashMap<int, string>> }
122+
|> ignore)
123+
|]
124+
108125
/// The names of the members that set a binding, as the rows of the test of the values that the default comparer finds
109126
/// equal.
110127
static member EqualValueExpressions = equalValueExpressions.Keys
111128

129+
/// The names of the expressions that take an array or a hash map and are given a null one, as the rows of their test.
130+
static member NullCollectionExpressions = nullCollectionExpressions.Keys
131+
112132
/// The names of the expressions that take a sequence and are given a null one, as the rows of their test.
113133
static member NullSequenceExpressions = nullSequenceExpressions.Keys
114134

@@ -324,6 +344,11 @@ type HashMapComputationExpressionTests () =
324344
let struct (paramName, run) = nullSequenceExpressions[name]
325345
FlatListAssert.RejectsNull ($"hashMap %s{name}", paramName, run)
326346

347+
[<TestMethod; DynamicData(nameof HashMapComputationExpressionTests.NullCollectionExpressions)>]
348+
member _.``yield! rejects a null array and a null hash map`` (name : string) =
349+
let struct (paramName, run) = nullCollectionExpressions[name]
350+
FlatListAssert.RejectsNull ($"hashMap %s{name}", paramName, run)
351+
327352
[<TestMethod; DynamicData(nameof HashMapComputationExpressionTests.DefaultSequenceExpressions)>]
328353
member _.``yield! and for reject a default flat list given as a sequence`` (name : string) =
329354
// The member rejects it as the functions of HashMap do, when the expression runs it and not when the buffer does

0 commit comments

Comments
 (0)