11namespace WoofWare.Myriad.Plugins.Test
22
3+ open System
4+ open System.Collections .Generic
5+ open System.Globalization
36open System.Text .Json .Nodes
47open ConsumePlugin
58open NUnit.Framework
@@ -14,7 +17,7 @@ module TestJsonParse =
1417 let s =
1518 """
1619{
17- "a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"},
20+ "a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}, "g": {},
1821 "e": ["something", "else"], "f": []
1922}
2023"""
@@ -30,6 +33,61 @@ module TestJsonParse =
3033 }
3134 E = [| " something" ; " else" |]
3235 F = [||]
36+ G = dict []
37+ }
38+
39+ let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
40+ actual |> shouldEqual expected
41+
42+ [<Test>]
43+ let ``Single example with explicit null`` () =
44+ let s =
45+ """
46+ {
47+ "a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}, "g": {"hi": null},
48+ "e": ["something", "else"], "f": []
49+ }
50+ """
51+
52+ let expected =
53+ {
54+ A = 3
55+ B = " hello"
56+ C = [ 6 ; 1 ]
57+ D =
58+ {
59+ Thing = " oh hi"
60+ }
61+ E = [| " something" ; " else" |]
62+ F = [||]
63+ G = dict [ " hi" , Nullable () ]
64+ }
65+
66+ let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
67+ actual |> shouldEqual expected
68+
69+ [<Test>]
70+ let ``Single example , nullable provided`` () =
71+ let s =
72+ """
73+ {
74+ "a": 3, "another-thing": "hello", "hi": [6, 1], "d": {"something": "oh hi"}, "g": {"hi": 3},
75+ "e": ["something", "else"], "f": []
76+ }
77+ """
78+
79+ let expected =
80+ {
81+ A = 3
82+ B = " hello"
83+ C = [ 6 ; 1 ]
84+ D =
85+ {
86+ Thing = " oh hi"
87+ }
88+ E = [| " something" ; " else" |]
89+ F = [||]
90+ G = dict [ " hi" , Nullable 3 ]
3391 }
3492
3593 let actual = s |> JsonNode.Parse |> JsonRecordType.jsonParse
@@ -61,3 +119,21 @@ module TestJsonParse =
61119 |> JsonNode.Parse
62120 |> SomeEnum.jsonParse
63121 |> shouldEqual expected
122+
123+ [<Test>]
124+ [<NonParallelizable>]
125+ let ``Bigints are parsed in the invariant culture`` () =
126+ let currentCulture = CultureInfo.CurrentCulture
127+ let desiredCulture = CultureInfo.CreateSpecificCulture " for-test"
128+ desiredCulture.NumberFormat.NegativeSign <- " !"
129+
130+ CultureInfo.CurrentCulture <- desiredCulture
131+
132+ try
133+ """ {"bigNum": -3}"""
134+ |> JsonNode.Parse
135+ |> ContainsABigInt.jsonParse
136+ |> _. BigNum
137+ |> shouldEqual ( bigint - 3 )
138+ finally
139+ CultureInfo.CurrentCulture <- currentCulture
0 commit comments