parent
2deb7011f5
commit
d398c558a4
2 changed files with 22 additions and 0 deletions
|
|
@ -11,6 +11,8 @@ import std/[json,parsejson,strutils]
|
||||||
from std/math import isNaN
|
from std/math import isNaN
|
||||||
when not defined(js):
|
when not defined(js):
|
||||||
import std/streams
|
import std/streams
|
||||||
|
import stdtest/testutils
|
||||||
|
from std/fenv import epsilon
|
||||||
|
|
||||||
proc testRoundtrip[T](t: T, expected: string) =
|
proc testRoundtrip[T](t: T, expected: string) =
|
||||||
# checks that `T => json => T2 => json2` is such that json2 = json
|
# checks that `T => json => T2 => json2` is such that json2 = json
|
||||||
|
|
@ -325,6 +327,15 @@ block: # bug #18007
|
||||||
let a = parseJson($(%NaN)).to(float)
|
let a = parseJson($(%NaN)).to(float)
|
||||||
doAssert a.isNaN
|
doAssert a.isNaN
|
||||||
|
|
||||||
|
whenRuntimeJs: discard # refs bug #18009
|
||||||
|
do:
|
||||||
|
testRoundtripVal(0.0): "0.0"
|
||||||
|
testRoundtripVal(-0.0): "-0.0"
|
||||||
|
|
||||||
|
block: # bug #15397, bug #13196
|
||||||
|
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
|
||||||
|
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let a = "18446744073709551615"
|
let a = "18446744073709551615"
|
||||||
let b = a.parseJson
|
let b = a.parseJson
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ discard """
|
||||||
import std/jsonutils
|
import std/jsonutils
|
||||||
import std/json
|
import std/json
|
||||||
from std/math import isNaN, signbit
|
from std/math import isNaN, signbit
|
||||||
|
from std/fenv import epsilon
|
||||||
from stdtest/testutils import whenRuntimeJs
|
from stdtest/testutils import whenRuntimeJs
|
||||||
|
|
||||||
proc testRoundtrip[T](t: T, expected: string) =
|
proc testRoundtrip[T](t: T, expected: string) =
|
||||||
|
|
@ -160,6 +161,16 @@ template fn() =
|
||||||
doAssert b[2].signbit
|
doAssert b[2].signbit
|
||||||
doAssert not b[3].signbit
|
doAssert not b[3].signbit
|
||||||
|
|
||||||
|
block: # bug #15397, bug #13196
|
||||||
|
let a = 0.1
|
||||||
|
let x = 0.12345678901234567890123456789
|
||||||
|
let b = (a + 0.2, 0.3, x)
|
||||||
|
testRoundtripVal(b): "[0.30000000000000004,0.3,0.12345678901234568]"
|
||||||
|
|
||||||
|
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
|
||||||
|
testRoundtripVal(epsilon(float64)): "2.220446049250313e-16"
|
||||||
|
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
|
||||||
|
|
||||||
block: # case object
|
block: # case object
|
||||||
type Foo = object
|
type Foo = object
|
||||||
x0: float
|
x0: float
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue