diff options
author | sanine-a <sanine.not@pm.me> | 2021-05-27 21:38:39 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2021-05-27 21:38:39 -0500 |
commit | a02326f48e1afc823b3a2fdddc50982a5ec9598d (patch) | |
tree | ae2256dd2d40bc8d1fa8d757685e9ef0f6646270 /src | |
parent | 8f2b1bb21725d5d228ac8b506cffd739336b36e5 (diff) |
add readme example test for hs_parse_args
Diffstat (limited to 'src')
-rw-r--r-- | src/test.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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); |