Files
WoofWare.Whippet/Plugins/Json/WoofWare.Whippet.Plugin.Json/WoofWare.Whippet.Plugin.Json.Test/TestJsonParse.fs
Patrick Stevens da609db2ce
Some checks are pending
.NET / build (Debug) (push) Waiting to run
.NET / build (Release) (push) Waiting to run
.NET / analyzers (push) Waiting to run
.NET / check-dotnet-format (push) Waiting to run
.NET / check-nix-format (push) Waiting to run
.NET / Check links (push) Waiting to run
.NET / Check flake (push) Waiting to run
.NET / nuget-pack (push) Waiting to run
.NET / expected-pack (push) Blocked by required conditions
.NET / check-accurate-generations (push) Waiting to run
.NET / all-required-checks-complete (push) Blocked by required conditions
.NET / nuget-publish (push) Blocked by required conditions
.NET / nuget-publish-fantomas (push) Blocked by required conditions
.NET / nuget-publish-json-plugin (push) Blocked by required conditions
.NET / nuget-publish-json-attrs (push) Blocked by required conditions
.NET / nuget-publish-argparser-plugin (push) Blocked by required conditions
.NET / nuget-publish-argparser-attrs (push) Blocked by required conditions
First release (#10)
2024-10-07 13:35:43 +01:00

64 lines
1.6 KiB
Forth

namespace WoofWare.Whippet.Plugin.Json.Test
open System.Text.Json.Nodes
open ConsumePlugin
open NUnit.Framework
open FsUnitTyped
[<TestFixture>]
module TestJsonParse =
let _canSeePastExtensionMethod = ToGetExtensionMethod.thisModuleWouldClash
[<Test>]
let ``Single example`` () =
let s =
"""
{
"a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"},
"e": ["something", "else"], "f": []
}
"""
let expected =
{
A = 3
B = "hello"
C = [ 6 ; 1 ]
D =
{
Thing = "oh hi"
}
E = [| "something" ; "else" |]
F = [||]
}
let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
actual |> shouldEqual expected
[<Test>]
let ``Inner example`` () =
let s =
"""{
"something": "oh hi"
}"""
let expected =
{
Thing = "oh hi"
}
let actual = s |> JsonNode.Parse |> InnerType.jsonParse
actual |> shouldEqual expected
[<TestCase("thing", SomeEnum.Thing)>]
[<TestCase("Thing", SomeEnum.Thing)>]
[<TestCase("THING", SomeEnum.Thing)>]
[<TestCase("blah", SomeEnum.Blah)>]
[<TestCase("Blah", SomeEnum.Blah)>]
[<TestCase("BLAH", SomeEnum.Blah)>]
let ``Can deserialise enum`` (str : string, expected : SomeEnum) =
sprintf "\"%s\"" str
|> JsonNode.Parse
|> SomeEnum.jsonParse
|> shouldEqual expected