summaryrefslogtreecommitdiff
path: root/libs/honeysuckle/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libs/honeysuckle/src/tests')
-rw-r--r--libs/honeysuckle/src/tests/colors.h22
-rw-r--r--libs/honeysuckle/src/tests/hs_create_table_tests.c2239
-rw-r--r--libs/honeysuckle/src/tests/hs_parse_args_tests.c603
-rw-r--r--libs/honeysuckle/src/tests/hs_parse_overloaded_tests.c188
-rw-r--r--libs/honeysuckle/src/tests/hs_process_table_tests.c511
-rw-r--r--libs/honeysuckle/src/tests/hs_pushstring_tests.c52
-rw-r--r--libs/honeysuckle/src/tests/hs_tests.h63
-rw-r--r--libs/honeysuckle/src/tests/hs_throw_error_tests.c57
-rw-r--r--libs/honeysuckle/src/tests/hs_type_to_string_tests.c102
-rw-r--r--libs/honeysuckle/src/tests/tests_main.c33
10 files changed, 3870 insertions, 0 deletions
diff --git a/libs/honeysuckle/src/tests/colors.h b/libs/honeysuckle/src/tests/colors.h
new file mode 100644
index 0000000..21451de
--- /dev/null
+++ b/libs/honeysuckle/src/tests/colors.h
@@ -0,0 +1,22 @@
+#ifndef COLORS_H
+#define COLORS_H
+
+#define RESET "\033[0m"
+#define BLACK "\033[30m" /* Black */
+#define RED "\033[31m" /* Red */
+#define GREEN "\033[32m" /* Green */
+#define YELLOW "\033[33m" /* Yellow */
+#define BLUE "\033[34m" /* Blue */
+#define MAGENTA "\033[35m" /* Magenta */
+#define CYAN "\033[36m" /* Cyan */
+#define WHITE "\033[37m" /* White */
+#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
+#define BOLDRED "\033[1m\033[31m" /* Bold Red */
+#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
+#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
+#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
+#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
+#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
+#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
+
+#endif
diff --git a/libs/honeysuckle/src/tests/hs_create_table_tests.c b/libs/honeysuckle/src/tests/hs_create_table_tests.c
new file mode 100644
index 0000000..1adc947
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_create_table_tests.c
@@ -0,0 +1,2239 @@
+#include "hs_tests.h"
+
+static int testfunc1(lua_State *L) { return 0; }
+static int testfunc2(lua_State *L) { return 0; }
+
+static void print_stack(lua_State *L)
+{
+ printf("stack: %d [", lua_gettop(L));
+ for (int i=0; i<lua_gettop(L); i++) {
+ printf(" %s, ", lua_typename(L, lua_type(L, i+1)));
+ }
+ printf("]\n");
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for hs_create_table
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(table_correct_index)
+{
+ int top_old = lua_gettop(L);
+ int index = hs_create_table(L);
+ mu_assert("the stack is unchanged!", lua_gettop(L) != top_old);
+ mu_assert("returned incorrect index!", index == lua_gettop(L));
+ return 0;
+}
+
+#define load_key(index, value, pushf) do { \
+ pushf(L, value); lua_gettable(L, index); \
+ mu_assert("value at key '" #value "' is nil!", \
+ !lua_isnil(L, -1)); \
+ } while(0)
+
+#define loadkey_bool(index, value) \
+ load_key(index, value, lua_pushboolean)
+#define loadkey_int(index, value) \
+ load_key(index, value, lua_pushinteger)
+#define loadkey_num(index, value) \
+ load_key(index, value, lua_pushnumber)
+#define loadkey_str(index, value) \
+ lua_getfield(L, index, value)
+#define loadkey_tbl(index, value) do { \
+ lua_pushvalue(L, value); lua_gettable(L, index); \
+ mu_assert("value at table (index '" #value "') is nil!", \
+ !lua_isnil(L, -1)); \
+ } while(0)
+#define loadkey_func(index, value) do { \
+ lua_pushvalue(L, value); lua_gettable(L, index); \
+ mu_assert("value at function (index '" #value "') is nil!", \
+ !lua_isnil(L, -1)); \
+ } while(0)
+#define loadkey_cfunc(index, value) \
+ load_key(index, value, lua_pushcfunction)
+#define loadkey_user(index, value) do { \
+ lua_pushvalue(L, value); lua_gettable(L, index); \
+ mu_assert("value at userdata (index '" #value "') is nil!", \
+ !lua_isnil(L, -1)); \
+ } while(0)
+#define loadkey_light(index, value) \
+ load_key(index, value, lua_pushlightuserdata)
+
+#define check_value(is_type, typestring, type, conversion, comparison) \
+ do { \
+ mu_assert("value is not of type " typestring, is_type(L, -1)); \
+ type value = conversion(L, -1); lua_pop(L, 1); \
+ mu_assert("test " #comparison " failed!", (comparison)); \
+ } while(0)
+
+#define checkval_bool(expected) \
+ check_value(lua_isboolean, "boolean", bool, lua_toboolean, value==expected)
+#define checkval_int(expected) \
+ check_value(lua_isnumber, "integer", lua_Integer, lua_tointeger, value==expected)
+#define checkval_num(expected) \
+ check_value(lua_isnumber, "number", lua_Number, lua_tonumber, value==expected)
+#define checkval_str(expected) \
+ check_value(lua_isstring, "string", const char *, lua_tostring, strcmp(value, expected)==0)
+#define checkval_tbl(expected) \
+ check_value(lua_istable, "table", const void *, lua_topointer, value==lua_topointer(L, expected))
+#define checkval_func(expected) \
+ check_value(lua_isfunction, "function", const void *, lua_topointer, value==lua_topointer(L, expected))
+#define checkval_cfunc(expected) \
+ check_value(lua_iscfunction, "C function", lua_CFunction, lua_tocfunction, value==expected)
+#define checkval_user(expected) \
+ check_value(lua_isuserdata, "userdata", void *, lua_touserdata, value==lua_topointer(L, expected))
+#define checkval_light(expected) \
+ check_value(lua_islightuserdata, "light userdata", void *, lua_touserdata, value==expected)
+
+#define store(name) \
+ lua_pushvalue(L, -1); \
+ int name ## _ref = luaL_ref(L, LUA_REGISTRYINDEX); \
+ int name = lua_gettop(L);
+
+#define load(name) \
+ lua_rawgeti(L, LUA_REGISTRYINDEX, name ## _ref); \
+ name = lua_gettop(L);
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * boolean keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_bool_bool)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_bool_bool(true, true), hs_bool_bool(false, true));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_bool(index, true);
+ checkval_bool(true);
+ loadkey_bool(index, false);
+ checkval_bool(true);
+ return 0;
+}
+
+TEST(create_table_bool_int)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_bool_int(true, 15), hs_bool_int(false, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_bool(index, true);
+ checkval_int(15);
+ loadkey_bool(index, false);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_bool_num)
+{
+ int oldtop = lua_gettop(L);
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_bool(index, true);
+ checkval_num(2.718);
+ loadkey_bool(index, false);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_bool_str)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_bool_str(true, "hello"), hs_bool_str(false, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_bool(index, true);
+ checkval_str("hello");
+ loadkey_bool(index, false);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_bool_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_bool_tbl(true, value1), hs_bool_tbl(false, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(value1);
+ load(value2);
+
+ loadkey_bool(index, true);
+ checkval_tbl(value1);
+ loadkey_bool(index, false);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_bool_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_bool_func(true, value1), hs_bool_func(false, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(value1);
+ load(value2);
+
+ loadkey_bool(index, true);
+ checkval_func(value1);
+ loadkey_bool(index, false);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_bool_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_bool_cfunc(true, testfunc1), hs_bool_cfunc(false, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_bool(index, true);
+ checkval_cfunc(testfunc1);
+ loadkey_bool(index, false);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_bool_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_bool_user(true, user1), hs_bool_user(false, user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_bool(index, true);
+ checkval_user(user1);
+ loadkey_bool(index, false);
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_bool_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_bool_light(true, light1), hs_bool_light(false, light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_bool(index, true);
+ checkval_light(light1);
+ loadkey_bool(index, false);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * integer keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_int_bool)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_int_bool(15, true), hs_int_bool(25, true));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_int(index, 15);
+ checkval_bool(true);
+ loadkey_int(index, 25);
+ checkval_bool(true);
+ return 0;
+}
+
+TEST(create_table_int_int)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_int_int(15, 15), hs_int_int(25, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_int(index, 15);
+ checkval_int(15);
+ loadkey_int(index, 25);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_int_num)
+{
+ int oldtop = lua_gettop(L);
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_int(index, 15);
+ checkval_num(2.718);
+ loadkey_int(index, 25);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_int_str)
+{
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_int_str(15, "hello"), hs_int_str(25, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_int(index, 15);
+ checkval_str("hello");
+ loadkey_int(index, 25);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_int_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_int_tbl(15, value1), hs_int_tbl(25, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(value1);
+ load(value2);
+
+ loadkey_int(index, 15);
+ checkval_tbl(value1);
+ loadkey_int(index, 25);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_int_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_int_func(15, value1), hs_int_func(25, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(value1);
+ load(value2);
+
+ loadkey_int(index, 15);
+ checkval_func(value1);
+ loadkey_int(index, 25);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_int_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+ int index = hs_create_table
+ (L, hs_int_cfunc(15, testfunc1), hs_int_cfunc(25, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_int(index, 15);
+ checkval_cfunc(testfunc1);
+ loadkey_int(index, 25);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_int_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_int_user(15, user1), hs_int_user(25, user2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_int(index, 15);
+ checkval_user(user1);
+ loadkey_int(index, 25);
+ checkval_user(user2);
+ return 0;
+}
+
+TEST(create_table_int_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_int_light(15, light1), hs_int_light(25, light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_int(index, 15);
+ checkval_light(light1);
+ loadkey_int(index, 25);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_num(index, 43.3f);
+ checkval_light(light1);
+ loadkey_num(index, 23.56f);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * string 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(func1);
+ load(func2);
+
+ loadkey_func(index, func1);
+ checkval_light(light1);
+ loadkey_func(index, func2);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * C function keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+/* todo */
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * userdata keys
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_table_user_bool)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_user_bool(user1, true), hs_user_bool(user2, false));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_user(index, user1);
+ checkval_bool(true);
+ loadkey_user(index, user2);
+ checkval_bool(false);
+ return 0;
+}
+
+TEST(create_table_user_int)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_user_int(user1, 15), hs_user_int(user2, 25));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_user(index, user1);
+ checkval_int(15);
+ loadkey_user(index, user2);
+ checkval_int(25);
+ return 0;
+}
+
+TEST(create_table_user_num)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_user_num(user1, 2.718), hs_user_num(user2, 1.618));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_user(index, user1);
+ checkval_num(2.718);
+ loadkey_user(index, user2);
+ checkval_num(1.618);
+ return 0;
+}
+
+TEST(create_table_user_str)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_user_str(user1, "hello"), hs_user_str(user2, "world"));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_user(index, user1);
+ checkval_str("hello");
+ loadkey_user(index, user2);
+ checkval_str("world");
+ return 0;
+}
+
+TEST(create_table_user_tbl)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+
+ lua_newtable(L);
+ store(value1);
+ lua_newtable(L);
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_user_tbl(user1, value1), hs_user_tbl(user2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_user(index, user1);
+ checkval_tbl(value1);
+ loadkey_user(index, user2);
+ checkval_tbl(value2);
+ return 0;
+}
+
+TEST(create_table_user_func)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+
+ luaL_loadstring(L, "print('hello')");
+ store(value1);
+ luaL_loadstring(L, "print('hello')");
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_user_func(user1, value1), hs_user_func(user2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_user(index, user1);
+ checkval_func(value1);
+ loadkey_user(index, user2);
+ checkval_func(value2);
+ return 0;
+}
+
+TEST(create_table_user_cfunc)
+{
+
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_user_cfunc(user1, testfunc1), hs_user_cfunc(user2, testfunc2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_user(index, user1);
+ checkval_cfunc(testfunc1);
+ loadkey_user(index, user2);
+ checkval_cfunc(testfunc2);
+ return 0;
+}
+
+
+TEST(create_table_user_user)
+{
+ int oldtop = lua_gettop(L);
+
+ luaL_loadstring(L, "print('')");
+ store(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+
+ lua_newuserdata(L, sizeof(char));
+ store(value1);
+ lua_newuserdata(L, sizeof(char));
+ store(value2);
+
+ int index = hs_create_table
+ (L, hs_user_user(user1, value1), hs_user_user(user2, value2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ load(value1);
+ load(value2);
+
+ loadkey_user(index, user1);
+ checkval_user(value1);
+ loadkey_user(index, user2);
+ checkval_user(value2);
+ return 0;
+}
+
+TEST(create_table_user_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(user1);
+ luaL_loadstring(L, "print('')");
+ store(user2);
+
+ int index = hs_create_table
+ (L, hs_user_light(user1, light1), hs_user_light(user2, light2));
+ mu_assert_equal(oldtop + 1, lua_gettop(L));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ load(user1);
+ load(user2);
+
+ loadkey_user(index, user1);
+ checkval_light(light1);
+ loadkey_user(index, user2);
+ checkval_light(light2);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ 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));
+ mu_assert_equal(index, lua_gettop(L));
+ mu_assert_equal(lua_type(L, index), LUA_TTABLE);
+
+ loadkey_light(index, light1);
+ checkval_light(value1);
+ loadkey_light(index, light2);
+ checkval_light(value2);
+ return 0;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * nested tables
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(create_nested_table)
+{
+ int index = hs_create_table
+ (L,
+ hs_str_tbl("sub1", hs_create_table(L, hs_str_int("five", 5))),
+ hs_str_tbl("sub2", hs_create_table(L, hs_str_int("six", 6)))
+ );
+
+ mu_assert_equal(lua_gettop(L), 1);
+
+
+ lua_getfield(L, index, "sub1");
+ mu_assert("'sub1' is not a table!", lua_istable(L, -1));
+ lua_getfield(L, -1, "five");
+ mu_assert("'sub1.five' is not a number!", lua_isnumber(L, -1));
+ mu_assert_equal(lua_tointeger(L, -1), 5);
+
+ lua_pop(L, 2);
+
+ lua_getfield(L, index, "sub2");
+ mu_assert("'sub2' is not a table!", lua_istable(L, -1));
+ lua_getfield(L, -1, "six");
+ mu_assert("'sub2.six' is not a number!", lua_isnumber(L, -1));
+ mu_assert_equal(lua_tointeger(L, -1), 6);
+
+ return 0;
+}
+
+TEST(create_tree)
+{
+ /*
+ * { 0={ 0={ 0=0, 1=1},
+ * 1={ 0=0, 1=1},
+ * },
+ * 1={ 0={ 0=0, 1=1},
+ * 1={ 0=0, 1=1},
+ * },
+ * }
+ */
+ int index = hs_create_table
+ (L,
+ hs_int_tbl(0,
+ hs_create_table
+ (L,
+ hs_int_tbl(0,
+ hs_create_table
+ (L,
+ hs_int_int(0, 0),
+ hs_int_int(1, 1)
+ )),
+ hs_int_tbl(1,
+ hs_create_table
+ (L,
+ hs_int_int(0, 0),
+ hs_int_int(1, 1)
+ )),
+ )),
+ hs_int_tbl(1,
+ hs_create_table
+ (L,
+ hs_int_tbl(0,
+ hs_create_table
+ (L,
+ hs_int_int(0, 0),
+ hs_int_int(1, 1)
+ )),
+ hs_int_tbl(1,
+ hs_create_table
+ (L,
+ hs_int_int(0, 0),
+ hs_int_int(1, 1)
+ )),
+ ))
+ );
+
+ mu_assert_equal(lua_gettop(L), 1);
+
+ lua_rawgeti(L, index, 0);
+ mu_assert("tbl[0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[0][0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[0][0][0] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 0);
+ mu_assert("tbl[0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[0][0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[0][0][1] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 0);
+ mu_assert("tbl[0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[0][1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[0][1][0] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 0);
+ mu_assert("tbl[0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[0][1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[0][1][1] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 1);
+ mu_assert("tbl[1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[1][0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[1][0][0] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 1);
+ mu_assert("tbl[1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[1][0] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[1][0][1] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 1);
+ mu_assert("tbl[1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[1][1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 0);
+ mu_assert("tbl[1][1][0] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ lua_rawgeti(L, index, 1);
+ mu_assert("tbl[1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[1][1] is not a table!", lua_istable(L, -1));
+ lua_rawgeti(L, -1, 1);
+ mu_assert("tbl[1][1][1] is not a number!", lua_isnumber(L, -1));
+ lua_pop(L, 3);
+
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * test suite
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+void hs_create_table_tests()
+{
+ printf("running hs_create_table() tests...\n");
+
+ mu_run_test("return correct stack index", table_correct_index);
+
+ /* boolean keys */
+ mu_run_test("create table with boolean keys and boolean values",
+ create_table_bool_bool);
+ mu_run_test("create table with boolean keys and integer values", \
+ create_table_bool_int);
+ mu_run_test("create table with boolean keys and number values", \
+ create_table_bool_num);
+ mu_run_test("create table with boolean keys and string values", \
+ create_table_bool_str);
+ mu_run_test("create table with boolean keys and table values", \
+ create_table_bool_tbl);
+ mu_run_test("create table with boolean keys and function values", \
+ create_table_bool_func);
+ mu_run_test("create table with boolean keys and C function values", \
+ create_table_bool_cfunc);
+ mu_run_test("create table with boolean keys and userdata values", \
+ create_table_bool_user);
+ mu_run_test("create table with boolean keys and light userdata values", \
+ create_table_bool_light);
+
+ /* integer keys */
+ mu_run_test("create table with integer keys and boolean values",
+ create_table_int_bool);
+ mu_run_test("create table with integer keys and integer values", \
+ create_table_int_int);
+ mu_run_test("create table with integer keys and number values", \
+ create_table_int_num);
+ mu_run_test("create table with integer keys and string values", \
+ create_table_int_str);
+ mu_run_test("create table with integer keys and table values", \
+ create_table_int_tbl);
+ mu_run_test("create table with integer keys and function values", \
+ create_table_int_func);
+ mu_run_test("create table with integer keys and C function values", \
+ create_table_int_cfunc);
+ mu_run_test("create table with integer keys and userdata values", \
+ create_table_int_user);
+ mu_run_test("create table with integer keys and light userdata values", \
+ create_table_int_light);
+
+ /* 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", \
+ create_table_num_int);
+ mu_run_test("create table with number keys and number values", \
+ create_table_num_num);
+ mu_run_test("create table with number keys and string values", \
+ create_table_num_str);
+ mu_run_test("create table with number keys and table values", \
+ create_table_num_tbl);
+ mu_run_test("create table with number keys and function values", \
+ create_table_num_func);
+ mu_run_test("create table with number keys and C function values", \
+ create_table_num_cfunc);
+ mu_run_test("create table with number keys and userdata values", \
+ create_table_num_user);
+ mu_run_test("create table with number keys and light userdata values", \
+ create_table_num_light);
+
+ /* 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", \
+ create_table_str_int);
+ mu_run_test("create table with string keys and number values", \
+ create_table_str_num);
+ mu_run_test("create table with string keys and string values", \
+ create_table_str_str);
+ mu_run_test("create table with string keys and table values", \
+ create_table_str_tbl);
+ mu_run_test("create table with string keys and function values", \
+ create_table_str_func);
+ mu_run_test("create table with string keys and C function values", \
+ create_table_str_cfunc);
+ mu_run_test("create table with string keys and userdata values", \
+ create_table_str_user);
+ mu_run_test("create table with string keys and light userdata values", \
+ create_table_str_light);
+
+ /* 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", \
+ create_table_tbl_int);
+ mu_run_test("create table with table keys and number values", \
+ create_table_tbl_num);
+ mu_run_test("create table with table keys and string values", \
+ create_table_tbl_str);
+ mu_run_test("create table with table keys and table values", \
+ create_table_tbl_tbl);
+ mu_run_test("create table with table keys and function values", \
+ create_table_tbl_func);
+ mu_run_test("create table with table keys and C function values", \
+ create_table_tbl_cfunc);
+ mu_run_test("create table with table keys and userdata values", \
+ 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);
+
+ /* C function keys /
+ mu_run_test("create table with C function keys and boolean values",
+ create_table_cfunc_bool);
+ mu_run_test("create table with C function keys and integer values", \
+ create_table_cfunc_int);
+ mu_run_test("create table with C function keys and number values", \
+ create_table_cfunc_num);
+ mu_run_test("create table with C function keys and string values", \
+ create_table_cfunc_str);
+ mu_run_test("create table with C function keys and table values", \
+ create_table_cfunc_tbl);
+ mu_run_test("create table with C function keys and function values", \
+ create_table_cfunc_func);
+ mu_run_test("create table with C function keys and C function values", \
+ create_table_cfunc_cfunc);
+ mu_run_test("create table with C function keys and userdata values", \
+ create_table_cfunc_user);
+ mu_run_test("create table with C function keys and light userdata values", \
+ create_table_cfunc_light);
+
+ /* userdata keys */
+ mu_run_test("create table with userdata keys and boolean values",
+ create_table_user_bool);
+ mu_run_test("create table with userdata keys and integer values", \
+ create_table_user_int);
+ mu_run_test("create table with userdata keys and number values", \
+ create_table_user_num);
+ mu_run_test("create table with userdata keys and string values", \
+ create_table_user_str);
+ mu_run_test("create table with userdata keys and table values", \
+ create_table_user_tbl);
+ mu_run_test("create table with userdata keys and function values", \
+ create_table_user_func);
+ mu_run_test("create table with userdata keys and C function values", \
+ create_table_user_cfunc);
+ mu_run_test("create table with userdata keys and userdata values", \
+ 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);
+
+ mu_run_test("create nested tables", create_nested_table);
+ mu_run_test("create tree of nested tables", create_tree);
+}
diff --git a/libs/honeysuckle/src/tests/hs_parse_args_tests.c b/libs/honeysuckle/src/tests/hs_parse_args_tests.c
new file mode 100644
index 0000000..83178f3
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_parse_args_tests.c
@@ -0,0 +1,603 @@
+#include "hs_tests.h"
+
+static int testfunc(lua_State *L) { return 0; }
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * hs_parse_args typechecking tests
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+// typechecking macros
+#define PARSE_TYPECHECK_TEST(name, type, macro) \
+ int name ## _testfunc(lua_State *L) { \
+ type test; hs_parse_args(L, macro(test)); \
+ return 0; \
+ } \
+ TEST(name)
+
+#define CHECK_FAIL_BOOL(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushboolean(L, true); \
+ mu_assert("incorrectly succeeded in parsing boolean!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_INT(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushinteger(L, 5); \
+ mu_assert("incorrectly succeeded in parsing integer!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_NUM(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushnumber(L, 42.0f); \
+ mu_assert("incorrectly succeeded in parsing number!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_STRING(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushstring(L, "hello!"); \
+ mu_assert("incorrectly succeeded in parsing string!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_TABLE(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_getglobal(L, "debug"); \
+ mu_assert("incorrectly succeeded in parsing table!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_FUNC(name) \
+ lua_pushcfunction(L, name ## _testfunc); \
+ luaL_loadstring(L, "print('hello, world!')"); \
+ mu_assert("incorrectly succeeded in parsing function!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_CFUNC(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushvalue(L, -1); \
+ mu_assert("incorrectly succeeded in parsing C function!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_USER(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_newuserdata(L, sizeof(char)); \
+ mu_assert("incorrectly succeeded in parsing userdata!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_LIGHT(name) \
+ int test_data = 5; \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushlightuserdata(L, &test_data); \
+ mu_assert("incorrectly succeeded in parsing light userdata!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+#define CHECK_FAIL_NIL(name) \
+ lua_pushcfunction(L, name ## _testfunc); lua_pushnil(L); \
+ mu_assert("incorrectly succeeded in parsing nil!", \
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
+
+
+PARSE_TYPECHECK_TEST(parse_bool_typecheck, bool, hs_bool)
+{
+ lua_pushcfunction(L, parse_bool_typecheck_testfunc);
+ lua_pushboolean(L, true);
+ mu_assert("typecheck for bool failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_INT(parse_bool_typecheck);
+ CHECK_FAIL_NUM(parse_bool_typecheck);
+ CHECK_FAIL_STRING(parse_bool_typecheck);
+ CHECK_FAIL_TABLE(parse_bool_typecheck);
+ CHECK_FAIL_FUNC(parse_bool_typecheck);
+ CHECK_FAIL_CFUNC(parse_bool_typecheck);
+ CHECK_FAIL_USER(parse_bool_typecheck);
+ CHECK_FAIL_LIGHT(parse_bool_typecheck);
+ CHECK_FAIL_NIL(parse_bool_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_int_typecheck, lua_Integer, hs_int)
+{
+ CHECK_FAIL_BOOL(parse_int_typecheck);
+
+ lua_pushcfunction(L, parse_int_typecheck_testfunc);
+ lua_pushinteger(L, 5);
+ mu_assert("typecheck for int failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ // we would check for num, but in lua 5.1 there
+ // isn't a separate integer type, so it would
+ // still work
+ CHECK_FAIL_STRING(parse_int_typecheck);
+ CHECK_FAIL_TABLE(parse_int_typecheck);
+ CHECK_FAIL_FUNC(parse_int_typecheck);
+ CHECK_FAIL_CFUNC(parse_int_typecheck);
+ CHECK_FAIL_USER(parse_int_typecheck);
+ CHECK_FAIL_LIGHT(parse_int_typecheck);
+ CHECK_FAIL_NIL(parse_int_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_num_typecheck, lua_Number, hs_num)
+{
+ CHECK_FAIL_BOOL(parse_num_typecheck);
+ // we would check for int, but in lua 5.1 there
+ // isn't a separate integer type, so it would
+ // still work
+
+ lua_pushcfunction(L, parse_int_typecheck_testfunc);
+ lua_pushnumber(L, 42.0f);
+ mu_assert("typecheck for number failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_STRING(parse_num_typecheck);
+ CHECK_FAIL_TABLE(parse_num_typecheck);
+ CHECK_FAIL_FUNC(parse_num_typecheck);
+ CHECK_FAIL_CFUNC(parse_num_typecheck);
+ CHECK_FAIL_USER(parse_num_typecheck);
+ CHECK_FAIL_LIGHT(parse_num_typecheck);
+ CHECK_FAIL_NIL(parse_num_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_string_typecheck, char *, hs_str)
+{
+ CHECK_FAIL_BOOL(parse_string_typecheck);
+ CHECK_FAIL_INT(parse_string_typecheck);
+ CHECK_FAIL_NUM(parse_string_typecheck);
+
+ lua_pushcfunction(L, parse_string_typecheck_testfunc);
+ lua_pushstring(L, "hello!");
+ mu_assert("typecheck for string failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_TABLE(parse_string_typecheck);
+ CHECK_FAIL_FUNC(parse_string_typecheck);
+ CHECK_FAIL_CFUNC(parse_string_typecheck);
+ CHECK_FAIL_USER(parse_string_typecheck);
+ CHECK_FAIL_LIGHT(parse_string_typecheck);
+ CHECK_FAIL_NIL(parse_string_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_table_typecheck, int, hs_tbl)
+{
+ CHECK_FAIL_BOOL(parse_table_typecheck);
+ CHECK_FAIL_INT(parse_table_typecheck);
+ CHECK_FAIL_NUM(parse_table_typecheck);
+ CHECK_FAIL_STRING(parse_table_typecheck);
+
+ lua_pushcfunction(L, parse_table_typecheck_testfunc);
+ lua_getglobal(L, "debug");
+ mu_assert("typecheck for table failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_FUNC(parse_table_typecheck);
+ CHECK_FAIL_CFUNC(parse_table_typecheck);
+ CHECK_FAIL_USER(parse_table_typecheck);
+ CHECK_FAIL_LIGHT(parse_table_typecheck);
+ CHECK_FAIL_NIL(parse_table_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_func_typecheck, int, hs_func)
+{
+ CHECK_FAIL_BOOL(parse_func_typecheck);
+ CHECK_FAIL_INT(parse_func_typecheck);
+ CHECK_FAIL_NUM(parse_func_typecheck);
+ CHECK_FAIL_STRING(parse_func_typecheck);
+ CHECK_FAIL_TABLE(parse_func_typecheck);
+
+ lua_pushcfunction(L, parse_func_typecheck_testfunc);
+ luaL_loadstring(L, "print('hello, world!')");
+ mu_assert("typecheck for function failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_func_typecheck_testfunc);
+ lua_pushvalue(L, -1);
+ mu_assert("typecheck for C function failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_USER(parse_func_typecheck);
+ CHECK_FAIL_LIGHT(parse_func_typecheck);
+ CHECK_FAIL_NIL(parse_func_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_cfunc_typecheck, lua_CFunction, hs_cfunc)
+{
+ CHECK_FAIL_BOOL(parse_cfunc_typecheck);
+ CHECK_FAIL_INT(parse_cfunc_typecheck);
+ CHECK_FAIL_NUM(parse_cfunc_typecheck);
+ CHECK_FAIL_STRING(parse_cfunc_typecheck);
+ CHECK_FAIL_TABLE(parse_cfunc_typecheck);
+ CHECK_FAIL_FUNC(parse_cfunc_typecheck);
+
+ lua_pushcfunction(L, parse_cfunc_typecheck_testfunc);
+ lua_pushvalue(L, -1);
+ mu_assert("typecheck for C function failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_USER(parse_cfunc_typecheck);
+ CHECK_FAIL_LIGHT(parse_cfunc_typecheck);
+ CHECK_FAIL_NIL(parse_cfunc_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_user_typecheck, void *, hs_user)
+{
+ CHECK_FAIL_BOOL(parse_user_typecheck);
+ CHECK_FAIL_INT(parse_user_typecheck);
+ CHECK_FAIL_NUM(parse_user_typecheck);
+ CHECK_FAIL_STRING(parse_user_typecheck);
+ CHECK_FAIL_TABLE(parse_user_typecheck);
+ CHECK_FAIL_FUNC(parse_user_typecheck);
+ CHECK_FAIL_CFUNC(parse_user_typecheck);
+
+ lua_pushcfunction(L, parse_user_typecheck_testfunc);
+ lua_newuserdata(L, sizeof(char));
+ mu_assert("typecheck for userdata failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_user_typecheck_testfunc);
+ int testdata = 5; lua_pushlightuserdata(L, &testdata);
+ mu_assert("typecheck for light userdata failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_NIL(parse_user_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_light_typecheck, void *, hs_light)
+{
+ CHECK_FAIL_BOOL(parse_light_typecheck);
+ CHECK_FAIL_INT(parse_light_typecheck);
+ CHECK_FAIL_NUM(parse_light_typecheck);
+ CHECK_FAIL_STRING(parse_light_typecheck);
+ CHECK_FAIL_TABLE(parse_light_typecheck);
+ CHECK_FAIL_FUNC(parse_light_typecheck);
+ CHECK_FAIL_CFUNC(parse_light_typecheck);
+ CHECK_FAIL_USER(parse_light_typecheck);
+
+ lua_pushcfunction(L, parse_light_typecheck_testfunc);
+ int testdata = 5; lua_pushlightuserdata(L, &testdata);
+ mu_assert("typecheck for light userdata failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ CHECK_FAIL_NIL(parse_light_typecheck);
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_nil_typecheck, int, hs_nil)
+{
+ CHECK_FAIL_BOOL(parse_nil_typecheck);
+ CHECK_FAIL_INT(parse_nil_typecheck);
+ CHECK_FAIL_NUM(parse_nil_typecheck);
+ CHECK_FAIL_STRING(parse_nil_typecheck);
+ CHECK_FAIL_TABLE(parse_nil_typecheck);
+ CHECK_FAIL_FUNC(parse_nil_typecheck);
+ CHECK_FAIL_CFUNC(parse_nil_typecheck);
+ CHECK_FAIL_USER(parse_nil_typecheck);
+ CHECK_FAIL_LIGHT(parse_nil_typecheck);
+
+ lua_pushcfunction(L, parse_nil_typecheck_testfunc);
+ lua_pushnil(L);
+ mu_assert("typecheck for nil failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ return 0;
+}
+
+PARSE_TYPECHECK_TEST(parse_any_typecheck, int, hs_any)
+{
+ lua_pushcfunction(L, parse_bool_typecheck_testfunc);
+ lua_pushboolean(L, true);
+ mu_assert("typecheck for bool failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_int_typecheck_testfunc);
+ lua_pushinteger(L, 5);
+ mu_assert("typecheck for int failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_int_typecheck_testfunc);
+ lua_pushnumber(L, 42.0f);
+ mu_assert("typecheck for number failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_string_typecheck_testfunc);
+ lua_pushstring(L, "hello!");
+ mu_assert("typecheck for string failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_table_typecheck_testfunc);
+ lua_getglobal(L, "debug");
+ mu_assert("typecheck for table failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_func_typecheck_testfunc);
+ luaL_loadstring(L, "print('hello, world!')");
+ mu_assert("typecheck for function failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_cfunc_typecheck_testfunc);
+ lua_pushvalue(L, -1);
+ mu_assert("typecheck for C function failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_user_typecheck_testfunc);
+ lua_newuserdata(L, sizeof(char));
+ mu_assert("typecheck for userdata failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_user_typecheck_testfunc);
+ int testdata = 5; lua_pushlightuserdata(L, &testdata);
+ mu_assert("typecheck for light userdata failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ lua_pushcfunction(L, parse_nil_typecheck_testfunc);
+ lua_pushnil(L);
+ mu_assert("typecheck for nil failed!",
+ lua_pcall(L, 1, 0, 0) == 0);
+
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * hs_parse_args parsing tests
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(parse_bool)
+{
+ lua_pushboolean(L, true);
+ bool b = false;
+ hs_parse_args(L, hs_bool(b));
+ mu_assert("failed to properly parse boolean!", b);
+ return 0;
+}
+
+TEST(parse_int)
+{
+ lua_pushinteger(L, 420);
+ lua_Integer i = 0;
+ hs_parse_args(L, hs_int(i));
+ mu_assert("failed to properly parse integer!", i == 420);
+ return 0;
+}
+
+TEST(parse_num)
+{
+ lua_pushnumber(L, 40.5f);
+ lua_Number n = 0;
+ hs_parse_args(L, hs_num(n));
+ mu_assert("failed to properly parse number!", n == 40.5f);
+ return 0;
+}
+
+TEST(parse_str)
+{
+ lua_pushstring(L, "hello, world!");
+ char *s = "";
+ hs_parse_args(L, hs_str(s));
+ mu_assert("failed to properly parse string!",
+ strcmp(s, "hello, world!") == 0);
+ return 0;
+}
+
+TEST(parse_tbl)
+{
+ lua_getglobal(L, "debug");
+ int correct_index = lua_gettop(L);
+ int tbl_index;
+ hs_parse_args(L, hs_tbl(tbl_index));
+ mu_assert("failed to properly parse table!", tbl_index == correct_index);
+ return 0;
+}
+
+TEST(parse_func)
+{
+ lua_getglobal(L, "type");
+ int correct_index = lua_gettop(L);
+ int index = 0;
+ hs_parse_args(L, hs_func(index));
+ mu_assert("failed to properly parse function!", index == correct_index);
+ return 0;
+}
+
+TEST(parse_cfunc)
+{
+ lua_pushcfunction(L, testfunc);
+ lua_CFunction f;
+ hs_parse_args(L, hs_cfunc(f));
+ mu_assert("failed to properly parse C function!", f == testfunc);
+ return 0;
+}
+
+int should_fail(lua_State *L)
+{
+ lua_CFunction f;
+ hs_parse_args(L, hs_cfunc(f));
+ return 0;
+}
+
+TEST(fail_parse_noncfunc)
+{
+ lua_pushcfunction(L, should_fail);
+ luaL_loadstring(L, "print('hello, world!')");
+ mu_assert("incorrectly parsed non-C function!",
+ lua_pcall(L, 1, 0, 0) != 0);
+ return 0;
+}
+
+TEST(parse_userdata)
+{
+ void *userdata = lua_newuserdata(L, sizeof(char));
+ void *parsed = NULL;
+ hs_parse_args(L, hs_user(parsed));
+ mu_assert("failed to properly parse userdata!",
+ parsed == userdata);
+ return 0;
+}
+
+TEST(parse_lightuserdata)
+{
+ int five = 5;
+ lua_pushlightuserdata(L, &five);
+
+ void *data;
+ hs_parse_args(L, hs_light(data));
+ mu_assert("failed to properly parse light userdata!",
+ data == &five);
+ return 0;
+}
+
+TEST(parse_nil)
+{
+ lua_pushnil(L);
+ int correct_index = lua_gettop(L);
+ int index = 0;
+ hs_parse_args(L, hs_nil(index));
+ mu_assert("failed to properly parse nil!",
+ index == correct_index);
+ return 0;
+}
+
+TEST(parse_any)
+{
+ lua_pushnil(L);
+ int correct_index = lua_gettop(L);
+ int index = 0;
+ hs_parse_args(L, hs_any(index));
+ mu_assert("failed to properly parse [any]!",
+ index == correct_index);
+ return 0;
+}
+
+TEST(parse_all)
+{
+ lua_pushboolean(L, true);
+ lua_pushinteger(L, 420);
+ lua_pushnumber(L, 40.5f);
+ lua_pushstring(L, "hello, world!");
+ lua_getglobal(L, "debug");
+ int tbl_index = lua_gettop(L);
+ lua_getglobal(L, "type");
+ int func_index = lua_gettop(L);
+ lua_pushcfunction(L, testfunc);
+ void *userdata = lua_newuserdata(L, sizeof(char));
+ int five = 5;
+ lua_pushlightuserdata(L, &five);
+ lua_pushnil(L);
+ int nil_index = lua_gettop(L);
+ lua_pushnil(L);
+ int any_index = lua_gettop(L);
+
+ bool b;
+ lua_Integer i;
+ lua_Number f;
+ char *str;
+ int i_tbl;
+ int i_func;
+ lua_CFunction fn;
+ void *user;
+ void *light;
+ int i_nil;
+ int i_any;
+ hs_parse_args
+ (L,
+ hs_bool(b),
+ hs_int(i),
+ hs_num(f),
+ hs_str(str),
+ hs_tbl(i_tbl),
+ hs_func(i_func),
+ hs_cfunc(fn),
+ hs_user(user),
+ hs_light(light),
+ hs_nil(i_nil),
+ hs_any(i_any));
+
+ mu_assert("failed to properly parse boolean!", b);
+ mu_assert("failed to properly parse integer!", i == 420);
+ mu_assert("failed to properly parse number!", f == 40.5f);
+ mu_assert("failed to properly parse string!",
+ strcmp(str, "hello, world!") == 0);
+ mu_assert("failed to properly parse table!", i_tbl == tbl_index);
+ mu_assert("failed to properly parse function!", func_index == i_func);
+ mu_assert("failed to properly parse C function!", fn == testfunc);
+ mu_assert("failed to properly parse userdata!", user == userdata);
+ mu_assert("failed to properly parse light userdata!", light == &five);
+ mu_assert("failed to properly parse nil!", nil_index == i_nil);
+ mu_assert("failed to properly parse [any]!", any_index == i_any);
+ return 0;
+}
+
+TEST(parse_readme_example)
+{
+ lua_pushboolean(L, true);
+ lua_pushinteger(L, 7);
+ lua_getglobal(L, "debug");
+ int expected = lua_gettop(L);
+ lua_pushnumber(L, 3.1415f);
+ lua_pushstring(L, "c: c: c:");
+ void *userdata = lua_newuserdata(L, sizeof(char));
+
+ bool b; lua_Integer i; int table_index;
+ lua_Number f; char *str; void *user;
+ hs_parse_args
+ (L, hs_bool(b), hs_int(i), hs_tbl(table_index),
+ hs_num(f), hs_str(str), hs_user(user));
+
+ mu_assert("failed to properly parse boolean!", b);
+ mu_assert("failed to properly parse integer!", i == 7);
+ mu_assert("failed to properly parse table!", table_index == expected);
+ mu_assert("failed to properly parse number!", f == 3.1415f);
+ mu_assert("failed to properly parse string!", strcmp(str, "c: c: c:") == 0);
+ mu_assert("failed to properly parse userdata!", user == userdata);
+ return 0;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * test suite
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+void hs_parse_args_tests()
+{
+ printf("running hs_parse_args() tests...\n");
+ mu_run_test("parse bool typecheck", parse_bool_typecheck);
+ mu_run_test("parse int typecheck", parse_int_typecheck);
+ mu_run_test("parse num typecheck", parse_num_typecheck);
+ mu_run_test("parse string typecheck", parse_string_typecheck);
+ mu_run_test("parse table typecheck", parse_table_typecheck);
+ mu_run_test("parse func typecheck", parse_func_typecheck);
+ mu_run_test("parse cfunc typecheck", parse_cfunc_typecheck);
+ mu_run_test("parse user typecheck", parse_user_typecheck);
+ mu_run_test("parse light typecheck", parse_light_typecheck);
+ mu_run_test("parse nil typecheck", parse_nil_typecheck);
+ mu_run_test("parse any typecheck", parse_any_typecheck);
+
+ mu_run_test("parse bool", parse_bool);
+ mu_run_test("parse int", parse_int);
+ mu_run_test("parse num", parse_num);
+ mu_run_test("parse str", parse_str);
+ mu_run_test("parse tbl", parse_tbl);
+ mu_run_test("parse func", parse_func);
+ mu_run_test("parse cfunc", parse_cfunc);
+ mu_run_test("fail parse noncfunc", fail_parse_noncfunc);
+ mu_run_test("parse userdata", parse_userdata);
+ mu_run_test("parse lightuserdata", parse_lightuserdata);
+ mu_run_test("parse nil", parse_nil);
+ mu_run_test("parse any", parse_any);
+ mu_run_test("parse all", parse_all);
+ mu_run_test("parse readme example", parse_readme_example);
+}
diff --git a/libs/honeysuckle/src/tests/hs_parse_overloaded_tests.c b/libs/honeysuckle/src/tests/hs_parse_overloaded_tests.c
new file mode 100644
index 0000000..0680253
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_parse_overloaded_tests.c
@@ -0,0 +1,188 @@
+#include "hs_tests.h"
+
+static int testfunc(lua_State *L) { return 0; }
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for hs_parse_overloaded
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+#define PARSE_OVERLOADED \
+ bool b; lua_Integer i; int ti, fi, ni; lua_Number f; \
+ char *str; lua_CFunction fn; void *user, *light; \
+ int choice = hs_parse_overloaded \
+ (L, \
+ hs_overload(hs_bool(b)), \
+ hs_overload(hs_int(i)), \
+ hs_overload(hs_num(f)), \
+ hs_overload(hs_str(str)), \
+ hs_overload(hs_tbl(ti)), \
+ hs_overload(hs_func(fi)), \
+ hs_overload(hs_cfunc(fn)), \
+ hs_overload(hs_user(user)), \
+ hs_overload(hs_light(light)), \
+ hs_overload(hs_nil(ni)));
+
+TEST(parse_bool_overloaded)
+{
+ lua_pushboolean(L, true);
+ PARSE_OVERLOADED;
+ mu_assert("boolean option was not chosen!", choice == 0);
+ mu_assert("failed to properly parse boolean!", b);
+ return 0;
+}
+
+TEST(parse_integer_overloaded)
+{
+ lua_pushinteger(L, 5);
+ PARSE_OVERLOADED;
+ mu_assert("integer option was not chosen!", choice == 1);
+ mu_assert("failed to properly parse integer!", i == 5);
+ return 0;
+}
+
+TEST(parse_number_overloaded)
+{
+ lua_pushnumber(L, 42.0f);
+ PARSE_OVERLOADED;
+ mu_assert("number option was not chosen!", choice == 2);
+ mu_assert("failed to properly parse boolean!", f == 42.0f);
+ return 0;
+}
+
+TEST(parse_string_overloaded)
+{
+ lua_pushstring(L, "hello, world!");
+ PARSE_OVERLOADED;
+ mu_assert("string option was not chosen!", choice == 3);
+ mu_assert("failed to properly parse string!",
+ strcmp(str, "hello, world!") == 0);
+ return 0;
+}
+
+TEST(parse_table_overloaded)
+{
+ lua_getglobal(L, "debug");
+ int expected = lua_gettop(L);
+ PARSE_OVERLOADED;
+ mu_assert("table option was not chosen!", choice == 4);
+ mu_assert("failed to properly parse table!", ti == expected);
+ return 0;
+}
+
+TEST(parse_function_overloaded)
+{
+ luaL_loadstring(L, "print('hello, world!')");
+ int expected = lua_gettop(L);
+ PARSE_OVERLOADED;
+ mu_assert("function option was not chosen!", choice == 5);
+ mu_assert("failed to properly parse function!", fi == expected);
+ return 0;
+}
+
+TEST(parse_cfunction_overloaded)
+{
+ lua_pushcfunction(L, testfunc);
+ PARSE_OVERLOADED;
+ mu_assert("C function option was not chosen!", choice == 6);
+ mu_assert("failed to properly parse C function!", fn == testfunc);
+ return 0;
+}
+
+TEST(parse_userdata_overloaded)
+{
+ void *userdata = lua_newuserdata(L, sizeof(char));
+ PARSE_OVERLOADED;
+ mu_assert("userdata option was not chosen!", choice == 7);
+ mu_assert("failed to properly parse userdata!", user == userdata);
+ return 0;
+}
+
+TEST(parse_lightuserdata_overloaded)
+{
+ int five = 5;
+ lua_pushlightuserdata(L, &five);
+ PARSE_OVERLOADED;
+ mu_assert("light userdata option was not chosen!", choice == 8);
+ mu_assert("failed to properly parse light userdata!", light == &five);
+ return 0;
+}
+
+TEST(parse_nil_overloaded)
+{
+ lua_pushnil(L);
+ int expected = lua_gettop(L);
+ PARSE_OVERLOADED;
+ mu_assert("nil option was not chosen!", choice == 9);
+ mu_assert("failed to properly parse nil!", ni == expected);
+ return 0;
+}
+
+TEST(parse_2_3_overload_0)
+{
+ lua_pushinteger(L, 69);
+ lua_pushstring(L, "foo");
+ lua_Integer i; char *str; void *data;
+ int choice = hs_parse_overloaded
+ (L,
+ hs_overload(hs_int(i), hs_str(str)),
+ hs_overload(hs_int(i), hs_str(str), hs_user(data)));
+
+ mu_assert("incorrectly selected option other than 0!", choice == 0);
+ mu_assert("failed to properly parse integer!", i == 69);
+ mu_assert("failed to properly parse string!", strcmp(str, "foo") == 0);
+ return 0;
+}
+
+TEST(parse_2_3_overload_1)
+{
+ lua_pushinteger(L, 69);
+ lua_pushstring(L, "foo");
+ void *userdata = lua_newuserdata(L, sizeof(char));
+ lua_Integer i; char *str; void *data;
+ int choice = hs_parse_overloaded
+ (L,
+ hs_overload(hs_int(i), hs_str(str)),
+ hs_overload(hs_int(i), hs_str(str), hs_user(data)));
+
+ mu_assert("incorrectly selected option other than 1!", choice == 1);
+ mu_assert("failed to properly parse integer!", i == 69);
+ mu_assert("failed to properly parse string!", strcmp(str, "foo") == 0);
+ mu_assert("failed to properly parse userdata!", userdata == data);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * test suite
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+void hs_parse_overloaded_tests()
+{
+ /* the commented tests below require more work to ensure that
+ * they function correctly. Due to type ambiguities that are
+ * useful in other contexts, overloads differing only in a
+ * number/integer, function/cfunction, or userdata/lightuserdata
+ * in the same position are not readily distinguishable from one
+ * another.
+ */
+
+ printf("running hs_parse_overloaded() parsing tests...\n");
+ mu_run_test("parse bool overloaded", parse_bool_overloaded);
+ mu_run_test("parse integer overloaded", parse_integer_overloaded);
+ // mu_run_test("parse number overloaded", parse_number_overloaded);
+ mu_run_test("parse string overloaded", parse_string_overloaded);
+ mu_run_test("parse table overloaded", parse_table_overloaded);
+ mu_run_test("parse function overloaded", parse_function_overloaded);
+ // mu_run_test("parse cfunction overloaded", parse_cfunction_overloaded);
+ mu_run_test("parse userdata overloaded", parse_userdata_overloaded);
+ // mu_run_test("parse lightuserdata overloaded", parse_lightuserdata_overloaded);
+ mu_run_test("parse nil overloaded", parse_nil_overloaded);
+ mu_run_test("parse 2/3 overload 0", parse_2_3_overload_0);
+ mu_run_test("parse 2/3 overload 1", parse_2_3_overload_1);
+}
diff --git a/libs/honeysuckle/src/tests/hs_process_table_tests.c b/libs/honeysuckle/src/tests/hs_process_table_tests.c
new file mode 100644
index 0000000..e8e8c4b
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_process_table_tests.c
@@ -0,0 +1,511 @@
+#include "hs_tests.h"
+
+#define process() \
+ bool boolean = false; \
+ lua_Integer integer = 0; \
+ lua_Number number = 0; \
+ const char *string = ""; \
+ hs_process_table(L, -1, \
+ hs_process_bool("boolean", hs_pt_set_boolean, &boolean), \
+ hs_process_int("integer", hs_pt_set_integer, &integer), \
+ hs_process_num("number", hs_pt_set_number, &number), \
+ hs_process_str("string", hs_pt_set_string, &string));
+
+#define test_set_boolean() do { mu_assert("failed to set boolean!", boolean == true); } while(0);
+#define test_noset_boolean() do { mu_assert("incorrectly set boolean!", boolean == false); } while(0);
+#define test_set_integer() do { mu_assert("failed to set integer!", integer == 14); } while(0);
+#define test_noset_integer() do { mu_assert("incorrectly set integer!", integer == 0); } while(0);
+#define test_set_number() do { mu_assert("failed to set number!", number == 44.66); } while(0);
+#define test_noset_number() do { mu_assert("incorrectly set number!", number == 0); } while(0);
+#define test_set_string() \
+ do { mu_assert("failed to set string!", strcmp(string, "c: c: c:") == 0); } while(0);
+#define test_noset_string() \
+ do { mu_assert("incorrectly set string!", strcmp(string, "") == 0); } while(0);
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for all 16 possible combinations of one table containing one
+ * boolean, integer, number, and string key each.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+
+TEST(process_none)
+{
+ lua_createtable(L, 0, 0);
+
+ process();
+
+ test_noset_boolean();
+ test_noset_integer();
+ test_noset_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_bool)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ process();
+
+ test_set_boolean();
+ test_noset_integer();
+ test_noset_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_int)
+{
+ lua_createtable(L, 0, 0);
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ process();
+
+ test_noset_boolean();
+ test_set_integer();
+ test_noset_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_bool_int)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ process();
+
+ test_set_boolean();
+ test_set_integer();
+ test_noset_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_number)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ process();
+
+ test_noset_boolean();
+ test_noset_integer();
+ test_set_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_bool_number)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ process();
+
+ test_set_boolean();
+ test_noset_integer();
+ test_set_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_int_number)
+{
+ lua_createtable(L, 0, 0);
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ process();
+
+ test_noset_boolean();
+ test_set_integer();
+ test_set_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_bool_int_number)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ process();
+
+ test_set_boolean();
+ test_set_integer();
+ test_set_number();
+ test_noset_string();
+
+ return 0;
+}
+TEST(process_string)
+{
+ lua_createtable(L, 0, 0);
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_noset_boolean();
+ test_noset_integer();
+ test_noset_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_bool_string)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_set_boolean();
+ test_noset_integer();
+ test_noset_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_int_string)
+{
+ lua_createtable(L, 0, 0);
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_noset_boolean();
+ test_set_integer();
+ test_noset_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_bool_int_string)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_set_boolean();
+ test_set_integer();
+ test_noset_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_number_string)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_noset_boolean();
+ test_noset_integer();
+ test_set_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_bool_number_string)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_set_boolean();
+ test_noset_integer();
+ test_set_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_int_number_string)
+{
+ lua_createtable(L, 0, 0);
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_noset_boolean();
+ test_set_integer();
+ test_set_number();
+ test_set_string();
+
+ return 0;
+}
+TEST(process_all)
+{
+ lua_createtable(L, 0, 0);
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "boolean");
+
+ lua_pushinteger(L, 14);
+ lua_setfield(L, -2, "integer");
+
+ lua_pushnumber(L, 44.66);
+ lua_setfield(L, -2, "number");
+
+ lua_pushstring(L, "c: c: c:");
+ lua_setfield(L, -2, "string");
+
+ process();
+
+ test_set_boolean();
+ test_set_integer();
+ test_set_number();
+ test_set_string();
+
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for four keys of the same type
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(process_four_bools)
+{
+ lua_createtable(L, 0, 4);
+
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "b1");
+
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "b2");
+
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "b3");
+
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "b4");
+
+ bool b1 = false;
+ bool b2 = true;
+ bool b3 = true;
+ bool b4 = false;
+
+ hs_process_table(L, -1,
+ hs_process_bool("b1", hs_pt_set_boolean, &b1),
+ hs_process_bool("b2", hs_pt_set_boolean, &b2),
+ hs_process_bool("b3", hs_pt_set_boolean, &b3),
+ hs_process_bool("b4", hs_pt_set_boolean, &b4),
+ );
+
+ mu_assert("b1 was not correctly set!", b1 == true);
+ mu_assert("b2 was not correctly set!", b2 == false);
+ mu_assert("b3 was not correctly set!", b3 == false);
+ mu_assert("b4 was not correctly set!", b4 == true);
+ return 0;
+}
+TEST(process_four_ints)
+{
+ lua_createtable(L, 0, 4);
+
+ lua_pushinteger(L, 2);
+ lua_setfield(L, -2, "j1");
+
+ lua_pushinteger(L, 1);
+ lua_setfield(L, -2, "j2");
+
+ lua_pushinteger(L, 3);
+ lua_setfield(L, -2, "j3");
+
+ lua_pushinteger(L, 4);
+ lua_setfield(L, -2, "j4");
+
+ lua_Integer j1 = 0;
+ lua_Integer j2 = 0;
+ lua_Integer j3 = 0;
+ lua_Integer j4 = 0;
+
+ hs_process_table(L, -1,
+ hs_process_int("j1", hs_pt_set_integer, &j1),
+ hs_process_int("j2", hs_pt_set_integer, &j2),
+ hs_process_int("j3", hs_pt_set_integer, &j3),
+ hs_process_int("j4", hs_pt_set_integer, &j4));
+
+ mu_assert("j1 was not correctly set!", j1 == 2);
+ mu_assert("j2 was not correctly set!", j2 == 1);
+ mu_assert("j3 was not correctly set!", j3 == 3);
+ mu_assert("j4 was not correctly set!", j4 == 4);
+ return 0;
+}
+TEST(process_four_numbers)
+{
+ lua_createtable(L, 0, 4);
+
+ lua_pushnumber(L, 3.141);
+ lua_setfield(L, -2, "n1");
+
+ lua_pushnumber(L, 2.718);
+ lua_setfield(L, -2, "n2");
+
+ lua_pushnumber(L, 1.618);
+ lua_setfield(L, -2, "n3");
+
+ lua_pushnumber(L, 4.669);
+ lua_setfield(L, -2, "n4");
+
+ lua_Number n1 = 0;
+ lua_Number n2 = 0;
+ lua_Number n3 = 0;
+ lua_Number n4 = 0;
+
+ hs_process_table(L, -1,
+ hs_process_num("n1", hs_pt_set_number, &n1),
+ hs_process_num("n2", hs_pt_set_number, &n2),
+ hs_process_num("n3", hs_pt_set_number, &n3),
+ hs_process_num("n4", hs_pt_set_number, &n4));
+
+ mu_assert("n1 was not correctly set!", n1 == 3.141);
+ mu_assert("n2 was not correctly set!", n2 == 2.718);
+ mu_assert("n3 was not correctly set!", n3 == 1.618);
+ mu_assert("n4 was not correctly set!", n4 == 4.669);
+ return 0;
+}
+TEST(process_four_strings)
+{
+ lua_createtable(L, 0, 4);
+
+ lua_pushstring(L, "When meditation is mastered, The mind is unwavering like the Flame of a lamp in a windless place." );
+ lua_setfield(L, -2, "s1");
+
+ lua_pushstring(L, "In the still mind, In the depths of meditation, The Self reveals itself.");
+ lua_setfield(L, -2, "s2");
+
+ lua_pushstring(L, "Beholding the Self By means of the Self, An aspirant knows the Joy and peace of complete fulfillment.");
+ lua_setfield(L, -2, "s3");
+
+ lua_pushstring(L, "Having attained that Abiding joy beyond the senses, Revealed in the stilled mind, He never swerves from the eternal truth.");
+ lua_setfield(L, -2, "s4");
+
+ const char *s1 = "";
+ const char *s2 = "";
+ const char *s3 = "";
+ const char *s4 = "";
+
+ hs_process_table(L, -1,
+ hs_process_str("s1", hs_pt_set_string, &s1),
+ hs_process_str("s2", hs_pt_set_string, &s2),
+ hs_process_str("s3", hs_pt_set_string, &s3),
+ hs_process_str("s4", hs_pt_set_string, &s4));
+
+ mu_assert("s1 was not correctly set!",
+ strcmp(s1, "When meditation is mastered, The mind is unwavering like the Flame of a lamp in a windless place.") == 0);
+ mu_assert("s2 was not correctly set!",
+ strcmp(s2, "In the still mind, In the depths of meditation, The Self reveals itself.") == 0);
+ mu_assert("s3 was not correctly set!",
+ strcmp(s3, "Beholding the Self By means of the Self, An aspirant knows the Joy and peace of complete fulfillment.") == 0);
+ mu_assert("s4 was not correctly set!",
+ strcmp(s4, "Having attained that Abiding joy beyond the senses, Revealed in the stilled mind, He never swerves from the eternal truth.") == 0);
+ return 0;
+}
+
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * test suite
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+void hs_process_table_tests()
+{
+ printf("running hs_process_table() tests...\n");
+
+ mu_run_test("process empty table", process_none);
+ mu_run_test("process boolean only", process_bool);
+ mu_run_test("process integer only", process_int);
+ mu_run_test("process boolean and integer", process_bool_int);
+ mu_run_test("process number only", process_number);
+ mu_run_test("process boolean and number", process_bool_number);
+ mu_run_test("process integer and number", process_int_number);
+ mu_run_test("process boolean, integer, and number", process_bool_int_number);
+
+ mu_run_test("process string only", process_string);
+ mu_run_test("process boolean and string", process_bool_string);
+ mu_run_test("process integer and string", process_int_string);
+ mu_run_test("process boolean, integer, and string", process_bool_int_string);
+ mu_run_test("process number and string", process_number_string);
+ mu_run_test("process boolean, number, and string", process_bool_number_string);
+ mu_run_test("process integer, number, and string", process_int_number_string);
+ mu_run_test("process basic types", process_all);
+
+ mu_run_test("process four booleans", process_four_bools);
+ mu_run_test("process four integers", process_four_ints);
+ mu_run_test("process four numbers", process_four_numbers);
+ mu_run_test("process four strings", process_four_strings);
+}
diff --git a/libs/honeysuckle/src/tests/hs_pushstring_tests.c b/libs/honeysuckle/src/tests/hs_pushstring_tests.c
new file mode 100644
index 0000000..e7fa1b4
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_pushstring_tests.c
@@ -0,0 +1,52 @@
+#include "hs_tests.h"
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for hs_pushstring
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(push_noformat)
+{
+ hs_pushstring(L, "a string");
+ mu_assert("no string at top of stack!", lua_isstring(L, -1));
+ const char *string = lua_tostring(L, -1);
+ mu_assert("string != 'a string'", strcmp(string, "a string") == 0);
+ return 0;
+}
+
+TEST(push_formatint)
+{
+ hs_pushstring(L, "%d is 5", 5);
+ mu_assert("no string at top of stack!", lua_isstring(L, -1));
+ const char *string = lua_tostring(L, -1);
+ mu_assert("string != '5 is 5'", strcmp(string, "5 is 5") == 0);
+ return 0;
+}
+
+TEST(push_formatstring)
+{
+ hs_pushstring(L, "%s is 'hello'", "hello");
+ mu_assert("no string at top of stack!", lua_isstring(L, -1));
+ const char *string = lua_tostring(L, -1);
+ mu_assert("string != 'hello is 'hello''",
+ strcmp(string, "hello is 'hello'") == 0);
+ return 0;
+}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * test suite
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+void hs_pushstring_tests()
+{
+ printf("running hs_pushstring() tests...\n");
+ mu_run_test("hs_pushstring (no printf formatting)", push_noformat);
+ mu_run_test("hs_pushstring (integer formatting)", push_formatint);
+ mu_run_test("hs_pushstring (string formatting)", push_formatstring);
+}
diff --git a/libs/honeysuckle/src/tests/hs_tests.h b/libs/honeysuckle/src/tests/hs_tests.h
new file mode 100644
index 0000000..15f2cb6
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_tests.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+#include "../honeysuckle.h"
+#include "colors.h"
+
+#define STR_IMPL(x) #x
+#define STR(x) STR_IMPL(x)
+
+#define mu_indent " "
+
+/* minunit testing macros modified from those at
+ www.jera.com/techinfo/jtns/jtn002.html */
+#define mu_assert(message, test) do { \
+ if (!(test)) return message \
+ "\n" mu_indent MAGENTA " [" __FILE__ ":" STR(__LINE__) "]" RESET; \
+ } while (0)
+#define mu_assert_equal(a, b) mu_assert("'" #a "' is not equal to '" #b "'", (a) == (b))
+#define mu_assert_not_equal(a, b) mu_assert("'" #a "' is equal to '" #b "'", (a) != (b))
+#define mu_assert_str_equal(a, b) \
+ mu_assert("'" #a "' is not equal to '" #b "'", strcmp((a), (b)) == 0)
+#define mu_assert_str_not_equal(a, b) \
+ mu_assert("'" #a "' is equal to '" #b "'", strcmp((a), (b)) != 0)
+
+#define mu_run_test(name, test) do { \
+ lua_State *L = luaL_newstate(); \
+ luaL_openlibs(L); \
+ const char *message = test(L); \
+ lua_close(L); \
+ tests_run++; \
+ if (message) { \
+ printf(RED mu_indent "test '%s' failed:" RESET " %s\n", name, message); \
+ tests_failed++; \
+ } \
+ } while (0)
+#define TEST(name) static const char* name(lua_State *L)
+#define mu_run_suite(suite) do { \
+ tests_run_old = tests_run; \
+ suite(); \
+ printf(mu_indent "ran %d tests\n", tests_run - tests_run_old); \
+ } while (0)
+
+extern int tests_run, tests_run_old, tests_failed;
+
+void hs_type_to_string_tests();
+void hs_parse_args_tests();
+void hs_parse_overloaded_tests();
+void hs_create_table_tests();
+void hs_create_enum_tests();
+void hs_process_table_tests();
+void hs_throw_error_tests();
+void hs_traceback_tests();
+void hs_call_tests();
+void hs_call_args_tests();
+void hs_pushstring_tests();
+void hs_rxx_tests();
diff --git a/libs/honeysuckle/src/tests/hs_throw_error_tests.c b/libs/honeysuckle/src/tests/hs_throw_error_tests.c
new file mode 100644
index 0000000..7ae683c
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_throw_error_tests.c
@@ -0,0 +1,57 @@
+#include "hs_tests.h"
+
+char err_string[32] = "";
+
+int set_err_string(lua_State *L)
+{
+ if (lua_isstring(L, -1))
+ strcpy(err_string, lua_tostring(L, -1));
+ return 0;
+}
+
+
+#define HS_ERROR_TEST(name, error_body, expectation) \
+ int name ## _errfunc(lua_State *L) error_body; \
+ TEST(name) { \
+ lua_pushcfunction(L, set_err_string); \
+ int pos = lua_gettop(L); \
+ lua_pushcfunction(L, name ## _errfunc); \
+ int result = lua_pcall(L, 0, 0, pos); \
+ mu_assert_equal(result, LUA_ERRRUN); \
+ mu_assert_str_not_equal(err_string, ""); \
+ mu_assert_str_equal(err_string, expectation); \
+ return 0; \
+ }
+
+
+HS_ERROR_TEST(hs_throw_error_constant, {
+ hs_throw_error(L, "a constant error");
+ return 0;
+ }, "a constant error");
+
+
+HS_ERROR_TEST(hs_throw_error_format, {
+ hs_throw_error(L, "%s number %d", "error", 10);
+ return 0;
+ }, "error number 10");
+
+
+HS_ERROR_TEST(hs_throw_error_long, {
+ hs_throw_error(L, "%s is a %s is a %s",
+ "a very, very, very long string",
+ "a very, very, very long string",
+ "a very, very, very long string");
+ return 0;
+ }, "a very, very, very long string is a a very, very, very long string is a a very, very, very long string");
+
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+void hs_throw_error_tests()
+{
+ printf("running hs_throw_error() tests...\n");
+
+ mu_run_test("throw constant error string", hs_throw_error_constant);
+ mu_run_test("throw error with format string", hs_throw_error_format);
+ mu_run_test("throw error with very long string", hs_throw_error_long);
+}
diff --git a/libs/honeysuckle/src/tests/hs_type_to_string_tests.c b/libs/honeysuckle/src/tests/hs_type_to_string_tests.c
new file mode 100644
index 0000000..3b158ab
--- /dev/null
+++ b/libs/honeysuckle/src/tests/hs_type_to_string_tests.c
@@ -0,0 +1,102 @@
+#include "hs_tests.h"
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for hs_type_to_string
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+TEST(hs_bool_to_string)
+{
+ mu_assert("HS_BOOL does not result in 'boolean'!",
+ strcmp(hs_type_to_string(HS_BOOL), "boolean") == 0);
+ return 0;
+}
+
+TEST(hs_int_to_string)
+{
+ mu_assert("HS_INT does not result in 'integer'!",
+ strcmp(hs_type_to_string(HS_INT), "integer") == 0);
+ return 0;
+}
+
+TEST(hs_num_to_string)
+{
+ mu_assert("HS_NUM does not result in 'number'!",
+ strcmp(hs_type_to_string(HS_NUM), "number") == 0);
+ return 0;
+}
+
+TEST(hs_str_to_string)
+{
+ mu_assert("HS_STR does not result in 'string'!",
+ strcmp(hs_type_to_string(HS_STR), "string") == 0);
+ return 0;
+}
+
+TEST(hs_tbl_to_string)
+{
+ mu_assert("HS_TBL does not result in 'table'!",
+ strcmp(hs_type_to_string(HS_TBL), "table") == 0);
+ return 0;
+}
+
+TEST(hs_func_to_string)
+{
+ mu_assert("HS_FUNC does not result in 'function'!",
+ strcmp(hs_type_to_string(HS_FUNC), "function") == 0);
+ return 0;
+}
+
+TEST(hs_cfunc_to_string)
+{
+ mu_assert("HS_CFUNC does not result in 'C function'!",
+ strcmp(hs_type_to_string(HS_CFUNC), "C function") == 0);
+ return 0;
+}
+
+TEST(hs_user_to_string)
+{
+ mu_assert("HS_USER does not result in 'userdata'!",
+ strcmp(hs_type_to_string(HS_USER), "userdata") == 0);
+ return 0;
+}
+
+TEST(hs_light_to_string)
+{
+ mu_assert("HS_LIGHT does not result in 'light userdata'!",
+ strcmp(hs_type_to_string(HS_LIGHT), "light userdata") == 0);
+ return 0;
+}
+
+TEST(hs_nil_to_string)
+{
+ mu_assert("HS_NIL does not result in 'nil'!",
+ strcmp(hs_type_to_string(HS_NIL), "nil") == 0);
+ return 0;
+}
+
+TEST(hs_any_to_string)
+{
+ mu_assert("HS_ANY does not result in 'any'!",
+ strcmp(hs_type_to_string(HS_ANY), "any") == 0);
+ return 0;
+}
+
+
+void hs_type_to_string_tests()
+{
+ printf("running hs_type_to_string() tests...\n");
+ mu_run_test("bool to string", hs_bool_to_string);
+ mu_run_test("int to string", hs_int_to_string);
+ mu_run_test("num to string", hs_num_to_string);
+ mu_run_test("str to string", hs_str_to_string);
+ mu_run_test("tbl to string", hs_tbl_to_string);
+ mu_run_test("func to string", hs_func_to_string);
+ mu_run_test("cfunc to string", hs_cfunc_to_string);
+ mu_run_test("user to string", hs_user_to_string);
+ mu_run_test("light to string", hs_light_to_string);
+ mu_run_test("nil to string", hs_nil_to_string);
+ mu_run_test("any to string", hs_any_to_string);
+}
diff --git a/libs/honeysuckle/src/tests/tests_main.c b/libs/honeysuckle/src/tests/tests_main.c
new file mode 100644
index 0000000..26af7cc
--- /dev/null
+++ b/libs/honeysuckle/src/tests/tests_main.c
@@ -0,0 +1,33 @@
+#include "hs_tests.h"
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * RUN TESTS
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+int tests_run = 0;
+int tests_run_old = 0;
+int tests_failed = 0;
+
+int main()
+{
+ printf("================ start tests ================\n\n");
+
+ mu_run_suite(hs_type_to_string_tests);
+ mu_run_suite(hs_parse_args_tests);
+ mu_run_suite(hs_parse_overloaded_tests);
+ mu_run_suite(hs_create_table_tests);
+ //mu_run_suite(hs_create_enum_tests);
+ mu_run_suite(hs_process_table_tests);
+ mu_run_suite(hs_throw_error_tests);
+
+ mu_run_suite(hs_pushstring_tests);
+
+ printf("\n=============== tests finished ===============\n\n");
+
+ const char *color = tests_failed == 0 ? GREEN : RED;
+ printf("%sran %d tests, %d failed\n" RESET, color, tests_run, tests_failed);
+ return tests_failed;
+}