summaryrefslogtreecommitdiff
path: root/src/tests/hs_parse_overloaded_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/hs_parse_overloaded_tests.c')
-rw-r--r--src/tests/hs_parse_overloaded_tests.c212
1 files changed, 109 insertions, 103 deletions
diff --git a/src/tests/hs_parse_overloaded_tests.c b/src/tests/hs_parse_overloaded_tests.c
index 812aab5..784807a 100644
--- a/src/tests/hs_parse_overloaded_tests.c
+++ b/src/tests/hs_parse_overloaded_tests.c
@@ -9,143 +9,149 @@ static int testfunc(lua_State *L) { return 0; }
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
-#define PARSE_OVERLOADED \
- bool b; int i, ti, fi, ni; float f; char *str; \
- lua_CFunction fn; void *user, *light; \
- int choice = hs_parse_overloaded \
- (L, \
- HS_BOOL, &b, HS_END, HS_INT, &i, HS_END, HS_NUM, &f, HS_END, \
- HS_STR, &str, HS_END, HS_TBL, &ti, HS_END, HS_FUNC, &fi, \
- HS_END, HS_CFUNC, &fn, HS_END, HS_USER, &user, HS_END, \
- HS_LIGHT, &light, HS_END, HS_NIL, &ni, HS_END, HS_END);
+#define PARSE_OVERLOADED \
+ bool b; long int i; int ti, fi, ni; double 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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)
{
- lua_getglobal(L, "type");
- 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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");
- int i; char *str; void *data;
- int choice = hs_parse_overloaded
- (L, HS_INT, &i, HS_STR, &str, HS_END,
- HS_INT, &i, HS_STR, &str, HS_USER, &data, HS_END,
- HS_END);
-
- 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;
+ lua_pushinteger(L, 69);
+ lua_pushstring(L, "foo");
+ long int 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));
- int i; char *str; void *data;
- int choice = hs_parse_overloaded
- (L, HS_INT, &i, HS_STR, &str, HS_END,
- HS_INT, &i, HS_STR, &str, HS_USER, &data, HS_END,
- HS_END);
-
- 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;
+ lua_pushinteger(L, 69);
+ lua_pushstring(L, "foo");
+ void *userdata = lua_newuserdata(L, sizeof(char));
+ long int 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;
}
@@ -158,17 +164,17 @@ TEST(parse_2_3_overload_1)
void hs_parse_overloaded_tests()
{
- 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);
+ 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);
}