summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2021-05-23 16:47:59 -0500
committersanine-a <sanine.not@pm.me>2021-05-23 16:47:59 -0500
commite06165088c13cd31819a7b1bb1a2ba9e5aaf689e (patch)
treea1772bfb552202af710bddc0ebf5231376c845e4 /src
parent4dc4d9f1d20a73d1e4c399a56c86bf70589b13d9 (diff)
create initial files and write three hs_pushstring() tests
Diffstat (limited to 'src')
-rw-r--r--src/honeysuckle.c7
-rw-r--r--src/honeysuckle.h27
-rw-r--r--src/test.c80
3 files changed, 114 insertions, 0 deletions
diff --git a/src/honeysuckle.c b/src/honeysuckle.c
new file mode 100644
index 0000000..423fa1b
--- /dev/null
+++ b/src/honeysuckle.c
@@ -0,0 +1,7 @@
+#include "honeysuckle.h"
+
+void hs_pushstring(lua_State *L, const char *format_string, ...)
+{
+ lua_pushnumber(L, 0.4);
+ format_string = format_string;
+}
diff --git a/src/honeysuckle.h b/src/honeysuckle.h
new file mode 100644
index 0000000..7538791
--- /dev/null
+++ b/src/honeysuckle.h
@@ -0,0 +1,27 @@
+#ifndef HONEYSUCKLE_H
+#define HONEYSUCKLE_H
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+
+#define HS_END 0
+
+/* type constants */
+#define HS_BOOL 1
+#define HS_INT 2
+#define HS_NUM 3
+#define HS_STR 4
+#define HS_TBL 5
+#define HS_FUNC 6
+#define HS_CFUNC 7
+#define HS_USER 8
+#define HS_LIGHT 9
+#define HS_NIL 10
+#define HS_ANY 11
+
+
+void hs_pushstring(lua_State *L, const char *format_string, ...);
+
+#endif
diff --git a/src/test.c b/src/test.c
new file mode 100644
index 0000000..5275d4d
--- /dev/null
+++ b/src/test.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+#include "honeysuckle.h"
+
+/* minunit testing macros modified from those at www.jera.com/techinfo/jtns/jtn002.html */
+#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
+#define mu_run_test(name, test) do { \
+ lua_State *L = luaL_newstate(); \
+ luaL_openlibs(L); \
+ char *message = test(L); \
+ lua_close(L); \
+ tests_run++; \
+ if (message) { \
+ printf("test '%s' failed: %s\n", name, message); \
+ tests_failed++; \
+ } \
+ } while (0)
+
+int tests_run = 0;
+int tests_failed = 0;
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * tests for hs_pushstring
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+static char* push_noformat(lua_State *L)
+{
+ 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;
+}
+
+static char* push_formatint(lua_State *L)
+{
+ 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;
+}
+
+static char* push_formatstring(lua_State *L)
+{
+ 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;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * RUN TESTS
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+int main()
+{
+ printf("================ start tests ================\n\n");
+ 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);
+ printf("\n=============== tests finished ===============\n\n");
+ printf("ran %d tests, %d failed\n", tests_run, tests_failed);
+ return 0;
+}