-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for
losslessOption
Fix #81 Tag: core
- Loading branch information
1 parent
5da2bf5
commit 5f380a0
Showing
11 changed files
with
445 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module Thoth.Json.Tests.BackAndForth | ||
|
||
open Thoth.Json.Tests.Testing | ||
open Thoth.Json.Core | ||
open Fable.Pyxpecto | ||
|
||
let tests (runner: TestRunner<_, _>) = | ||
testList | ||
"Thoth.Json - BackAndForth" | ||
[ | ||
|
||
testCase "losslessOption is symmetric" | ||
<| fun _ -> | ||
// Simple Some 'T | ||
let expected = Some 42 | ||
|
||
let json = | ||
expected | ||
|> Encode.losslessOption Encode.int | ||
|> runner.Encode.toString 0 | ||
|
||
let decoded = | ||
runner.Decode.fromString | ||
(Decode.losslessOption Decode.int) | ||
json | ||
|
||
equal (Ok expected) decoded | ||
|
||
// Simple None | ||
|
||
let expected = None | ||
|
||
let json = | ||
expected | ||
|> Encode.losslessOption Encode.int | ||
|> runner.Encode.toString 0 | ||
|
||
let decoded = | ||
runner.Decode.fromString | ||
(Decode.losslessOption Decode.int) | ||
json | ||
|
||
equal (Ok expected) decoded | ||
|
||
// Nested option with value | ||
|
||
let expected = Some(Some(Some 42)) | ||
|
||
let json = | ||
expected | ||
|> Encode.losslessOption ( | ||
Encode.losslessOption (Encode.losslessOption Encode.int) | ||
) | ||
|> runner.Encode.toString 0 | ||
|
||
let decoded = | ||
runner.Decode.fromString | ||
(Decode.losslessOption ( | ||
Decode.losslessOption ( | ||
Decode.losslessOption Decode.int | ||
) | ||
)) | ||
json | ||
|
||
equal (Ok expected) decoded | ||
|
||
// Nested option with None | ||
|
||
let expected = Some(Some None) | ||
|
||
let json = | ||
expected | ||
|> Encode.losslessOption ( | ||
Encode.losslessOption (Encode.losslessOption Encode.int) | ||
) | ||
|> runner.Encode.toString 0 | ||
|
||
let decoded = | ||
runner.Decode.fromString | ||
(Decode.losslessOption ( | ||
Decode.losslessOption ( | ||
Decode.losslessOption Decode.int | ||
) | ||
)) | ||
json | ||
|
||
equal (Ok expected) decoded | ||
|
||
] |
Oops, something went wrong.