pikapython/port/linux/test/VM-test.cpp
2021-10-14 21:02:19 +08:00

82 lines
2.1 KiB
C

#include "gtest/gtest.h"
extern "C" {
#include "BaseObj.h"
#include "PikaParser.h"
#include "PikaStdLib_SysObj.h"
#include "PikaVM.h"
#include "dataMemory.h"
#include "dataQueue.h"
#include "dataStrs.h"
}
TEST(VM, num1) {
char* line = (char*)"1";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, a_1) {
char* line = (char*)"a = 1";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
ASSERT_EQ(obj_getInt(self, (char*)"a"), 1);
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, a_1d1) {
char* line = (char*)"a = 1.1";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
ASSERT_FLOAT_EQ(obj_getFloat(self, (char*)"a"), 1.1);
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, str_xy) {
char* line = (char*)"a = 'xy'";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
ASSERT_STREQ(obj_getStr(self, (char*)"a"), (char*)"xy");
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, str_xy_space) {
char* line = (char*)"a = 'xy '";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
ASSERT_STREQ(obj_getStr(self, (char*)"a"), (char*)"xy ");
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}