summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-08-24 16:54:33 -0500
committersanine <sanine.not@pm.me>2021-08-24 16:54:33 -0500
commit9149147708e7a74a1276835a2dbecc4d7fa1a3bb (patch)
treee79b7493792765508716703ca9a7e9d803cbd1f3
parent9782f9ff35b1fdfa67438ea620bd7c91497781a3 (diff)
fix hs_parse_arg string handling and function test
-rw-r--r--src/hs_parse_args.c2
-rw-r--r--src/tests/hs_parse_args_tests.c20
2 files changed, 13 insertions, 9 deletions
diff --git a/src/hs_parse_args.c b/src/hs_parse_args.c
index eee34e9..5a14bd0 100644
--- a/src/hs_parse_args.c
+++ b/src/hs_parse_args.c
@@ -24,7 +24,7 @@ static bool check_parse(lua_State *L, int index, struct hs_arg *expected)
return true;
case HS_STR:
- if (!lua_isstring(L, index))
+ if (!lua_isstring(L, index) || lua_isnumber(L, index))
return false;
*(expected->ptr.string) = (char *) lua_tostring(L, index);
return true;
diff --git a/src/tests/hs_parse_args_tests.c b/src/tests/hs_parse_args_tests.c
index 39c40fb..a6aa475 100644
--- a/src/tests/hs_parse_args_tests.c
+++ b/src/tests/hs_parse_args_tests.c
@@ -48,7 +48,7 @@ static int testfunc(lua_State *L) { return 0; }
lua_pop(L, 1);
#define CHECK_FAIL_FUNC(name) \
- lua_pushcfunction(L, name ## _testfunc); lua_getglobal(L, "test"); \
+ lua_pushcfunction(L, name ## _testfunc); lua_getglobal(L, "print"); \
mu_assert("incorrectly succeeded in parsing function!", \
lua_pcall(L, 1, 0, 0) != 0); \
lua_pop(L, 1);
@@ -191,11 +191,15 @@ PARSE_TYPECHECK_TEST(parse_func_typecheck, int, hs_func)
CHECK_FAIL_TABLE(parse_func_typecheck);
lua_pushcfunction(L, parse_func_typecheck_testfunc);
- lua_getglobal(L, "test");
+ lua_getglobal(L, "print");
mu_assert("typecheck for function failed!",
lua_pcall(L, 1, 0, 0) == 0);
- CHECK_FAIL_CFUNC(parse_func_typecheck);
+ 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);
@@ -534,7 +538,7 @@ TEST(parse_all)
return 0;
}
-/*TEST(parse_readme_example)
+TEST(parse_readme_example)
{
lua_pushboolean(L, true);
lua_pushinteger(L, 7);
@@ -546,8 +550,8 @@ TEST(parse_all)
bool b; int i; int table_index; float 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, HS_END);
+ (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);
@@ -556,7 +560,7 @@ TEST(parse_all)
mu_assert("failed to properly parse string!", strcmp(str, "c: c: c:") == 0);
mu_assert("failed to properly parse userdata!", user == userdata);
return 0;
- }*/
+}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
@@ -594,5 +598,5 @@ void hs_parse_args_tests()
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);
+ mu_run_test("parse readme example", parse_readme_example);
}