summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/honeysuckle.h1
-rw-r--r--src/test.c84
2 files changed, 83 insertions, 2 deletions
diff --git a/src/honeysuckle.h b/src/honeysuckle.h
index b996aed..43e5f51 100644
--- a/src/honeysuckle.h
+++ b/src/honeysuckle.h
@@ -23,7 +23,6 @@
const char* hs_type_to_string(int type);
void hs_parse_args(lua_State *L, ...);
-void hs_parse_args_fast(lua_State *L, ...);
int hs_parse_overloaded(lua_State *L, ...);
int hs_create_table(lua_State *L, ...);
diff --git a/src/test.c b/src/test.c
index 8bb31c0..63dc637 100644
--- a/src/test.c
+++ b/src/test.c
@@ -484,6 +484,16 @@ TEST(parse_str)
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, HS_END);
+ mu_assert("failed to properly parse table!", tbl_index == correct_index);
+ return 0;
+}
+
TEST(parse_func)
{
lua_getglobal(L, "type");
@@ -554,6 +564,75 @@ TEST(parse_nil)
return 0;
}
+TEST(parse_any)
+{
+ lua_pushnil(L);
+ int correct_index = lua_gettop(L);
+ int index = 0;
+ hs_parse_args(L, HS_ANY, &index, HS_END);
+ 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;
+ int i;
+ float 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,
+ HS_END);
+ 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;
+}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
@@ -632,12 +711,15 @@ int main()
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 nil", parse_nil);
+ mu_run_test("parse any", parse_any);
+ mu_run_test("parse all", parse_all);
printf("running hs_pushstring() tests...\n");
mu_run_test("hs_pushstring (no printf formatting)", push_noformat);