mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-11 15:08:40 +00:00
Add JSON parse source gen (#9)
This commit is contained in:
@@ -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>
|
||||
|
31
MyriadPlugin.Test/TestJsonParse.fs
Normal file
31
MyriadPlugin.Test/TestJsonParse.fs
Normal 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
|
24
MyriadPlugin.Test/TestRemoveOptions.fs
Normal file
24
MyriadPlugin.Test/TestRemoveOptions.fs
Normal 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
|
Reference in New Issue
Block a user