Commit: 750ff1000ec72f4797d48a4de5a11f7e4a1ee416
Parent: 40937aa3f7a2b6f9175480bdb5df5541fc13bf5b
Author: Randy Palamar
Date: Tue, 29 Oct 2024 07:48:33 -0600
test: remove string.h usage
Diffstat:
M | test.c | | | 30 | ++++++++++++++++++++---------- |
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/test.c b/test.c
@@ -1,5 +1,3 @@
-#include <string.h> /* memcmp */
-
#define GLFW_PRESS 1
#define GLFW_REPEAT 2
@@ -46,11 +44,17 @@ get_gpu_glyph_index(Arena a, void *b, void *c, u32 cp, u32 d, u32 e, CachedGlyph
*cg = &scg;
}
-#define ESC(a) s8("\x1B"#a)
-#define CSI(a) ESC([a)
-
-static s8 failure_string = s8("\x1B[31mFAILURE\x1B[0m\n");
-static s8 success_string = s8("\x1B[32mSUCCESS\x1B[0m\n");
+static b32
+mem_cmp(void *a_, void *b_, size len)
+{
+ /* NOTE: small size assumption */
+ ASSERT(len < 32);
+ b32 result = 0;
+ u8 *a = a_, *b = b_;
+ for (size i = 0; i < len; i++)
+ result |= a[i] != b[i];
+ return result;
+}
struct test_result { b32 status; const char *info; };
#define TEST_FN(name) struct test_result name(Term *term, Arena arena)
@@ -73,6 +77,12 @@ static Test_Fn *tests[] = {
TESTS
};
+#define ESC(a) s8("\x1B"#a)
+#define CSI(a) ESC([a)
+
+static s8 failure_string = s8("\x1B[31mFAILURE\x1B[0m\n");
+static s8 success_string = s8("\x1B[32mSUCCESS\x1B[0m\n");
+
static void
buffer_reset(Term *t)
{
@@ -274,9 +284,9 @@ static TEST_FN(cursor_at_line_boundary)
/* NOTE: check that cursor state was transferred */
Cursor line_end = simulate_line(term, lb->buf);
- result.status &= !memcmp(&line_end.style,
- &lb->buf[1].cursor_state,
- sizeof(lb->buf[0].cursor_state));
+ result.status &= !mem_cmp(&line_end.style,
+ &lb->buf[1].cursor_state,
+ sizeof(lb->buf[0].cursor_state));
return result;
}