summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--src/honeysuckle.c6
-rw-r--r--src/test.c99
3 files changed, 106 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4dcfccd..2e02378 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,13 +3,12 @@ project(honeysuckle
VERSION 1.0.0
DESCRIPTION "A C library to make writing lua bindings simple")
-set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wpedantic")
-
find_package(Lua51 REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
# build and link the library
add_library(honeysuckle src/honeysuckle.c)
+set_target_properties(honeysuckle PROPERTIES CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wpedantic")
target_link_libraries(honeysuckle ${LUA_LIBRARIES})
set_target_properties(honeysuckle PROPERTIES
VERSION ${PROJECT_VERSION}
diff --git a/src/honeysuckle.c b/src/honeysuckle.c
index 423fa1b..2e2a12f 100644
--- a/src/honeysuckle.c
+++ b/src/honeysuckle.c
@@ -1,5 +1,11 @@
#include "honeysuckle.h"
+const char* hs_type_to_string(int type)
+{
+ type = type;
+ return "mock";
+}
+
void hs_pushstring(lua_State *L, const char *format_string, ...)
{
lua_pushnumber(L, 0.4);
diff --git a/src/test.c b/src/test.c
index 5a74414..f52fa99 100644
--- a/src/test.c
+++ b/src/test.c
@@ -25,6 +25,90 @@
int tests_run = 0;
int tests_failed = 0;
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for hs_type_to_string
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+static char* hs_bool_to_string(lua_State *L)
+{
+ mu_assert("HS_BOOL does not result in 'boolean'!",
+ strcmp(hs_type_to_string(HS_BOOL), "boolean") == 0);
+ return 0;
+}
+
+static char* hs_int_to_string(lua_State *L)
+{
+ mu_assert("HS_INT does not result in 'integer'!",
+ strcmp(hs_type_to_string(HS_INT), "integer") == 0);
+ return 0;
+}
+
+static char* hs_num_to_string(lua_State *L)
+{
+ mu_assert("HS_NUM does not result in 'number'!",
+ strcmp(hs_type_to_string(HS_NUM), "number") == 0);
+ return 0;
+}
+
+static char* hs_str_to_string(lua_State *L)
+{
+ mu_assert("HS_STR does not result in 'string'!",
+ strcmp(hs_type_to_string(HS_STR), "string") == 0);
+ return 0;
+}
+
+static char* hs_tbl_to_string(lua_State *L)
+{
+ mu_assert("HS_TBL does not result in 'table'!",
+ strcmp(hs_type_to_string(HS_TBL), "table") == 0);
+ return 0;
+}
+
+static char* hs_func_to_string(lua_State *L)
+{
+ mu_assert("HS_FUNC does not result in 'function'!",
+ strcmp(hs_type_to_string(HS_FUNC), "function") == 0);
+ return 0;
+}
+
+static char* hs_cfunc_to_string(lua_State *L)
+{
+ mu_assert("HS_CFUNC does not result in 'C function'!",
+ strcmp(hs_type_to_string(HS_CFUNC), "C function") == 0);
+ return 0;
+}
+
+static char* hs_user_to_string(lua_State *L)
+{
+ mu_assert("HS_USER does not result in 'userdata'!",
+ strcmp(hs_type_to_string(HS_USER), "userdata") == 0);
+ return 0;
+}
+
+static char* hs_light_to_string(lua_State *L)
+{
+ mu_assert("HS_LIGHT does not result in 'light userdata'!",
+ strcmp(hs_type_to_string(HS_LIGHT), "light userdata") == 0);
+ return 0;
+}
+
+static char* hs_nil_to_string(lua_State *L)
+{
+ mu_assert("HS_NIL does not result in 'nil'!",
+ strcmp(hs_type_to_string(HS_NIL), "nil") == 0);
+ return 0;
+}
+
+static char* hs_any_to_string(lua_State *L)
+{
+ mu_assert("HS_ANY does not result in 'any'!",
+ strcmp(hs_type_to_string(HS_ANY), "any") == 0);
+ return 0;
+}
+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
@@ -71,10 +155,25 @@ static char* push_formatstring(lua_State *L)
int main()
{
printf("================ start tests ================\n\n");
+
+ 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);
+
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);
+
printf("\n=============== tests finished ===============\n\n");
printf("ran %d tests, %d failed\n", tests_run, tests_failed);
return 0;