summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tests/hs_create_table_tests.c239
1 files changed, 239 insertions, 0 deletions
diff --git a/src/tests/hs_create_table_tests.c b/src/tests/hs_create_table_tests.c
index 029e1f1..0d6465d 100644
--- a/src/tests/hs_create_table_tests.c
+++ b/src/tests/hs_create_table_tests.c
@@ -1679,6 +1679,225 @@ TEST(create_table_user_light)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
+ * light userdata keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_light_bool)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ int index = hs_create_table
+ (L, hs_light_bool(light1, true), hs_light_bool(light2, true));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_light(index, light1);
+ checkval_bool(true);
+ loadkey_light(index, light2);
+ checkval_bool(true);
+ return 0;
+}
+
+TEST(create_table_light_int)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ int index = hs_create_table
+ (L, hs_light_int(light1, 15), hs_light_int(light2, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_light(index, light1);
+ checkval_int(15);
+ loadkey_light(index, light2);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_light_num)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ int index = hs_create_table
+ (L, hs_light_num(light1, 2.718), hs_light_num(light2, 1.618));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_light(index, light1);
+ checkval_num(2.718);
+ loadkey_light(index, light2);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_light_str)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ int index = hs_create_table
+ (L, hs_light_str(light1, "hello"), hs_light_str(light2, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_light(index, light1);
+ checkval_str("hello");
+ loadkey_light(index, light2);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_light_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_light_tbl(light1, value1), hs_light_tbl(light2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(value1);
+ load(value2);
+
+ loadkey_light(index, light1);
+ checkval_tbl(value1);
+ loadkey_light(index, light2);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_light_func)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ luaL_loadstring(L, "print('hello')");
+ store(value1);
+ luaL_loadstring(L, "print('hello')");
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_light_func(light1, value1), hs_light_func(light2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(value1);
+ load(value2);
+
+ loadkey_light(index, light1);
+ checkval_func(value1);
+ loadkey_light(index, light2);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_light_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ int index = hs_create_table
+ (L, hs_light_cfunc(light1, testfunc1), hs_light_cfunc(light2, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_light(index, light1);
+ checkval_cfunc(testfunc1);
+ loadkey_light(index, light2);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_light_user)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ lua_newuserdata(L, sizeof(char));
+ store(user1);
+ lua_newuserdata(L, sizeof(char));
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_light_user(light1, user1), hs_light_user(light2, user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(user1);
+ load(user2);
+
+ loadkey_light(index, light1);
+ checkval_user(user1);
+ loadkey_light(index, light2);
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_light_light)
+{
+ int oldtop = lua_gettop(L);
+
+ int l1 = 5;
+ int l2 = 6;
+ void *light1 = (void *) &l1;
+ void *light2 = (void *) &l2;
+
+ int a1 = 5;
+ void *value1 = (void *) &a1;
+ int a2 = 6;
+ void *value2 = (void *) &a2;
+
+ int index = hs_create_table
+ (L, hs_light_light(light1, value1), hs_light_light(light2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_light(index, light1);
+ checkval_light(value1);
+ loadkey_light(index, light2);
+ checkval_light(value2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
* test suite
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1849,4 +2068,24 @@ void hs_create_table_tests()
create_table_user_user);
mu_run_test("create table with userdata keys and light userdata values", \
create_table_user_light);
+
+ /* light userdata keys */
+ mu_run_test("create table with light userdata keys and boolean values",
+ create_table_light_bool);
+ mu_run_test("create table with light userdata keys and integer values", \
+ create_table_light_int);
+ mu_run_test("create table with light userdata keys and number values", \
+ create_table_light_num);
+ mu_run_test("create table with light userdata keys and string values", \
+ create_table_light_str);
+ mu_run_test("create table with light userdata keys and table values", \
+ create_table_light_tbl);
+ mu_run_test("create table with light userdata keys and function values", \
+ create_table_light_func);
+ mu_run_test("create table with light userdata keys and C function values", \
+ create_table_light_cfunc);
+ mu_run_test("create table with light userdata keys and userdata values", \
+ create_table_light_user);
+ mu_run_test("create table with light userdata keys and light userdata values", \
+ create_table_light_light);
}