Reorder json add and %, fixes #6385 (#6388)

* Reorder json `add` and `%`, fixes https://github.com/nim-lang/Nim/issues/6385

* rename json test files
This commit is contained in:
Mamy Ratsimbazafy 2017-09-16 20:09:44 +02:00 • committed by Dominik Picheta
commit 5b8f33a905
3 changed files with 25 additions and 10 deletions

View file

@ -721,6 +721,16 @@ proc getElems*(n: JsonNode, default: seq[JsonNode] = @[]): seq[JsonNode] =
if n.isNil or n.kind != JArray: return default if n.isNil or n.kind != JArray: return default
else: return n.elems else: return n.elems
proc add*(father, child: JsonNode) =
## Adds `child` to a JArray node `father`.
assert father.kind == JArray
father.elems.add(child)
proc add*(obj: JsonNode, key: string, val: JsonNode) =
## Sets a field from a `JObject`.
assert obj.kind == JObject
obj.fields[key] = val
proc `%`*(s: string): JsonNode = proc `%`*(s: string): JsonNode =
## Generic constructor for JSON data. Creates a new `JString JsonNode`. ## Generic constructor for JSON data. Creates a new `JString JsonNode`.
new(result) new(result)
@ -909,16 +919,6 @@ proc contains*(node: JsonNode, val: JsonNode): bool =
proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key) proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key)
## Deprecated for `hasKey` ## Deprecated for `hasKey`
proc add*(father, child: JsonNode) =
## Adds `child` to a JArray node `father`.
assert father.kind == JArray
father.elems.add(child)
proc add*(obj: JsonNode, key: string, val: JsonNode) =
## Sets a field from a `JObject`.
assert obj.kind == JObject
obj.fields[key] = val
proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} = proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
## Sets a field from a `JObject`. ## Sets a field from a `JObject`.
assert(obj.kind == JObject) assert(obj.kind == JObject)

View file

@ -0,0 +1,10 @@
# Test case for https://github.com/nim-lang/Nim/issues/6385
import json
# export json
proc foo*[T](a: T) =
let params = %*{
"data": [ 1 ]
}
echo $params

View file

@ -0,0 +1,5 @@
# Test case for https://github.com/nim-lang/Nim/issues/6385
import mjsonexternproc
# import json
foo(1)