Add JSON parse source gen (#9)

This commit is contained in:
Patrick Stevens
2023-12-27 11:46:12 +00:00
committed by GitHub
parent 055aad8c5e
commit 39d603c317
22 changed files with 882 additions and 145 deletions

View File

@@ -9,12 +9,16 @@
<ItemGroup>
<Compile Include="TestSurface.fs" />
<Compile Include="TestRemoveOptions.fs" />
<Compile Include="TestJsonParse.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ApiSurface" Version="4.0.8" />
<PackageReference Include="ApiSurface" Version="4.0.25" />
<PackageReference Include="FsCheck" Version="2.16.6" />
<PackageReference Include="FsUnit" Version="5.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
@@ -22,6 +26,7 @@
<ItemGroup>
<ProjectReference Include="..\MyriadPlugin\MyriadPlugin.fsproj" />
<ProjectReference Include="..\ConsumePlugin\ConsumePlugin.fsproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,31 @@
namespace MyriadPlugin.Test
open System.Text.Json.Nodes
open ConsumePlugin
open NUnit.Framework
open FsUnitTyped
[<TestFixture>]
module TestJsonParse =
[<Test>]
let ``Single example`` () =
let s =
"""
{
"a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}
}
"""
let expected =
{
A = 3
B = "hello"
C = [ 6 ; 1 ]
D =
{
Thing = "oh hi"
}
}
let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
actual |> shouldEqual expected

View File

@@ -0,0 +1,24 @@
namespace MyriadPlugin.Test
open FsCheck
open ConsumePlugin
open NUnit.Framework
open FsUnitTyped
module TestRemoveOptions =
let shortenProperty (f : RecordType) =
let g = RecordType.shorten f
g.B |> shouldEqual f.B
g.C |> shouldEqual f.C
match f.A with
| None -> g.A |> shouldEqual (RecordType.DefaultA ())
| Some a -> g.A |> shouldEqual a
true
[<Test>]
let ``shorten works`` () =
Check.QuickThrowOnFailure shortenProperty