summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-08-29 00:01:34 -0500
committersanine <sanine.not@pm.me>2021-08-29 00:01:34 -0500
commit6626abcdbf06a85dfd675d08c5973f7b67df549f (patch)
treeacc95b20df3c8d0c28f5c70eee2dc6191638d28c
parent1ea8716ba8f8fad52c7103ce63696949fb28ae3e (diff)
add tests for number, string, table, and function keys
-rw-r--r--src/tests/hs_create_table_tests.c902
1 files changed, 877 insertions, 25 deletions
diff --git a/src/tests/hs_create_table_tests.c b/src/tests/hs_create_table_tests.c
index f529f57..f21ca64 100644
--- a/src/tests/hs_create_table_tests.c
+++ b/src/tests/hs_create_table_tests.c
@@ -103,7 +103,7 @@ TEST(create_table_bool_bool)
int index = hs_create_table
(L, hs_bool_bool(true, true), hs_bool_bool(false, true));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_bool(index, true);
checkval_bool(true);
loadkey_bool(index, false);
@@ -117,7 +117,7 @@ TEST(create_table_bool_int)
int index = hs_create_table
(L, hs_bool_int(true, 15), hs_bool_int(false, 25));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_bool(index, true);
checkval_int(15);
loadkey_bool(index, false);
@@ -131,7 +131,7 @@ TEST(create_table_bool_num)
int index = hs_create_table
(L, hs_bool_num(true, 2.718), hs_bool_num(false, 1.618));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_bool(index, true);
checkval_num(2.718);
loadkey_bool(index, false);
@@ -145,7 +145,7 @@ TEST(create_table_bool_str)
int index = hs_create_table
(L, hs_bool_str(true, "hello"), hs_bool_str(false, "world"));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_bool(index, true);
checkval_str("hello");
loadkey_bool(index, false);
@@ -168,7 +168,7 @@ TEST(create_table_bool_tbl)
load(value1);
load(value2);
-
+
loadkey_bool(index, true);
checkval_tbl(value1);
loadkey_bool(index, false);
@@ -184,14 +184,14 @@ TEST(create_table_bool_func)
store(value1);
luaL_loadstring(L, "print('hello')");
store(value2);
-
+
int index = hs_create_table
(L, hs_bool_func(true, value1), hs_bool_func(false, value2));
mu_assert_equal(oldtop + 1, lua_gettop(L));
load(value1);
load(value2);
-
+
loadkey_bool(index, true);
checkval_func(value1);
loadkey_bool(index, false);
@@ -206,7 +206,7 @@ TEST(create_table_bool_cfunc)
int index = hs_create_table
(L, hs_bool_cfunc(true, testfunc1), hs_bool_cfunc(false, testfunc2));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_bool(index, true);
checkval_cfunc(testfunc1);
loadkey_bool(index, false);
@@ -230,7 +230,7 @@ TEST(create_table_bool_user)
load(user1);
load(user2);
-
+
loadkey_bool(index, true);
checkval_user(user1);
loadkey_bool(index, false);
@@ -249,7 +249,7 @@ TEST(create_table_bool_light)
int index = hs_create_table
(L, hs_bool_light(true, light1), hs_bool_light(false, light2));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_bool(index, true);
checkval_light(light1);
loadkey_bool(index, false);
@@ -271,7 +271,7 @@ TEST(create_table_int_bool)
int index = hs_create_table
(L, hs_int_bool(15, true), hs_int_bool(25, true));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_int(index, 15);
checkval_bool(true);
loadkey_int(index, 25);
@@ -285,7 +285,7 @@ TEST(create_table_int_int)
int index = hs_create_table
(L, hs_int_int(15, 15), hs_int_int(25, 25));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_int(index, 15);
checkval_int(15);
loadkey_int(index, 25);
@@ -299,7 +299,7 @@ TEST(create_table_int_num)
int index = hs_create_table
(L, hs_int_num(15, 2.718), hs_int_num(25, 1.618));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_int(index, 15);
checkval_num(2.718);
loadkey_int(index, 25);
@@ -313,7 +313,7 @@ TEST(create_table_int_str)
int index = hs_create_table
(L, hs_int_str(15, "hello"), hs_int_str(25, "world"));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_int(index, 15);
checkval_str("hello");
loadkey_int(index, 25);
@@ -336,7 +336,7 @@ TEST(create_table_int_tbl)
load(value1);
load(value2);
-
+
loadkey_int(index, 15);
checkval_tbl(value1);
loadkey_int(index, 25);
@@ -352,14 +352,14 @@ TEST(create_table_int_func)
store(value1);
luaL_loadstring(L, "print('hello')");
store(value2);
-
+
int index = hs_create_table
(L, hs_int_func(15, value1), hs_int_func(25, value2));
mu_assert_equal(oldtop + 1, lua_gettop(L));
load(value1);
load(value2);
-
+
loadkey_int(index, 15);
checkval_func(value1);
loadkey_int(index, 25);
@@ -374,7 +374,7 @@ TEST(create_table_int_cfunc)
int index = hs_create_table
(L, hs_int_cfunc(15, testfunc1), hs_int_cfunc(25, testfunc2));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_int(index, 15);
checkval_cfunc(testfunc1);
loadkey_int(index, 25);
@@ -398,7 +398,7 @@ TEST(create_table_int_user)
load(user1);
load(user2);
-
+
loadkey_int(index, 15);
checkval_user(user1);
loadkey_int(index, 25);
@@ -417,7 +417,7 @@ TEST(create_table_int_light)
int index = hs_create_table
(L, hs_int_light(15, light1), hs_int_light(25, light2));
mu_assert_equal(oldtop + 1, lua_gettop(L));
-
+
loadkey_int(index, 15);
checkval_light(light1);
loadkey_int(index, 25);
@@ -428,6 +428,840 @@ TEST(create_table_int_light)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
+ * number keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_num_bool)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_num_bool(43.3f, true), hs_num_bool(23.56f, false));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_num(index, 43.3f);
+ checkval_bool(true);
+ loadkey_num(index, 23.56f);
+ checkval_bool(false);
+ return 0;
+}
+
+TEST(create_table_num_int)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_num_int(43.3f, 15), hs_num_int(23.56f, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_num(index, 43.3f);
+ checkval_int(15);
+ loadkey_num(index, 23.56f);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_num_num)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_num_num(43.3f, 2.718), hs_num_num(23.56f, 1.618));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_num(index, 43.3f);
+ checkval_num(2.718);
+ loadkey_num(index, 23.56f);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_num_str)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_num_str(43.3f, "hello"), hs_num_str(23.56f, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_num(index, 43.3f);
+ checkval_str("hello");
+ loadkey_num(index, 23.56f);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_num_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_num_tbl(43.3f, value1), hs_num_tbl(23.56f, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(value1);
+ load(value2);
+
+ loadkey_num(index, 43.3f);
+ checkval_tbl(value1);
+ loadkey_num(index, 23.56f);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_num_func)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('hello')");
+ store(value1);
+ luaL_loadstring(L, "print('hello')");
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_num_func(43.3f, value1), hs_num_func(23.56f, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(value1);
+ load(value2);
+
+ loadkey_num(index, 43.3f);
+ checkval_func(value1);
+ loadkey_num(index, 23.56f);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_num_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_num_cfunc(43.3f, testfunc1), hs_num_cfunc(23.56f, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_num(index, 43.3f);
+ checkval_cfunc(testfunc1);
+ loadkey_num(index, 23.56f);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_num_user)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newuserdata(L, sizeof(char));
+ store(user1);
+ lua_newuserdata(L, sizeof(char));
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_num_user(43.3f, user1), hs_num_user(23.56f, user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(user1);
+ load(user2);
+
+ loadkey_num(index, 43.3f);
+ checkval_user(user1);
+ loadkey_num(index, 23.56f);
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_num_light)
+{
+ int a1 = 5;
+ void *light1 = (void *) &a1;
+ int a2 = 6;
+ void *light2 = (void *) &a2;
+
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_num_light(43.3f, light1), hs_num_light(23.56f, light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_num(index, 43.3f);
+ checkval_light(light1);
+ loadkey_num(index, 23.56f);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * boolean keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_str_bool)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_str_bool("c:", true), hs_str_bool(":)", true));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_str(index, "c:");
+ checkval_bool(true);
+ loadkey_str(index, ":)");
+ checkval_bool(true);
+ return 0;
+}
+
+TEST(create_table_str_int)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_str_int("c:", 15), hs_str_int(":)", 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_str(index, "c:");
+ checkval_int(15);
+ loadkey_str(index, ":)");
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_str_num)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_str_num("c:", 2.718), hs_str_num(":)", 1.618));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_str(index, "c:");
+ checkval_num(2.718);
+ loadkey_str(index, ":)");
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_str_str)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_str_str("c:", "hello"), hs_str_str(":)", "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_str(index, "c:");
+ checkval_str("hello");
+ loadkey_str(index, ":)");
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_str_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_str_tbl("c:", value1), hs_str_tbl(":)", value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(value1);
+ load(value2);
+
+ loadkey_str(index, "c:");
+ checkval_tbl(value1);
+ loadkey_str(index, ":)");
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_str_func)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('hello')");
+ store(value1);
+ luaL_loadstring(L, "print('hello')");
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_str_func("c:", value1), hs_str_func(":)", value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(value1);
+ load(value2);
+
+ loadkey_str(index, "c:");
+ checkval_func(value1);
+ loadkey_str(index, ":)");
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_str_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_str_cfunc("c:", testfunc1), hs_str_cfunc(":)", testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_str(index, "c:");
+ checkval_cfunc(testfunc1);
+ loadkey_str(index, ":)");
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_str_user)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newuserdata(L, sizeof(char));
+ store(user1);
+ lua_newuserdata(L, sizeof(char));
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_str_user("c:", user1), hs_str_user(":)", user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(user1);
+ load(user2);
+
+ loadkey_str(index, "c:");
+ checkval_user(user1);
+ loadkey_str(index, ":)");
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_str_light)
+{
+ int a1 = 5;
+ void *light1 = (void *) &a1;
+ int a2 = 6;
+ void *light2 = (void *) &a2;
+
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_str_light("c:", light1), hs_str_light(":)", light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ loadkey_str(index, "c:");
+ checkval_light(light1);
+ loadkey_str(index, ":)");
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * table keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_tbl_bool)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+ int index = hs_create_table
+ (L, hs_tbl_bool(tbl1, true), hs_tbl_bool(tbl2, false));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_bool(true);
+ loadkey_tbl(index, tbl2);
+ checkval_bool(false);
+ return 0;
+}
+
+TEST(create_table_tbl_int)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+ int index = hs_create_table
+ (L, hs_tbl_int(tbl1, 15), hs_tbl_int(tbl2, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_int(15);
+ loadkey_tbl(index, tbl2);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_tbl_num)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+ int index = hs_create_table
+ (L, hs_tbl_num(tbl1, 2.718), hs_tbl_num(tbl2, 1.618));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_num(2.718);
+ loadkey_tbl(index, tbl2);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_tbl_str)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+ int index = hs_create_table
+ (L, hs_tbl_str(tbl1, "hello"), hs_tbl_str(tbl2, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_str("hello");
+ loadkey_tbl(index, tbl2);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_tbl_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_tbl_tbl(tbl1, value1), hs_tbl_tbl(tbl2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_tbl(value1);
+ loadkey_tbl(index, tbl2);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_tbl_func)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+
+ luaL_loadstring(L, "print('hello')");
+ store(value1);
+ luaL_loadstring(L, "print('hello')");
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_tbl_func(tbl1, value1), hs_tbl_func(tbl2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_func(value1);
+ loadkey_tbl(index, tbl2);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_tbl_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+ int index = hs_create_table
+ (L, hs_tbl_cfunc(tbl1, testfunc1), hs_tbl_cfunc(tbl2, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_cfunc(testfunc1);
+ loadkey_tbl(index, tbl2);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_tbl_user)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+
+ lua_newuserdata(L, sizeof(char));
+ store(user1);
+ lua_newuserdata(L, sizeof(char));
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_tbl_user(tbl1, user1), hs_tbl_user(tbl2, user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ load(user1);
+ load(user2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_user(user1);
+ loadkey_tbl(index, tbl2);
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_tbl_light)
+{
+ int a1 = 5;
+ void *light1 = (void *) &a1;
+ int a2 = 6;
+ void *light2 = (void *) &a2;
+
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(tbl1);
+ lua_newtable(L);
+ store(tbl2);
+
+ int index = hs_create_table
+ (L, hs_tbl_light(tbl1, light1), hs_tbl_light(tbl2, light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(tbl1);
+ load(tbl2);
+
+ loadkey_tbl(index, tbl1);
+ checkval_light(light1);
+ loadkey_tbl(index, tbl2);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * function keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_func_bool)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+ int index = hs_create_table
+ (L, hs_func_bool(func1, true), hs_func_bool(func2, false));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_bool(true);
+ loadkey_func(index, func2);
+ checkval_bool(false);
+ return 0;
+}
+
+TEST(create_table_func_int)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+ int index = hs_create_table
+ (L, hs_func_int(func1, 15), hs_func_int(func2, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_int(15);
+ loadkey_func(index, func2);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_func_num)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+ int index = hs_create_table
+ (L, hs_func_num(func1, 2.718), hs_func_num(func2, 1.618));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_num(2.718);
+ loadkey_func(index, func2);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_func_str)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+ int index = hs_create_table
+ (L, hs_func_str(func1, "hello"), hs_func_str(func2, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_str("hello");
+ loadkey_func(index, func2);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_func_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_func_tbl(func1, value1), hs_func_tbl(func2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_func(index, func1);
+ checkval_tbl(value1);
+ loadkey_func(index, func2);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_func_func)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+
+ luaL_loadstring(L, "print('hello')");
+ store(value1);
+ luaL_loadstring(L, "print('hello')");
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_func_func(func1, value1), hs_func_func(func2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_func(index, func1);
+ checkval_func(value1);
+ loadkey_func(index, func2);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_func_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+ int index = hs_create_table
+ (L, hs_func_cfunc(func1, testfunc1), hs_func_cfunc(func2, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_cfunc(testfunc1);
+ loadkey_func(index, func2);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_func_user)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+
+ lua_newuserdata(L, sizeof(char));
+ store(user1);
+ lua_newuserdata(L, sizeof(char));
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_func_user(func1, user1), hs_func_user(func2, user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ load(user1);
+ load(user2);
+
+ loadkey_func(index, func1);
+ checkval_user(user1);
+ loadkey_func(index, func2);
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_func_light)
+{
+ int a1 = 5;
+ void *light1 = (void *) &a1;
+ int a2 = 6;
+ void *light2 = (void *) &a2;
+
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(func1);
+ luaL_loadstring(L, "print('')");
+ store(func2);
+
+ int index = hs_create_table
+ (L, hs_func_light(func1, light1), hs_func_light(func2, light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_light(light1);
+ loadkey_func(index, func2);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
* test suite
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -436,7 +1270,7 @@ TEST(create_table_int_light)
void hs_create_table_tests()
{
printf("running hs_create_table() tests...\n");
-
+
mu_run_test("return correct stack index", table_correct_index);
/* boolean keys */
@@ -479,7 +1313,7 @@ void hs_create_table_tests()
mu_run_test("create table with integer keys and light userdata values", \
create_table_int_light);
- /* number keys /
+ /* number keys */
mu_run_test("create table with number keys and boolean values",
create_table_num_bool);
mu_run_test("create table with number keys and integer values", \
@@ -499,7 +1333,7 @@ void hs_create_table_tests()
mu_run_test("create table with number keys and light userdata values", \
create_table_num_light);
- /* string keys /
+ /* string keys */
mu_run_test("create table with string keys and boolean values",
create_table_str_bool);
mu_run_test("create table with string keys and integer values", \
@@ -519,7 +1353,7 @@ void hs_create_table_tests()
mu_run_test("create table with string keys and light userdata values", \
create_table_str_light);
- /* table keys /
+ /* table keys */
mu_run_test("create table with table keys and boolean values",
create_table_tbl_bool);
mu_run_test("create table with table keys and integer values", \
@@ -538,6 +1372,24 @@ void hs_create_table_tests()
create_table_tbl_user);
mu_run_test("create table with table keys and light userdata values", \
create_table_tbl_light);
- /**/
+ /* function keys */
+ mu_run_test("create table with function keys and boolean values",
+ create_table_func_bool);
+ mu_run_test("create table with function keys and integer values", \
+ create_table_func_int);
+ mu_run_test("create table with function keys and number values", \
+ create_table_func_num);
+ mu_run_test("create table with function keys and string values", \
+ create_table_func_str);
+ mu_run_test("create table with function keys and table values", \
+ create_table_func_tbl);
+ mu_run_test("create table with function keys and function values", \
+ create_table_func_func);
+ mu_run_test("create table with function keys and C function values", \
+ create_table_func_cfunc);
+ mu_run_test("create table with function keys and userdata values", \
+ create_table_func_user);
+ mu_run_test("create table with function keys and light userdata values", \
+ create_table_func_light);
}