diff options
author | sanine-a <sanine.not@pm.me> | 2021-07-02 22:02:06 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2021-07-02 22:02:06 -0500 |
commit | 6416977ea7e2159a67fd6a9877c5e01abe2f8269 (patch) | |
tree | 84941ea147ade3eb3545048d6b7cf68b5ee29e0d /src/tests/hs_pushstring_tests.c | |
parent | 8c66847bfc4a6af1ca86e916b678a6b8ce58be2f (diff) |
begin refactor of tests into individual source files
Diffstat (limited to 'src/tests/hs_pushstring_tests.c')
-rw-r--r-- | src/tests/hs_pushstring_tests.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/tests/hs_pushstring_tests.c b/src/tests/hs_pushstring_tests.c new file mode 100644 index 0000000..e7fa1b4 --- /dev/null +++ b/src/tests/hs_pushstring_tests.c @@ -0,0 +1,52 @@ +#include "hs_tests.h" + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * tests for hs_pushstring + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +TEST(push_noformat) +{ + hs_pushstring(L, "a string"); + mu_assert("no string at top of stack!", lua_isstring(L, -1)); + const char *string = lua_tostring(L, -1); + mu_assert("string != 'a string'", strcmp(string, "a string") == 0); + return 0; +} + +TEST(push_formatint) +{ + hs_pushstring(L, "%d is 5", 5); + mu_assert("no string at top of stack!", lua_isstring(L, -1)); + const char *string = lua_tostring(L, -1); + mu_assert("string != '5 is 5'", strcmp(string, "5 is 5") == 0); + return 0; +} + +TEST(push_formatstring) +{ + hs_pushstring(L, "%s is 'hello'", "hello"); + mu_assert("no string at top of stack!", lua_isstring(L, -1)); + const char *string = lua_tostring(L, -1); + mu_assert("string != 'hello is 'hello''", + strcmp(string, "hello is 'hello'") == 0); + return 0; +} + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * test suite + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +void hs_pushstring_tests() +{ + printf("running hs_pushstring() tests...\n"); + mu_run_test("hs_pushstring (no printf formatting)", push_noformat); + mu_run_test("hs_pushstring (integer formatting)", push_formatint); + mu_run_test("hs_pushstring (string formatting)", push_formatstring); +} |