From a02326f48e1afc823b3a2fdddc50982a5ec9598d Mon Sep 17 00:00:00 2001 From: sanine-a Date: Thu, 27 May 2021 21:38:39 -0500 Subject: add readme example test for hs_parse_args --- src/test.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test.c b/src/test.c index 9d202cc..ff4dd80 100644 --- a/src/test.c +++ b/src/test.c @@ -634,6 +634,30 @@ TEST(parse_all) return 0; } +TEST(parse_readme_example) +{ + lua_pushboolean(L, true); + lua_pushinteger(L, 7); + lua_getglobal(L, "debug"); + int expected = lua_gettop(L); + lua_pushnumber(L, 3.1415f); + lua_pushstring(L, "c: c: c:"); + void *userdata = lua_newuserdata(L, sizeof(char)); + + 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); + + mu_assert("failed to properly parse boolean!", b); + mu_assert("failed to properly parse integer!", i == 7); + mu_assert("failed to properly parse table!", table_index == expected); + mu_assert("failed to properly parse number!", f == 3.1415f); + mu_assert("failed to properly parse string!", strcmp(str, "c: c: c:") == 0); + mu_assert("failed to properly parse userdata!", user == userdata); + return 0; +} + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * @@ -834,6 +858,7 @@ int main() 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); printf("running hs_parse_overloaded() parsing tests...\n"); mu_run_test("parse bool overloaded", parse_bool_overloaded); -- cgit v1.2.1