* Reorder json `add` and `%`, fixes https://github.com/nim-lang/Nim/issues/6385 * rename json test files
This commit is contained in:
parent
12af4a3f8a
commit
5b8f33a905
3 changed files with 25 additions and 10 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
10
tests/stdlib/mjsonexternproc.nim
Normal file
10
tests/stdlib/mjsonexternproc.nim
Normal 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
|
||||||
5
tests/stdlib/tjsonexternproc.nim
Normal file
5
tests/stdlib/tjsonexternproc.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Test case for https://github.com/nim-lang/Nim/issues/6385
|
||||||
|
|
||||||
|
import mjsonexternproc
|
||||||
|
# import json
|
||||||
|
foo(1)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue