fixes json.nim regression
This commit is contained in:
parent
dafd995402
commit
f8e720fda9
2 changed files with 5 additions and 16 deletions
|
|
@ -390,18 +390,10 @@ proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
|
||||||
assert(obj.kind == JObject)
|
assert(obj.kind == JObject)
|
||||||
obj.fields[key] = val
|
obj.fields[key] = val
|
||||||
|
|
||||||
proc `%`*[T: tuple|object](o: T): JsonNode =
|
proc `%`*[T: object](o: T): JsonNode =
|
||||||
## Construct JsonNode from tuples and objects.
|
## Construct JsonNode from tuples and objects.
|
||||||
##
|
|
||||||
## If passed an anonymous tuple, creates `JArray JsonNode`,
|
|
||||||
## otherwise (named tuples and objects) `JObject JsonNode`.
|
|
||||||
const isNamed = T is object or isNamedTuple(T)
|
|
||||||
when isNamed:
|
|
||||||
result = newJObject()
|
result = newJObject()
|
||||||
for k, v in o.fieldPairs: result[k] = %v
|
for k, v in o.fieldPairs: result[k] = %v
|
||||||
else:
|
|
||||||
result = newJArray()
|
|
||||||
for a in o.fields: result.add(%a)
|
|
||||||
|
|
||||||
proc `%`*(o: ref object): JsonNode =
|
proc `%`*(o: ref object): JsonNode =
|
||||||
## Generic constructor for JSON data. Creates a new `JObject JsonNode`
|
## Generic constructor for JSON data. Creates a new `JObject JsonNode`
|
||||||
|
|
@ -1718,7 +1710,6 @@ when isMainModule:
|
||||||
|
|
||||||
# Test loading of file.
|
# Test loading of file.
|
||||||
when not defined(js):
|
when not defined(js):
|
||||||
echo("99% of tests finished. Going to try loading file.")
|
|
||||||
var parsed = parseFile("tests/testdata/jsontest.json")
|
var parsed = parseFile("tests/testdata/jsontest.json")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -1752,6 +1743,8 @@ when isMainModule:
|
||||||
doAssert($ %*[] == "[]")
|
doAssert($ %*[] == "[]")
|
||||||
doAssert($ %*{} == "{}")
|
doAssert($ %*{} == "{}")
|
||||||
|
|
||||||
|
doAssert(not compiles(%{"error": "No messages"}))
|
||||||
|
|
||||||
# bug #9111
|
# bug #9111
|
||||||
block:
|
block:
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -517,10 +517,6 @@ when true:
|
||||||
doAssert v.name == "smith"
|
doAssert v.name == "smith"
|
||||||
doAssert MyRef(w).name == "smith"
|
doAssert MyRef(w).name == "smith"
|
||||||
|
|
||||||
block test_tuple:
|
|
||||||
doAssert $(%* (a1: 10, a2: "foo")) == """{"a1":10,"a2":"foo"}"""
|
|
||||||
doAssert $(%* (10, "foo")) == """[10,"foo"]"""
|
|
||||||
|
|
||||||
# TODO: when the issue with the limeted vm registers is solved, the
|
# TODO: when the issue with the limeted vm registers is solved, the
|
||||||
# exact same test as above should be evaluated at compile time as
|
# exact same test as above should be evaluated at compile time as
|
||||||
# well, to ensure that the vm functionality won't diverge from the
|
# well, to ensure that the vm functionality won't diverge from the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue