From bb5fc5ae430e7528650b202532827c789ec690bc Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Wed, 24 Jan 2024 02:01:25 +0000 Subject: [PATCH] Polish tests --- .../SerdesTests.fs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/FsCodec.SystemTextJson.Tests/SerdesTests.fs b/tests/FsCodec.SystemTextJson.Tests/SerdesTests.fs index 760cebb..bf7540e 100644 --- a/tests/FsCodec.SystemTextJson.Tests/SerdesTests.fs +++ b/tests/FsCodec.SystemTextJson.Tests/SerdesTests.fs @@ -80,7 +80,7 @@ let [] ``RejectNullStringConverter rejects null strings`` () = let value = { c = 1; d = null } raises <@ serdes.Serialize value @> -type WithList = { x: int; y: list } +type WithList = { x: int; y: list; z: Set } let [] ``RejectNullConverter rejects null lists and Sets`` () = #if false // requires WithList to be CLIMutable, which would be a big imposition @@ -93,18 +93,28 @@ let [] ``RejectNullConverter rejects null lists and Sets`` () = if pt.IsGenericType && (let gtd = pt.GetGenericTypeDefinition() in gtd = typedefof> || gtd = typedefof>) then p.IsRequired <- true) let serdes = Options.Create(TypeInfoResolver = tir) |> Serdes + raises <@ serdes.Deserialize """{"x":0}""" @> #else let serdes = Options.Create(rejectNull = true) |> Serdes -#endif // Fails with NRE when RejectNullConverter delegates to Default list Converter // seems akin to https://github.com/dotnet/runtime/issues/86483 - let res = serdes.Deserialize """{"x":0,"y":[1]}""" - test <@ [1] = res.y @> + // let res = serdes.Deserialize """{"x":0,"y":[1]}""" + // test <@ [1] = res.y @> + // PROBLEM: Doesn't raise raises <@ serdes.Deserialize """{"x":0}""" @> - // PROBLEM: there doesn't seem to be a way to intercept explicitly passed nulls + // PROBLEM: doesnt raise - there doesn't seem to be a way to intercept explicitly passed nulls // raises <@ serdes.Deserialize """{"x":0,"y":null}""" @> +#endif + +#if false // I guess TypeShape is doing a reasaonable thing not propagating + // PROBLEM: TypeShape.Generic.exists does not call the predicate if the list or set is `null` + let res = serdes.Deserialize """{"x":0}""" + let hasNullList = TypeShape.Generic.exists (fun (x: int list) -> obj.ReferenceEquals(x, null)) + let hasNullSet = TypeShape.Generic.exists (fun (x: Set) -> obj.ReferenceEquals(x, null)) + test <@ hasNullList res && hasNullSet res @> +#endif let [] ``RejectNullStringConverter serializes strings correctly`` () = let serdes = Serdes(Options.Create(rejectNullStrings = true))