debug if_assert

This commit is contained in:
lyon 2021-09-05 09:00:10 +08:00
parent ec174be13d
commit 67eed0ac52
6 changed files with 40 additions and 10 deletions

View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/../build/src/test/pikascript_test",
"args": [
// "--gtest_filter=object_test.test2"
"--gtest_filter=block.assert1"
// "--gtest_filter=block.init"
// "--gtest_filter=sysObj.print"
// "--gtest_filter=object_test.a_b"
],

View File

@ -12,9 +12,9 @@ void block_deinit(PikaObj *self)
obj_deinit(self);
}
PikaObj *block_init()
PikaObj *block_init(Args *args)
{
PikaObj *self = New_TinyObj(NULL);
PikaObj *self = New_TinyObj(args);
obj_setStr(self, "mode", "");
obj_setStr(self, "assert", "");
obj_setStr(self, "body", "");

View File

@ -3,7 +3,7 @@
#include "PikaObj.h"
void block_deinit(PikaObj *self);
PikaObj *block_init();
PikaObj *block_init(Args *args);
char *block_popLine(PikaObj *self);
void block_pushLine(PikaObj *self, char *line);
char *block_getAssert(PikaObj *self);

View File

@ -8,6 +8,7 @@ void if_setAssert(PikaObj *self, char *line)
{
Args *buffs = New_strBuff();
char *assert = strsRemovePrefix(buffs, line, "if ");
assert = strsGetFirstToken(buffs, assert, ':');
block_setAssert(self, assert);
block_setMode(self, "if");
args_deinit(buffs);

View File

@ -602,7 +602,7 @@ Args *obj_runDirect(PikaObj *self, char *cmd)
if (strIsStartWith(cmd, "if "))
{
obj_setInt(self, "_isInBlock", 1);
obj_setObjWithoutClass(self, "_block", block_init());
obj_setObjWithoutClass(self, "_block", block_init);
PikaObj *block = obj_getObj(self, "_block", 0);
if_setAssert(block, cmd);
/* this line processed ok */

View File

@ -4,18 +4,20 @@ extern "C"
#include "PikaBlock.h"
#include "dataStrs.h"
#include "PikaIf.h"
#include "TinyObj.h"
#include "PikaObj.h"
}
TEST(block, init)
{
PikaObj *block = block_init();
PikaObj *block = block_init(NULL);
block_deinit(block);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(block, push)
{
PikaObj *block = block_init();
PikaObj *block = block_init(NULL);
block_pushLine(block, (char *)"line1");
block_pushLine(block, (char *)"line2");
block_deinit(block);
@ -24,7 +26,7 @@ TEST(block, push)
TEST(block, pop)
{
PikaObj *block = block_init();
PikaObj *block = block_init(NULL);
block_pushLine(block, (char *)"line1");
block_pushLine(block, (char *)"line2");
char *line1 = block_popLine(block);
@ -39,7 +41,7 @@ TEST(block, pop)
TEST(block, assert1)
{
PikaObj *block = block_init();
PikaObj *block = block_init(NULL);
{
block_setAssert(block, (char *)"1");
int res = block_checkAssert(block);
@ -56,10 +58,12 @@ TEST(block, assert1)
TEST(block, if1)
{
PikaObj *block = block_init();
PikaObj *block = block_init(NULL);
if_setAssert(block, (char *)"if 1 :");
if_pushLine(block, (char *)" print('hello')");
if_pushLine(block, (char *)" print('hello2')");
char *assert = block_getAssert(block);
ASSERT_STREQ((char *)"1 ", assert);
int res = block_checkAssert(block);
char *line1 = block_popLine(block);
ASSERT_STREQ((char *)"print('hello')", line1);
@ -69,4 +73,29 @@ TEST(block, if1)
block_deinit(block);
}
TEST(block, if2)
{
PikaObj *obj = New_TinyObj(NULL);
obj_run(obj, (char *)"if 1 :");
obj_deinit(obj);
}
TEST(block, if3)
{
PikaObj *obj = New_TinyObj(NULL);
obj_run(obj, (char *)"if 1 :");
obj_run(obj, (char *)" print('hello')");
obj_run(obj, (char *)" print('hello2')");
PikaObj *block = obj_getObj(obj, (char *)"_block", 0);
char *mode = block_getMode(block);
ASSERT_STREQ((char *)"if", mode);
char *assert = block_getAssert(block);
ASSERT_STREQ((char *)"1 ", assert);
char *line1 = block_popLine(block);
ASSERT_STREQ((char *)"print('hello')", line1);
char *line2 = block_popLine(block);
ASSERT_STREQ((char *)"print('hello2')", line2);
obj_deinit(obj);
}
void block_pushLine(PikaObj *self, char *line);