import std/math import std/unittest import pkg/serde import pkg/questionable import pkg/questionable/results suite "json - deserialize std types": test "deserializes NaN float": check %NaN == newJString("nan") test "deserialize enum": type MyEnum = enum First Second let json = newJString("Second") check !MyEnum.fromJson(json) == Second test "deserializes Option[T] when has a value": let json = newJInt(1) check (!fromJson(?int, json) == some 1) test "deserializes Option[T] when doesn't have a value": let json = newJNull() check !fromJson(?int, json) == none int test "deserializes float": let json = newJFloat(1.234) check !float.fromJson(json) == 1.234 test "deserializes Inf float": let json = newJString("inf") check !float.fromJson(json) == Inf test "deserializes -Inf float": let json = newJString("-inf") check !float.fromJson(json) == -Inf test "deserializes NaN float": let json = newJString("nan") check (!float.fromJson(json)).isNaN test "deserializes array to sequence": let expected = @[1, 2, 3] let json = !JsonNode.parse("[1,2,3]") check !seq[int].fromJson(json) == expected test "deserializes uints int.high or smaller": let largeUInt: uint = uint(int.high) let json = newJInt(BiggestInt(largeUInt)) check !uint.fromJson(json) == largeUInt test "deserializes large uints": let largeUInt: uint = uint(int.high) + 1'u let json = newJString($BiggestUInt(largeUInt)) check !uint.fromJson(json) == largeUInt