1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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);
}
|