diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/test.c | 69 | 
1 files changed, 60 insertions, 9 deletions
@@ -127,11 +127,6 @@ TEST(hs_any_to_string)      return 0;							\      }								\      TEST(name) -#define PARSE_TYPECHECK_TEST_NOVAL(name, constant)		\ -    int name ## _testfunc(lua_State *L) {			\ -	hs_parse_args(L, constant, HS_END); return 0;		\ -    }								\ -    TEST(name)  #define CHECK_FAIL_BOOL(name)						\      lua_pushcfunction(L, name ## _testfunc); lua_pushboolean(L, true);	\ @@ -264,7 +259,7 @@ PARSE_TYPECHECK_TEST(parse_string_typecheck, char *, HS_STR)      return 0;  } -PARSE_TYPECHECK_TEST_NOVAL(parse_table_typecheck, HS_TBL) +PARSE_TYPECHECK_TEST(parse_table_typecheck, int, HS_TBL)  {      CHECK_FAIL_BOOL(parse_table_typecheck);      CHECK_FAIL_INT(parse_table_typecheck); @@ -284,7 +279,7 @@ PARSE_TYPECHECK_TEST_NOVAL(parse_table_typecheck, HS_TBL)      return 0;  } -PARSE_TYPECHECK_TEST_NOVAL(parse_func_typecheck, HS_FUNC) +PARSE_TYPECHECK_TEST(parse_func_typecheck, int, HS_FUNC)  {      CHECK_FAIL_BOOL(parse_func_typecheck);      CHECK_FAIL_INT(parse_func_typecheck); @@ -368,7 +363,7 @@ PARSE_TYPECHECK_TEST(parse_light_typecheck, void *, HS_LIGHT)      return 0;  } -PARSE_TYPECHECK_TEST_NOVAL(parse_nil_typecheck, HS_NIL) +PARSE_TYPECHECK_TEST(parse_nil_typecheck, int, HS_NIL)  {      CHECK_FAIL_BOOL(parse_nil_typecheck);      CHECK_FAIL_INT(parse_nil_typecheck); @@ -388,6 +383,61 @@ PARSE_TYPECHECK_TEST_NOVAL(parse_nil_typecheck, HS_NIL)      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); +    lua_getglobal(L, "test"); +    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; +} +  TEST(parse_bool)  {      lua_pushboolean(L, true); @@ -565,7 +615,8 @@ int main()      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 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);  | 
