Commit: 65619029d828def759a1fe67630dc3d5a157b6a0
Parent: 400dd63d5a02cf6426bc56279de1017eb4cc017a
Author: Randy Palamar
Date: Mon, 8 Jul 2024 21:18:07 -0600
test: cell colouring
Diffstat:
M | test.c | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++++---- |
1 file changed, 48 insertions(+), 4 deletions(-)
diff --git a/test.c b/test.c
@@ -12,6 +12,19 @@ struct test_result { b32 status; const char *info; };
#define TEST_FN(name) struct test_result name(Term *term, Arena arena)
typedef TEST_FN(Test_Fn);
+#define TESTS \
+ X(colour_setting) \
+ X(cursor_movement)
+
+#define X(fn) static TEST_FN(fn);
+TESTS
+#undef X
+
+#define X(fn) fn,
+static Test_Fn *tests[] = {
+ TESTS
+};
+
static size
copy_into_ringbuf(RingBuf *rb, s8 raw)
{
@@ -31,6 +44,16 @@ copy_into_ringbuf(RingBuf *rb, s8 raw)
return raw.len;
}
+static b32
+check_cells_equal(Cell *a, Cell *b)
+{
+ b32 result = a->cp == b->cp &&
+ a->style.bg.rgba == b->style.bg.rgba &&
+ a->style.fg.rgba == b->style.fg.rgba &&
+ a->style.attr == b->style.attr;
+ return result;
+}
+
static s8
launder_static_string(Term *term, s8 static_str)
{
@@ -42,7 +65,7 @@ launder_static_string(Term *term, s8 static_str)
return raw;
}
-static TEST_FN(test_cursor_movement)
+static TEST_FN(cursor_movement)
{
struct test_result result = {.info = __FUNCTION__};
@@ -59,9 +82,30 @@ static TEST_FN(test_cursor_movement)
return result;
}
-static Test_Fn *tests[] = {
- test_cursor_movement,
-};
+static TEST_FN(colour_setting)
+{
+ struct test_result result = {.info = __FUNCTION__};
+
+ launder_static_string(term, s8(CSI(8m)));
+ launder_static_string(term, s8(CSI(4m)));
+ launder_static_string(term, s8(CSI(9m)));
+ launder_static_string(term, s8(CSI(24m)));
+ launder_static_string(term, s8(CSI(33m)));
+ launder_static_string(term, s8(CSI(48;2;75;63;42m)));
+ s8 raw = launder_static_string(term, s8("A"));
+
+ split_raw_input_to_lines(term, raw);
+ blit_lines(term, arena);
+
+ Cell c = { .cp = 'A', .style = {
+ .bg = (Colour){.r = 75, .g = 63, .b = 42, .a = 0xFF},
+ .fg = g_colours.data[3],
+ .attr = (ATTR_INVISIBLE|ATTR_STRUCK),
+ }};
+ result.status = check_cells_equal(&c, term->fb.rows[0]);
+
+ return result;
+}
static u32 failure_count;