mirror of
https://github.com/logos-storage/nim-serde.git
synced 2026-01-03 22:23:11 +00:00
59 lines
1.5 KiB
Nim
59 lines
1.5 KiB
Nim
import std/unittest
|
|
|
|
import pkg/serde
|
|
|
|
suite "json serialization pragmas":
|
|
|
|
test "fails to compile when object marked with 'serialize' specifies options":
|
|
type
|
|
MyObj {.serialize(key="test", ignore=true).} = object
|
|
|
|
check not compiles(%MyObj())
|
|
|
|
test "compiles when object marked with 'serialize' only":
|
|
type
|
|
MyObj {.serialize.} = object
|
|
|
|
check compiles(%MyObj())
|
|
|
|
test "fails to compile when field marked with 'deserialize' specifies mode":
|
|
type
|
|
MyObj = object
|
|
field {.deserialize(mode=OptIn).}: bool
|
|
|
|
check not compiles(MyObj.fromJson("""{"field":true}"""))
|
|
|
|
test "compiles when object marked with 'deserialize' specifies mode":
|
|
type
|
|
MyObj {.deserialize(mode=OptIn).} = object
|
|
field: bool
|
|
|
|
check compiles(MyObj.fromJson("""{"field":true}"""))
|
|
|
|
test "fails to compile when object marked with 'deserialize' specifies key":
|
|
type
|
|
MyObj {.deserialize("test").} = object
|
|
field: bool
|
|
|
|
check not compiles(MyObj.fromJson("""{"field":true}"""))
|
|
|
|
test "compiles when field marked with 'deserialize' specifies key":
|
|
type
|
|
MyObj = object
|
|
field {.deserialize("test").}: bool
|
|
|
|
check compiles(MyObj.fromJson("""{"field":true}"""))
|
|
|
|
test "compiles when field marked with empty 'deserialize'":
|
|
type
|
|
MyObj = object
|
|
field {.deserialize.}: bool
|
|
|
|
check compiles(MyObj.fromJson("""{"field":true}"""))
|
|
|
|
test "compiles when field marked with 'serialize'":
|
|
type
|
|
MyObj = object
|
|
field {.serialize.}: bool
|
|
|
|
check compiles(%MyObj()) |