2022-06-24 16:08:27 +08:00
|
|
|
|
#include "test_common.h"
|
2022-10-28 18:39:50 +08:00
|
|
|
|
TEST_START
|
2022-06-24 16:08:27 +08:00
|
|
|
|
|
2022-07-11 03:14:14 +00:00
|
|
|
|
#if PIKA_SYNTAX_SLICE_ENABLE
|
2022-06-24 16:08:27 +08:00
|
|
|
|
TEST(builtin, bytes) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/bytes.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
uint8_t *res = obj_getBytes(pikaMain, "res");
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_EQ(res[1], 1);
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-06-24 16:08:27 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-06-30 16:10:08 +08:00
|
|
|
|
|
2022-07-14 08:36:02 +00:00
|
|
|
|
#if PIKA_BUILTIN_STRUCT_ENABLE
|
2022-06-30 16:10:08 +08:00
|
|
|
|
TEST(builtin, type1) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/type.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
|
EXPECT_STREQ(log_buff[0], "OK\r\n");
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-06-30 16:10:08 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-07-18 05:29:43 +00:00
|
|
|
|
|
|
|
|
|
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
|
|
|
|
|
TEST(builtin, seek) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/seek.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
int len = obj_getInt(pikaMain, "len");
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_EQ(len, 3576);
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-07-18 05:29:43 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-07-18 13:53:39 +08:00
|
|
|
|
|
2022-10-02 00:00:53 +08:00
|
|
|
|
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL)
|
2022-07-18 13:53:39 +08:00
|
|
|
|
TEST(builtin, file2) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/file2.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
char *s = obj_getStr(pikaMain, "s");
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_STREQ(s, "import PikaStdLib\n");
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-07-18 13:53:39 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
|
|
|
|
|
TEST(builtin, file3) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/file3.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-07-18 13:53:39 +08:00
|
|
|
|
}
|
2022-07-26 10:41:29 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2022-10-02 00:00:53 +08:00
|
|
|
|
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE
|
2022-07-26 10:41:29 +08:00
|
|
|
|
TEST(builtin, bigfile) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/bigfile.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
// uint8_t* b = obj_getBytes(pikaMain, "b");
|
|
|
|
|
/* assert */
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-07-26 10:41:29 +08:00
|
|
|
|
}
|
2022-08-06 17:59:32 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
TEST(builtin, nofound) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/file_nofound.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-08-06 17:59:32 +08:00
|
|
|
|
}
|
2022-08-18 11:38:05 +08:00
|
|
|
|
|
|
|
|
|
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
|
|
|
|
|
TEST(builtin, callback_1) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "test/python/callback/test1.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_STREQ(log_buff[0], "b\r\n");
|
|
|
|
|
EXPECT_STREQ(log_buff[1], "a\r\n");
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-08-18 11:38:05 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-09-05 22:30:28 +08:00
|
|
|
|
|
2022-09-06 08:19:05 +08:00
|
|
|
|
#if !PIKA_NANO_ENABLE
|
2022-09-05 22:30:28 +08:00
|
|
|
|
TEST(builtin, utf8) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/utf8.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_STREQ(log_buff[2], "你好,Hello, Bonjour.\r\n");
|
|
|
|
|
EXPECT_STREQ(log_buff[1], "你好,Hello, Bonjour.\r\n");
|
|
|
|
|
EXPECT_STREQ(log_buff[0], "Hi, Hello, Bonjour.\r\n");
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-09-05 22:30:28 +08:00
|
|
|
|
}
|
2023-03-11 22:30:19 +08:00
|
|
|
|
|
|
|
|
|
TEST(builtin, str_join) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "test/python/builtin/str_join.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
|
EXPECT_STREQ(log_buff[0], "PASS\r\n");
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2023-03-11 22:30:19 +08:00
|
|
|
|
}
|
2023-03-17 14:28:10 +08:00
|
|
|
|
|
|
|
|
|
TEST(builtin, int_extern) {
|
2023-05-14 23:54:57 +08:00
|
|
|
|
/* init */
|
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
|
|
|
|
PikaObj *pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
|
/* run */
|
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
|
pikaVM_runSingleFile(pikaMain, "test/python/builtin/int_extern.py");
|
|
|
|
|
/* collect */
|
|
|
|
|
/* assert */
|
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
|
EXPECT_STREQ(log_buff[0], "PASS\r\n");
|
|
|
|
|
/* deinit */
|
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2023-03-17 14:28:10 +08:00
|
|
|
|
}
|
2023-03-26 21:30:18 +08:00
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_PASS(builtin, list_tuple_equ,
|
2023-04-28 11:19:44 +08:00
|
|
|
|
"test/python/builtin/list_tuple_equ.py")
|
2023-03-26 21:30:18 +08:00
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_PASS(builtin, fn_default1,
|
2023-04-28 11:19:44 +08:00
|
|
|
|
"test/python/builtin/fn_default1.py")
|
2022-10-28 18:39:50 +08:00
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_PASS(builtin, fn_default_tuple,
|
2023-04-29 18:38:02 +08:00
|
|
|
|
"test/python/builtin/fn_default_tuple.py")
|
2023-04-29 12:21:29 +08:00
|
|
|
|
|
2023-05-01 21:48:33 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_PASS(builtin, max_min, "test/python/builtin/max_min.py")
|
|
|
|
|
|
2023-05-05 21:43:49 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_PASS(builtin, split, "test/python/builtin/split.py")
|
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin, split_slice, "'test'.split('e')[0]",
|
2023-05-05 21:43:49 +08:00
|
|
|
|
"'t'\r\n")
|
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin, split_slice_1, "'test'.split('e')[1]",
|
2023-05-05 21:43:49 +08:00
|
|
|
|
"'st'\r\n")
|
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin, replace_split_0,
|
2023-05-05 21:43:49 +08:00
|
|
|
|
"'a b c d'.replace(' ', ',').split(',')[0]",
|
|
|
|
|
"'a'\r\n")
|
|
|
|
|
|
2023-05-14 23:54:57 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(builtin, class_script,
|
|
|
|
|
"test/python/builtin/class_script.py",
|
|
|
|
|
"Obj1.test\r\n")
|
|
|
|
|
|
2023-05-15 00:05:56 +08:00
|
|
|
|
TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(builtin, class_hint,
|
|
|
|
|
"test/python/builtin/class_hint.py", "1\r\n")
|
|
|
|
|
|
2023-04-28 11:19:44 +08:00
|
|
|
|
#endif
|
2023-03-11 22:30:19 +08:00
|
|
|
|
|
2022-10-28 18:39:50 +08:00
|
|
|
|
TEST_END
|