Skip to content

Commit eccbb21

Browse files
xperiandriclaude
andcommitted
fixup! test: cover EquatableArray in F#
Use the ready-made `Assert.IsEmpty` for the span of the default value, and drop the `Assert.HasLength` that the previous fixup added to `Assert.fs`. MSTest 4.2.3 has no span overloads of `Assert.IsEmpty` and `Assert.HasCount` (newer versions have them), so the test checks the array that `ToArray` copies from the span; an empty span gives `Array.Empty`, so nothing is allocated. `Assert.fs` and `AssertExtensionsTests.fs` are the same as on `main` again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent c5ebef2 commit eccbb21

3 files changed

Lines changed: 5 additions & 43 deletions

File tree

‎tests/FSharp.Collections.Immutable.Tests/Assert.fs‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/// <summary>
22
/// Assertions on F# <see cref="T:Microsoft.FSharp.Core.FSharpOption`1"/>,
33
/// <see cref="T:Microsoft.FSharp.Core.FSharpValueOption`1"/> and <see cref="T:Microsoft.FSharp.Core.FSharpResult`2"/>
4-
/// values, and on the length of a span, as extensions of
5-
/// <see cref="T:Microsoft.VisualStudio.TestTools.UnitTesting.Assert"/>.
4+
/// values as extensions of <see cref="T:Microsoft.VisualStudio.TestTools.UnitTesting.Assert"/>.
65
/// <para>
76
/// The assertions whose names start with <c>Want</c> return the unwrapped value or fail the test; their <c>Is</c>
87
/// twins discard the value.
@@ -11,7 +10,6 @@
1110
[<AutoOpen>]
1211
module FSharp.Collections.Immutable.Tests.AssertExtensions
1312

14-
open System
1513
open System.Runtime.InteropServices
1614
open Microsoft.VisualStudio.TestTools.UnitTesting
1715

@@ -134,22 +132,3 @@ type Assert with
134132
/// </summary>
135133
static member inline ErrorEquals<'R, ^E> (expected : ^E, actual : Result<'R, ^E>, [<Optional>] message : string | null) =
136134
Assert.AreEqual (box expected, box (Assert.WantError (actual, message)), message)
137-
138-
/// <summary>
139-
/// Fails the test with <paramref name="message"/> unless <paramref name="actual"/> has exactly
140-
/// <paramref name="expected"/> elements.
141-
/// </summary>
142-
/// <remarks>
143-
/// <c>Assert.HasCount</c> takes an <see cref="T:System.Collections.Generic.IEnumerable`1"/>, which a span is not.
144-
/// </remarks>
145-
static member HasLength (expected : int, actual : ReadOnlySpan<'T>, [<Optional>] message : string | null) =
146-
let length = actual.Length
147-
148-
if length <> expected then
149-
let description =
150-
match message with
151-
| null
152-
| "" -> ""
153-
| message -> $" '{message}'"
154-
155-
Assert.Fail $"Assert.HasLength failed. Expected length: {expected}. Actual: {length}.{description}"

‎tests/FSharp.Collections.Immutable.Tests/AssertExtensionsTests.fs‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open System
44
open Microsoft.VisualStudio.TestTools.UnitTesting
55

66
/// <summary>
7-
/// The assertions on options, value options, results and the length of spans that extend
7+
/// The assertions on options, value options and results that extend
88
/// <see cref="T:Microsoft.VisualStudio.TestTools.UnitTesting.Assert"/>.
99
/// </summary>
1010
[<TestClass; AssertExtensionsTestCategory>]
@@ -154,22 +154,3 @@ type AssertExtensionsTests () =
154154
assertContains number "the number must be the default" "IsDefaultOf must fail with its message on a non-default number"
155155
let option = failureOf (fun () -> Assert.IsDefaultOf (Some 1, "the option must be the default"))
156156
assertContains option "the option must be the default" "IsDefaultOf must fail with its message on a non-default option"
157-
158-
// ---- span length ----
159-
160-
[<TestMethod; DataRow 0; DataRow 1; DataRow 5>]
161-
member _.``HasLength passes for a span of the expected length`` (length : int) =
162-
Assert.HasLength (length, ReadOnlySpan<int>(Array.zeroCreate length), "message")
163-
164-
[<TestMethod; DataRow 0; DataRow 3>]
165-
member _.``HasLength fails with the message and both lengths for a span of another length`` (expected : int) =
166-
let failure =
167-
failureOf (fun () -> Assert.HasLength (expected, ReadOnlySpan<int> [| 1; 2 |], "the span has the wrong length"))
168-
assertContains failure "the span has the wrong length" "HasLength must fail with its message"
169-
assertContains failure $"Expected length: %d{expected}." "HasLength must name the expected length"
170-
assertContains failure "Actual: 2." "HasLength must name the actual length"
171-
172-
[<TestMethod>]
173-
member _.``HasLength fails without a message too`` () =
174-
let failure = failureOf (fun () -> Assert.HasLength (1, ReadOnlySpan<int>.Empty))
175-
assertContains failure "Expected length: 1. Actual: 0." "HasLength must name both lengths without a message"

‎tests/FSharp.Collections.Immutable.Tests/EquatableArray/EquatableArrayDefaultValueTests.fs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ type EquatableArrayDefaultValueTests () =
6969
(EquatableArray.toImmutableArray defaultValue).IsDefault,
7070
"toImmutableArray must not give a default ImmutableArray"
7171
)
72-
Assert.HasLength (0, defaultValue.AsSpan (), "the span of the default value must be empty")
72+
// MSTest 4.2.3 has no span overloads of Assert.IsEmpty and Assert.HasCount (newer versions have them), so the span
73+
// goes through an array; an empty span gives Array.Empty, so the test allocates nothing
74+
Assert.IsEmpty (defaultValue.AsSpan().ToArray(), "the span of the default value must be empty")
7375

7476
[<TestMethod>]
7577
member _.``the default value formats as an empty F# array`` () =

0 commit comments

Comments
 (0)