From 3f0f1680dcdf6ca025084cd8b42381c2e0e10575 Mon Sep 17 00:00:00 2001 From: Lyon Date: Wed, 6 Sep 2023 22:58:28 +0800 Subject: [PATCH] add test_tuple_nested test. --- port/linux/package/pikascript/_testcase.pyi | 2 ++ port/linux/package/pikascript/main.py | 2 +- .../pikascript-lib/testcase/_testcase.c | 27 +++++++++++++++++++ port/linux/package/pikascript/testcase.py | 5 ++++ src/PikaVersion.h | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 port/linux/package/pikascript/_testcase.pyi create mode 100644 port/linux/package/pikascript/pikascript-lib/testcase/_testcase.c create mode 100644 port/linux/package/pikascript/testcase.py diff --git a/port/linux/package/pikascript/_testcase.pyi b/port/linux/package/pikascript/_testcase.pyi new file mode 100644 index 000000000..d7dff41ba --- /dev/null +++ b/port/linux/package/pikascript/_testcase.pyi @@ -0,0 +1,2 @@ + +def test_tuple_nested(tuple_nasted: tuple): ... diff --git a/port/linux/package/pikascript/main.py b/port/linux/package/pikascript/main.py index 1175db500..48ee1d32b 100644 --- a/port/linux/package/pikascript/main.py +++ b/port/linux/package/pikascript/main.py @@ -4,7 +4,7 @@ import pika_lua, pika_cjson, cjson_test, json import GTestTask, TempDevTest import cb_test import configparser, network, math, struct -import test_module1, test_cmodule, test_module4, import_test +import test_module1, test_cmodule, test_module4, import_test, testcase import hashlib, hmac, aes, base64, time, os, zlib import _thread, weakref, eventloop import this diff --git a/port/linux/package/pikascript/pikascript-lib/testcase/_testcase.c b/port/linux/package/pikascript/pikascript-lib/testcase/_testcase.c new file mode 100644 index 000000000..335d7249d --- /dev/null +++ b/port/linux/package/pikascript/pikascript-lib/testcase/_testcase.c @@ -0,0 +1,27 @@ +#include "_testcase.h" + +void _testcase_test_tuple_nested(PikaObj* self, PikaObj* tuple_nasted) { + size_t len = pikaTuple_getSize(tuple_nasted); + for (size_t i = 0; i < len; i++) { + Arg* item = pikaTuple_get(tuple_nasted, i); + if (arg_isTuple(item)) { + PikaObj* tuple_inner = arg_getObj(item); + size_t len_inner = pikaTuple_getSize(tuple_inner); + for (size_t j = 0; j < len_inner; j++) { + Arg* item_inner = pikaTuple_get(tuple_inner, j); + if (ARG_TYPE_INT == arg_getType(item_inner)) { + int64_t value = arg_getInt(item_inner); + pika_platform_printf("[%d, %d] %ld\n", i, j, value); + } + if (ARG_TYPE_FLOAT == arg_getType(item_inner)) { + double value = arg_getFloat(item_inner); + pika_platform_printf("[%d, %d] %f\n", i, j, value); + } + if (ARG_TYPE_STRING == arg_getType(item_inner)) { + char* value = arg_getStr(item_inner); + pika_platform_printf("[%d, %d] %s\n", i, j, value); + } + } + } + } +} diff --git a/port/linux/package/pikascript/testcase.py b/port/linux/package/pikascript/testcase.py new file mode 100644 index 000000000..8ea603828 --- /dev/null +++ b/port/linux/package/pikascript/testcase.py @@ -0,0 +1,5 @@ +import _testcase + +def test_tuple_nested(): + student_records = ((12345, "Alice"), (67890, "Bob")) + _testcase.test_tuple_nested(student_records) diff --git a/src/PikaVersion.h b/src/PikaVersion.h index 534161c20..963e3bc62 100644 --- a/src/PikaVersion.h +++ b/src/PikaVersion.h @@ -2,4 +2,4 @@ #define PIKA_VERSION_MINOR 12 #define PIKA_VERSION_MICRO 5 -#define PIKA_EDIT_TIME "2023/08/29 13:56:27" +#define PIKA_EDIT_TIME "2023/09/06 22:57:32"