mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 15:31:28 +00:00
StringStream and parseJson, parseCfg, parseSql et al for the vm (#10746)
This commit is contained in:
committed by
Andreas Rumpf
parent
728ff1004a
commit
1102b8ac6e
@@ -520,3 +520,43 @@ when true:
|
||||
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
|
||||
# exact same test as above should be evaluated at compile time as
|
||||
# well, to ensure that the vm functionality won't diverge from the
|
||||
# runtime functionality. Until then, the following test should do it.
|
||||
|
||||
static:
|
||||
var t = parseJson("""
|
||||
{
|
||||
"name":"Bongo",
|
||||
"email":"bongo@bingo.com",
|
||||
"list": [11,7,15],
|
||||
"year": 1975,
|
||||
"dict": {"a": 1, "b": 2},
|
||||
"arr": [1.0, 2.0, 7.0],
|
||||
"person": {"name": "boney"},
|
||||
"dog": {"name": "honey"},
|
||||
"fruit": {"color": 10},
|
||||
"distfruit": {"color": 11},
|
||||
"emails": ["abc", "123"]
|
||||
}
|
||||
""")
|
||||
|
||||
doAssert t["name"].getStr == "Bongo"
|
||||
doAssert t["email"].getStr == "bongo@bingo.com"
|
||||
doAssert t["list"][0].getInt == 11
|
||||
doAssert t["list"][1].getInt == 7
|
||||
doAssert t["list"][2].getInt == 15
|
||||
doAssert t["year"].getInt == 1975
|
||||
doAssert t["dict"]["a"].getInt == 1
|
||||
doAssert t["dict"]["b"].getInt == 2
|
||||
doAssert t["arr"][0].getFloat == 1.0
|
||||
doAssert t["arr"][1].getFloat == 2.0
|
||||
doAssert t["arr"][2].getFloat == 7.0
|
||||
doAssert t["person"]["name"].getStr == "boney"
|
||||
doAssert t["distfruit"]["color"].getInt == 11
|
||||
doAssert t["dog"]["name"].getStr == "honey"
|
||||
doAssert t["fruit"]["color"].getInt == 10
|
||||
doAssert t["emails"][0].getStr == "abc"
|
||||
doAssert t["emails"][1].getStr == "123"
|
||||
|
||||
Reference in New Issue
Block a user