1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Add new types to JSON render.

Add bool, array, and int64 as valid array subtypes.

Pretty print for the array subtype is not correct but is currently not in use (this can be seen at line 328 in typeJsonTest.c).
This commit is contained in:
David Steele 2019-07-24 06:52:49 -04:00
parent 62f0c7fb37
commit 615735e7ee
2 changed files with 22 additions and 2 deletions

View File

@ -970,12 +970,24 @@ jsonFromVar(const Variant *var, unsigned int indent)
{
strCat(jsonStr, "null");
}
else if (varType(varSub) == varTypeBool)
{
strCat(jsonStr, strPtr(jsonFromBool(varBool(varSub))));
}
else if (varType(varSub) == varTypeKeyValue)
{
// Update the depth before processing the contents of the list element
strCat(indentDepth, strPtr(indentSpace));
strCat(jsonStr, strPtr(jsonFromKvInternal(varKv(varSub), indentSpace, indentDepth)));
}
else if (varType(varSub) == varTypeVariantList)
{
strCat(jsonStr, strPtr(jsonFromVar(varSub, indent)));
}
else if (varType(varSub) == varTypeInt64)
{
strCat(jsonStr, strPtr(jsonFromInt64(varInt64(varSub))));
}
else if (varType(varSub) == varTypeUInt)
{
strCat(jsonStr, strPtr(jsonFromUInt(varUInt(varSub))));

View File

@ -288,12 +288,16 @@ testRun(void)
TEST_ASSIGN(varListOuter, varNewVarLst(varLstNew()), "new variant list with keyValues");
varLstAdd(varVarLst(varListOuter), varNewStrZ("ASTRING"));
varLstAdd(varVarLst(varListOuter), varNewInt64(9223372036854775807LL));
varLstAdd(varVarLst(varListOuter), varNewBool(true));
varLstAdd(varVarLst(varListOuter), varNewVarLst(varLstNew()));
varLstAdd(varVarLst(varListOuter), NULL);
varLstAdd(varVarLst(varListOuter), keyValue);
TEST_ASSIGN(json, jsonFromVar(varListOuter, 0), "VariantList - no indent");
TEST_RESULT_STR(strPtr(json),
"[\"ASTRING\",null,{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\","
"[\"ASTRING\",9223372036854775807,true,[],null,{\"backup-info-size-delta\":1982702,"
"\"backup-prior\":\"20161219-212741F_20161219-212803I\","
"\"backup-reference\":[\"20161219-212741F\",\"20161219-212741F_20161219-212803I\",null],"
"\"backup-timestamp-start\":1482182951,\"checksum-page-error\":[1],"
"\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}}]",
@ -304,7 +308,8 @@ testRun(void)
TEST_ASSIGN(json, jsonFromVar(varListOuter, 0), "VariantList - no indent - multiple elements");
TEST_RESULT_STR(strPtr(json),
"[\"ASTRING\",null,{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\","
"[\"ASTRING\",9223372036854775807,true,[],null,{\"backup-info-size-delta\":1982702,"
"\"backup-prior\":\"20161219-212741F_20161219-212803I\","
"\"backup-reference\":[\"20161219-212741F\",\"20161219-212741F_20161219-212803I\",null],"
"\"backup-timestamp-start\":1482182951,\"checksum-page-error\":[1],"
"\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}},"
@ -318,6 +323,9 @@ testRun(void)
TEST_RESULT_STR(strPtr(json),
"[\n"
" \"ASTRING\",\n"
" 9223372036854775807,\n"
" true,\n"
" []\n,\n"
" null,\n"
" {\n"
" \"backup-info-size-delta\" : 1982702,\n"