@@ -236,7 +236,7 @@ proc readValue*(r: var JsonReader[DefaultFlavor], value: var MyCaseObject)
236236{.pop .}
237237
238238var
239- customVisit: TokenRegistry
239+ customVisit {. global , compileTime .} : TokenRegistry
240240
241241Json .useCustomSerialization (WithCustomFieldRule .intVal):
242242 read:
@@ -377,14 +377,14 @@ suite "toJson tests":
377377 " abc" .toJson == " \" abc\" "
378378
379379 test " float" :
380- Json .roundtripTest 1.23 , " 1.23"
381- Json .roundtripTest 1.23 'f32 , " 1.23"
382- Json .roundtripTest 1.23 'f64 , " 1.23"
380+ Json .roundtripChecks 1.23 , " 1.23"
381+ Json .roundtripChecks 1.23 'f32 , " 1.23"
382+ Json .roundtripChecks 1.23 'f64 , " 1.23"
383383
384384 test " enums" :
385- Json .roundtripTest x0, " \" x0\" "
386- Json .roundtripTest x1, " \" x1\" "
387- Json .roundtripTest x2, " \" x2\" "
385+ Json .roundtripChecks x0, " \" x0\" "
386+ Json .roundtripChecks x1, " \" x1\" "
387+ Json .roundtripChecks x2, " \" x2\" "
388388 expect UnexpectedTokenError :
389389 discard Json .decode (" 0" , EnumTestX )
390390 expect UnexpectedTokenError :
@@ -406,10 +406,10 @@ suite "toJson tests":
406406 expect UnexpectedValueError :
407407 discard Json .decode (" \" 0\" " , EnumTestX )
408408
409- Json .roundtripTest y1, " \" y1\" "
410- Json .roundtripTest y3, " \" y3\" "
411- Json .roundtripTest y4, " \" y4\" "
412- Json .roundtripTest y6, " \" y6\" "
409+ Json .roundtripChecks y1, " \" y1\" "
410+ Json .roundtripChecks y3, " \" y3\" "
411+ Json .roundtripChecks y4, " \" y4\" "
412+ Json .roundtripChecks y6, " \" y6\" "
413413 check:
414414 Json .decode (" 1" , EnumTestY ) == y1
415415 Json .decode (" 3" , EnumTestY ) == y3
@@ -438,9 +438,9 @@ suite "toJson tests":
438438 expect UnexpectedValueError :
439439 discard Json .decode (" \" 1\" " , EnumTestY )
440440
441- Json .roundtripTest z1, " \" aaa\" "
442- Json .roundtripTest z2, " \" bbb\" "
443- Json .roundtripTest z3, " \" ccc\" "
441+ Json .roundtripChecks z1, " \" aaa\" "
442+ Json .roundtripChecks z2, " \" bbb\" "
443+ Json .roundtripChecks z3, " \" ccc\" "
444444 expect UnexpectedTokenError :
445445 discard Json .decode (" 0" , EnumTestZ )
446446 expect UnexpectedValueError :
@@ -458,9 +458,9 @@ suite "toJson tests":
458458 expect UnexpectedValueError :
459459 discard Json .decode (" \"\ud83d\udc3c\" " , EnumTestZ )
460460
461- Json .roundtripTest n1, " \" aaa\" "
462- Json .roundtripTest n2, " \" bbb\" "
463- Json .roundtripTest n3, " \" ccc\" "
461+ Json .roundtripChecks n1, " \" aaa\" "
462+ Json .roundtripChecks n2, " \" bbb\" "
463+ Json .roundtripChecks n3, " \" ccc\" "
464464 check:
465465 Json .decode (" \" aAA\" " , EnumTestN ) == n1
466466 Json .decode (" \" bBB\" " , EnumTestN ) == n2
@@ -491,9 +491,9 @@ suite "toJson tests":
491491 expect UnexpectedValueError :
492492 discard Json .decode (" \"\ud83d\udc3c\" " , EnumTestN )
493493
494- Json .roundtripTest o1, " \" o1\" "
495- Json .roundtripTest o2, " \" o2\" "
496- Json .roundtripTest o3, " \" o3\" "
494+ Json .roundtripChecks o1, " \" o1\" "
495+ Json .roundtripChecks o2, " \" o2\" "
496+ Json .roundtripChecks o3, " \" o3\" "
497497 check:
498498 Json .decode (" \" o_1\" " , EnumTestO ) == o1
499499 Json .decode (" \" o_2\" " , EnumTestO ) == o2
@@ -656,7 +656,10 @@ suite "toJson tests":
656656 let decoded = try :
657657 Json .decode (json, Simple , requireAllFields = true , allowUnknownFields = true )
658658 except SerializationError as err:
659- checkpoint " Unexpected deserialization failure: " & err.formatMsg (" <input>" )
659+ when nimvm :
660+ checkpoint " Unexpected deserialization failure: " & err.msg
661+ else :
662+ checkpoint " Unexpected deserialization failure: " & err.formatMsg (" <input>" )
660663 raise
661664
662665 check:
@@ -737,8 +740,8 @@ suite "toJson tests":
737740 h3 = Json .decode (""" {"r":{"distance":3,"x":1,"y":"2"}} """ ,
738741 HoldsOption , requireAllFields = true )
739742
740- Json .roundtripTest h1, """ {"r":null,"o":{"distance":3,"x":1,"y":"2"}} """
741- Json .roundtripTest h2, """ {"r":{"distance":3,"x":1,"y":"2"}} """
743+ Json .roundtripChecks h1, """ {"r":null,"o":{"distance":3,"x":1,"y":"2"}} """
744+ Json .roundtripChecks h2, """ {"r":{"distance":3,"x":1,"y":"2"}} """
742745
743746 check h3 == h2
744747
@@ -754,10 +757,10 @@ suite "toJson tests":
754757 h5 = OtherOptionTest (b: some Meter (2 ))
755758 h6 = OtherOptionTest (a: some Meter (3 ), b: some Meter (4 ))
756759
757- Json .roundtripTest h3, """ {} """
758- Json .roundtripTest h4, """ {"a":1} """
759- Json .roundtripTest h5, """ {"b":2} """
760- Json .roundtripTest h6, """ {"a":3,"b":4} """
760+ Json .roundtripChecks h3, """ {} """
761+ Json .roundtripChecks h4, """ {"a":1} """
762+ Json .roundtripChecks h5, """ {"b":2} """
763+ Json .roundtripChecks h6, """ {"a":3,"b":4} """
761764
762765 let
763766 arr = @ [some h3, some h4, some h5, some h6, none (OtherOptionTest )]
@@ -796,11 +799,11 @@ suite "toJson tests":
796799 # lent iterator error
797800 let a = a
798801 let b = b
799- Json .roundtripTest NestedOptionTest (c: a, d: b), results[r]
802+ Json .roundtripChecks NestedOptionTest (c: a, d: b), results[r]
800803 r.inc
801804
802- Json .roundtripTest SeqOptionTest (a: @ [some 5 .Meter , none Meter ], b: Meter (5 )), """ {"a":[5,null],"b":5} """
803- Json .roundtripTest OtherOptionTest2 (a: some 5 .Meter , b: none Meter , c: some 10 .Meter ), """ {"a":5,"c":10} """
805+ Json .roundtripChecks SeqOptionTest (a: @ [some 5 .Meter , none Meter ], b: Meter (5 )), """ {"a":[5,null],"b":5} """
806+ Json .roundtripChecks OtherOptionTest2 (a: some 5 .Meter , b: none Meter , c: some 10 .Meter ), """ {"a":5,"c":10} """
804807
805808 test " Result Opt types" :
806809 check:
@@ -812,8 +815,8 @@ suite "toJson tests":
812815 h1 = HoldsResultOpt (o: Opt [Simple ].ok Simple (x: 1 , y: " 2" , distance: Meter (3 )))
813816 h2 = HoldsResultOpt (r: newSimple (1 , " 2" , Meter (3 )))
814817
815- Json .roundtripTest h1, """ {"o":{"distance":3,"x":1,"y":"2"},"r":null} """
816- Json .roundtripTest h2, """ {"r":{"distance":3,"x":1,"y":"2"}} """
818+ Json .roundtripChecks h1, """ {"o":{"distance":3,"x":1,"y":"2"},"r":null} """
819+ Json .roundtripChecks h2, """ {"r":{"distance":3,"x":1,"y":"2"}} """
817820
818821 let
819822 h3 = Json .decode (""" {"r":{"distance":3,"x":1,"y":"2"}} """ ,
@@ -828,7 +831,7 @@ suite "toJson tests":
828831
829832 test " Custom field serialization" :
830833 let obj = WithCustomFieldRule (str: " test" , intVal: 10 )
831- Json .roundtripTest obj, """ {"str":"test","intVal":"10"} """
834+ Json .roundtripChecks obj, """ {"str":"test","intVal":"10"} """
832835
833836 test " Case object as field" :
834837 let
@@ -911,7 +914,10 @@ suite "toJson tests":
911914
912915 except SerializationError as e:
913916 echo e.getStackTrace
914- echo e.formatMsg (" <>" )
917+ when nimvm :
918+ echo e.msg
919+ else :
920+ echo e.formatMsg (" <>" )
915921 raise e
916922
917923 test " Holders of JsonString" :
@@ -927,7 +933,10 @@ suite "toJson tests":
927933 let decoded = Json .decode (jsonContent, JsonNode )
928934 check decoded[" tasks" ][0 ][" label" ] == newJString (" nimbus-eth2 build" )
929935 except SerializationError as err:
930- checkpoint err.formatMsg (" ./cases/comments.json" )
936+ when nimvm :
937+ checkpoint " <./cases/comments.json> " & err.msg
938+ else :
939+ checkpoint err.formatMsg (" ./cases/comments.json" )
931940 check false
932941
933942 test " A nil cstring" :
0 commit comments