StringStream and parseJson, parseCfg, parseSql et al for the vm (#10746)

This commit is contained in:
Arne Döring
2019-02-28 22:57:57 +01:00
committed by Andreas Rumpf
parent 728ff1004a
commit 1102b8ac6e
15 changed files with 354 additions and 403 deletions

View File

@@ -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"