-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathTuple.fs
40 lines (33 loc) · 1.32 KB
/
Tuple.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace FSharp.Json
module Tuple =
open NUnit.Framework
type TheTuple = {
value: string*int*bool
}
[<Test>]
let ``Tuple serialization/deserialization`` () =
let expected = { TheTuple.value = ("The string", 123, true) }
let json = Json.serialize(expected)
let actual = Json.deserialize<TheTuple> json
Assert.AreEqual(expected, actual)
[<Test>]
let ``Tuple serialized as array`` () =
let value = { TheTuple.value = ("The string", 123, true) }
let actual = Json.serializeU value
let expected = """{"value":["The string",123,true]}"""
Assert.AreEqual(expected, actual)
type TheTupleWithOption = {
value: string*int option*bool
}
[<Test>]
let ``Tuple with optional serialization`` () =
let value = { TheTupleWithOption.value = ("The string", None, true) }
let actual = Json.serializeU value
let expected = """{"value":["The string",null,true]}"""
Assert.AreEqual(expected, actual)
[<Test>]
let ``Tuple with optional deserialization`` () =
let expected = { TheTupleWithOption.value = ("The string", None, true) }
let json = """{"value":["The string",null,true]}"""
let actual = Json.deserialize<TheTupleWithOption> json
Assert.AreEqual(expected, actual)