mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
parse(), print() for cJSON is ok
This commit is contained in:
parent
b016924634
commit
604711f708
@ -4,6 +4,6 @@ import json
|
||||
|
||||
|
||||
class cJSON(TinyObj):
|
||||
def __init__(self): ...
|
||||
def print(self) -> str: ...
|
||||
def parse(self, val: str) -> any: ...
|
||||
def parse(self, value: str): ...
|
||||
def __del__(self): ...
|
||||
|
@ -1,9 +1,22 @@
|
||||
#include "cJSON_cJSON.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
void cJSON_cJSON___init__(PikaObj* self) {}
|
||||
Arg* cJSON_cJSON_parse(PikaObj* self, char* val) {
|
||||
return NULL;
|
||||
void cJSON_cJSON_parse(PikaObj* self, char* value) {
|
||||
cJSON* item = cJSON_Parse(value);
|
||||
obj_setPtr(self, "item", item);
|
||||
}
|
||||
|
||||
char* cJSON_cJSON_print(PikaObj* self) {
|
||||
return NULL;
|
||||
cJSON* item = obj_getPtr(self, "item");
|
||||
char* res = cJSON_Print(item);
|
||||
obj_setStr(self, "_buf", res);
|
||||
cJSON_free(res);
|
||||
return obj_getStr(self, "_buf");
|
||||
}
|
||||
|
||||
void cJSON_cJSON___del__(PikaObj* self) {
|
||||
cJSON* item = obj_getPtr(self, "item");
|
||||
if (NULL != item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
}
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
"--gtest_filter=pikaMain.module_import_from_module"
|
||||
// "--gtest_filter=pikaMain.module_import_from_module"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -4,6 +4,6 @@ import json
|
||||
|
||||
|
||||
class cJSON(TinyObj):
|
||||
def __init__(self): ...
|
||||
def print(self) -> str: ...
|
||||
def parse(self, value: str) -> any: ...
|
||||
def parse(self, value: str): ...
|
||||
def __del__(self): ...
|
||||
|
@ -1,10 +1,22 @@
|
||||
#include "cJSON_cJSON.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
void cJSON_cJSON___init__(PikaObj* self) {}
|
||||
Arg* cJSON_cJSON_parse(PikaObj* self, char* value) {
|
||||
cJSON* cJSON_struct = cJSON_Parse(value);
|
||||
void cJSON_cJSON_parse(PikaObj* self, char* value) {
|
||||
cJSON* item = cJSON_Parse(value);
|
||||
obj_setPtr(self, "item", item);
|
||||
}
|
||||
|
||||
char* cJSON_cJSON_print(PikaObj* self) {
|
||||
return NULL;
|
||||
cJSON* item = obj_getPtr(self, "item");
|
||||
char* res = cJSON_Print(item);
|
||||
obj_setStr(self, "_buf", res);
|
||||
cJSON_free(res);
|
||||
return obj_getStr(self, "_buf");
|
||||
}
|
||||
|
||||
void cJSON_cJSON___del__(PikaObj* self) {
|
||||
cJSON* item = obj_getPtr(self, "item");
|
||||
if (NULL != item) {
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
}
|
@ -12,4 +12,34 @@ extern "C" {
|
||||
#include "pika_config_gtest.h"
|
||||
}
|
||||
|
||||
extern PikaMemInfo pikaMemInfo;
|
||||
extern PikaMemInfo pikaMemInfo;
|
||||
|
||||
TEST(cJSON, parse_print) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
char testjson[] =
|
||||
"{\n"
|
||||
"\"name\": \"mculover666\",\n"
|
||||
"\"age\": 22,\n"
|
||||
"\"weight\": 55.5,\n"
|
||||
"\"address\":\n"
|
||||
"{\n"
|
||||
" \"country\": \"China\",\n"
|
||||
" \"zip-code\": 111111\n"
|
||||
"},\n"
|
||||
"\"skill\": [\"c\", \"Java\", \"Python\"],\n"
|
||||
"\"student\": false\n"
|
||||
"}\n";
|
||||
/* run */
|
||||
obj_setStr(pikaMain, "testjson", testjson);
|
||||
obj_run(pikaMain,
|
||||
"a = cJSON.cJSON()\n"
|
||||
"a.parse(testjson)\n"
|
||||
"a.print()\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user