|
2 | 2 | module FSharp.Data.GraphQL.Tests.ObjectListFilter.TypeCoercion.FilterTests |
3 | 3 |
|
4 | 4 | open Xunit |
| 5 | +open System |
5 | 6 | open FSharp.Data.GraphQL.Server.Middleware |
6 | 7 | open FSharp.Data.GraphQL.Tests.ObjectListFilter.TypeCoercion.Common |
7 | 8 |
|
@@ -197,3 +198,34 @@ let ``coerceFilter coerces values inside NOT`` () = |
197 | 198 | let result = applyFilter filter |
198 | 199 | result |> List.length |> equals 2 |
199 | 200 | result |> List.map (fun e -> e.Name) |> List.sort |> equals [ "Bob"; "Charlie" ] |
| 201 | + |
| 202 | +// ────────────────────────────────────────────────────────────────────────────── |
| 203 | +// StringComparer on non-string field must not throw InvalidCastException |
| 204 | +// ────────────────────────────────────────────────────────────────────────────── |
| 205 | + |
| 206 | +[<Fact>] |
| 207 | +let ``Equals with StringComparer on non-string field does not throw InvalidCastException`` () = |
| 208 | + // WrappedGuid is not a string; passing StringComparer.OrdinalIgnoreCase used to |
| 209 | + // crash with InvalidCastException because the code unconditionally cast f.Value |
| 210 | + // to string when a StringComparer was present. |
| 211 | + let filter = |
| 212 | + Equals ( |
| 213 | + { FieldName = "wrappedGuid"; Value = WrappedGuid (Guid.Parse "cccccccc-cccc-cccc-cccc-cccccccccccc") }, |
| 214 | + StringComparer.OrdinalIgnoreCase |
| 215 | + ) |
| 216 | + let result = applyFilter filter |
| 217 | + result |> List.length |> equals 1 |
| 218 | + (List.head result).Name |> equals "Charlie" |
| 219 | + |
| 220 | +[<Fact>] |
| 221 | +let ``Not Equals with StringComparer on non-string field does not throw InvalidCastException`` () = |
| 222 | + let filter = |
| 223 | + Not ( |
| 224 | + Equals ( |
| 225 | + { FieldName = "wrappedGuid"; Value = WrappedGuid (Guid.Parse "cccccccc-cccc-cccc-cccc-cccccccccccc") }, |
| 226 | + StringComparer.OrdinalIgnoreCase |
| 227 | + ) |
| 228 | + ) |
| 229 | + let result = applyFilter filter |
| 230 | + result |> List.length |> equals 2 |
| 231 | + result |> List.map (fun e -> e.Name) |> List.sort |> equals [ "Alice"; "Bob" ] |
0 commit comments