@@ -47,30 +47,20 @@ type SortedMapComputationExpressionTests () =
4747 })
4848 |]
4949
50- /// The expressions that take a sequence, an array or a sorted map, by name, with the name of the parameter and the
51- /// expression on a null input . The expression rejects the input when the member runs, and not when the buffer does.
52- static let nullInputExpressions : Map < string , struct ( string * ( unit -> unit ))> =
50+ /// The expressions that take a sequence, by name, with the name of the sequence parameter and the expression on a null
51+ /// sequence . The expression rejects the sequence when the member runs, and not when the buffer does.
52+ static let nullSequenceExpressions : Map < string , struct ( string * ( unit -> unit ))> =
5353 Map.ofArray [|
5454 " yield! of a sequence of struct pairs" ,
5555 struct ( " pairs" ,
5656 fun () ->
5757 sortedMap { yield ! Unchecked.defaultof< seq< struct ( int * string)>> }
5858 |> ignore)
59- " yield! of an array of struct pairs" ,
60- struct ( " pairs" ,
61- fun () ->
62- sortedMap { yield ! Unchecked.defaultof< struct ( int * string) array> }
63- |> ignore)
6459 " yield! of a sequence of key/value pairs" ,
6560 struct ( " pairs" ,
6661 fun () ->
6762 sortedMap { yield ! Unchecked.defaultof< seq< KeyValuePair< int, string>>> }
6863 |> ignore)
69- " yield! of a sorted map" ,
70- struct ( " table" ,
71- fun () ->
72- sortedMap { yield ! Unchecked.defaultof< SortedMap< int, string>> }
73- |> ignore)
7464 " for" ,
7565 struct ( " source" ,
7666 fun () ->
@@ -81,6 +71,23 @@ type SortedMapComputationExpressionTests () =
8171 |> ignore)
8272 |]
8373
74+ /// The expressions that take an array or a sorted map, by name, with the name of the parameter and the expression on a
75+ /// null one. A null array or sorted map is not a sequence for the member, which would fail with NullReferenceException
76+ /// when the buffer runs; the expression rejects it when the member runs.
77+ static let nullCollectionExpressions : Map < string , struct ( string * ( unit -> unit ))> =
78+ Map.ofArray [|
79+ " yield! of an array of struct pairs" ,
80+ struct ( " pairs" ,
81+ fun () ->
82+ sortedMap { yield ! Unchecked.defaultof< struct ( int * string) array> }
83+ |> ignore)
84+ " yield! of a sorted map" ,
85+ struct ( " table" ,
86+ fun () ->
87+ sortedMap { yield ! Unchecked.defaultof< SortedMap< int, string>> }
88+ |> ignore)
89+ |]
90+
8491 /// The expressions that take a sequence, by name, with the name of the sequence parameter and the expression on a
8592 /// default flat list that is given as the sequence. A default flat list converts to a sequence without a check and fails
8693 /// with InvalidOperationException when the sequence is enumerated. The last row gives a sequence of objects, which a
@@ -116,9 +123,11 @@ type SortedMapComputationExpressionTests () =
116123 /// equal.
117124 static member EqualValueExpressions = equalValueExpressions.Keys
118125
119- /// The names of the expressions that take a sequence, an array or a sorted map and are given a null one, as the rows of
120- /// their test.
121- static member NullInputExpressions = nullInputExpressions.Keys
126+ /// The names of the expressions that take an array or a sorted map and are given a null one, as the rows of their test.
127+ static member NullCollectionExpressions = nullCollectionExpressions.Keys
128+
129+ /// The names of the expressions that take a sequence and are given a null one, as the rows of their test.
130+ static member NullSequenceExpressions = nullSequenceExpressions.Keys
122131
123132 /// The names of the expressions that take a sequence and are given a default flat list, as the rows of their test.
124133 static member DefaultSequenceExpressions = defaultSequenceExpressions.Keys
@@ -369,9 +378,14 @@ type SortedMapComputationExpressionTests () =
369378 Assert.AreEqual< int>( 3 , SortedMap.count table, " SortedMapCE must merge the keys that the comparer considers equal" )
370379 Assert.AreEqual< int>( 4 , SortedMap.find " a" table, " SortedMapCE must keep the last binding of equal keys" )
371380
372- [<TestMethod; DynamicData( nameof SortedMapComputationExpressionTests.NullInputExpressions) >]
373- member _. ``yield ! and for reject a null input`` ( name : string ) =
374- let struct ( paramName , run ) = nullInputExpressions[ name]
381+ [<TestMethod; DynamicData( nameof SortedMapComputationExpressionTests.NullSequenceExpressions) >]
382+ member _. ``yield ! and for reject a null sequence`` ( name : string ) =
383+ let struct ( paramName , run ) = nullSequenceExpressions[ name]
384+ FlatListAssert.RejectsNull ( $" sortedMap %s {name}" , paramName, run)
385+
386+ [<TestMethod; DynamicData( nameof SortedMapComputationExpressionTests.NullCollectionExpressions) >]
387+ member _. ``yield ! rejects a null array and a null sorted map`` ( name : string ) =
388+ let struct ( paramName , run ) = nullCollectionExpressions[ name]
375389 FlatListAssert.RejectsNull ( $" sortedMap %s {name}" , paramName, run)
376390
377391 [<TestMethod; DynamicData( nameof SortedMapComputationExpressionTests.DefaultSequenceExpressions) >]
0 commit comments