summaryrefslogtreecommitdiff
path: root/tests/spec_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/spec_test.c')
-rw-r--r--tests/spec_test.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/tests/spec_test.c b/tests/spec_test.c
index 202f9ba..56e974c 100644
--- a/tests/spec_test.c
+++ b/tests/spec_test.c
@@ -6,7 +6,7 @@
* Rows read as text: '#' is U+FFFD, '?' is any other code point outside
* ASCII or a cluster, '_' is the right half of a wide glyph.
*/
-#include "term/term.h"
+#include "wsap_vtcore/wsap_vtcore.h"
#include <stdio.h>
#include <stdlib.h>
@@ -21,7 +21,7 @@ struct spec {
* the history check; reply NULL skips the reply check. */
int attr_x, attr_y;
uint16_t attrs;
- term_color fg, bg;
+ wsap_vtcore_color fg, bg;
int history;
const char *reply;
};
@@ -31,8 +31,8 @@ struct spec {
#define NO_EXTRA .attr_x = -1, .history = -1
#define CASE(name_, input_, a, b, c, x_, y_) \
{ .name = name_, .input = input_, .cols = 8, .rows = 3, ROWS3(a, b, c), AT(x_, y_), NO_EXTRA }
-#define RED (TERM_COLOR_SLOT | 1)
-#define BLUE (TERM_COLOR_SLOT | 4)
+#define RED (WSAP_VTCORE_COLOR_SLOT | 1)
+#define BLUE (WSAP_VTCORE_COLOR_SLOT | 4)
static const struct spec cases[] = {
/* Printing and C0 controls. */
@@ -174,56 +174,56 @@ static const struct spec cases[] = {
.name = "SGR", .input = "\033[1;3;4;9;53;38;5;123;48;2;1;2;3mX",
.cols = 8, .rows = 3, ROWS3("X", "", ""), AT(1, 0),
.attr_x = 0, .attr_y = 0,
- .attrs = TERM_ATTR_BOLD | TERM_ATTR_ITALIC | TERM_ATTR_STRIKE |
- TERM_ATTR_OVERLINE | TERM_ATTR_UNDERLINE,
- .fg = TERM_COLOR_SLOT | 123, .bg = 0xff010203u, .history = -1,
+ .attrs = WSAP_VTCORE_ATTR_BOLD | WSAP_VTCORE_ATTR_ITALIC | WSAP_VTCORE_ATTR_STRIKE |
+ WSAP_VTCORE_ATTR_OVERLINE | WSAP_VTCORE_ATTR_UNDERLINE,
+ .fg = WSAP_VTCORE_COLOR_SLOT | 123, .bg = 0xff010203u, .history = -1,
},
{
.name = "SGR colon RGB with a color space", .input = "\033[38:2::1:2:3mX",
.cols = 8, .rows = 3, ROWS3("X", "", ""), AT(1, 0),
- .attr_x = 0, .attr_y = 0, .fg = 0xff010203u, .bg = TERM_COLOR_BG, .history = -1,
+ .attr_x = 0, .attr_y = 0, .fg = 0xff010203u, .bg = WSAP_VTCORE_COLOR_BG, .history = -1,
},
{
/* 48:2:: takes the next three fields as RGB; the trailing 0 resets. */
.name = "SGR colon form is not two semicolon colors",
.input = "\033[48:2::::38;2;;;mX",
.cols = 8, .rows = 3, ROWS3("X", "", ""), AT(1, 0),
- .attr_x = 0, .attr_y = 0, .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG, .history = -1,
+ .attr_x = 0, .attr_y = 0, .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG, .history = -1,
},
{
.name = "restore restores the pen", .input = "\033[31m\0337\033[m\0338X",
.cols = 8, .rows = 3, ROWS3("X", "", ""), AT(1, 0),
- .attr_x = 0, .attr_y = 0, .fg = RED, .bg = TERM_COLOR_BG, .history = -1,
+ .attr_x = 0, .attr_y = 0, .fg = RED, .bg = WSAP_VTCORE_COLOR_BG, .history = -1,
},
{
.name = "SCORC restores the pen", .input = "\033[1m\033[s\033[m\033[uX",
.cols = 8, .rows = 3, ROWS3("X", "", ""), AT(1, 0),
- .attr_x = 0, .attr_y = 0, .attrs = TERM_ATTR_BOLD,
- .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG, .history = -1,
+ .attr_x = 0, .attr_y = 0, .attrs = WSAP_VTCORE_ATTR_BOLD,
+ .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG, .history = -1,
},
{
.name = "restore without save resets the pen", .input = "\033[31m\0338X",
.cols = 8, .rows = 3, ROWS3("X", "", ""), AT(1, 0),
- .attr_x = 0, .attr_y = 0, .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG, .history = -1,
+ .attr_x = 0, .attr_y = 0, .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG, .history = -1,
},
{
/* A rectangle edge on the right half of a wide glyph changes both
* halves. */
.name = "DECCARA on half a wide glyph", .input = "a中b\033[1;3;1;3;1$r",
.cols = 8, .rows = 3, ROWS3("a?_b", "", ""), AT(4, 0),
- .attr_x = 1, .attr_y = 0, .attrs = TERM_ATTR_BOLD,
- .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG, .history = -1,
+ .attr_x = 1, .attr_y = 0, .attrs = WSAP_VTCORE_ATTR_BOLD,
+ .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG, .history = -1,
},
{
.name = "erase uses the pen background", .input = "ab\033[41m\033[1;1H\033[X",
.cols = 8, .rows = 3, ROWS3(" b", "", ""), AT(0, 0),
- .attr_x = 0, .attr_y = 0, .fg = TERM_COLOR_FG, .bg = TERM_COLOR_SLOT | 1, .history = -1,
+ .attr_x = 0, .attr_y = 0, .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_SLOT | 1, .history = -1,
},
{
.name = "full-screen scroll BCE", .input = "abc\033[44m\r\n\r\n\r\n",
.cols = 8, .rows = 3, ROWS3("", "", ""), AT(0, 2),
.attr_x = 0, .attr_y = 2,
- .fg = TERM_COLOR_FG, .bg = BLUE, .history = -1,
+ .fg = WSAP_VTCORE_COLOR_FG, .bg = BLUE, .history = -1,
},
/* Replies. */
@@ -268,41 +268,41 @@ static void on_reply(void *ud, const char *bytes, size_t len)
}
}
-static char cell_char(const struct term_snapshot *s, const struct term_cell *c)
+static char cell_char(const struct wsap_vtcore_snapshot *s, const struct wsap_vtcore_cell *c)
{
if (c->width == 0) return '_';
uint32_t cps[4] = {0};
- int n = term_snapshot_cluster(s, c->text, cps, 4);
+ int n = wsap_vtcore_snapshot_cluster(s, c->text, cps, 4);
if (n != 1) return '?';
if (cps[0] == 0xFFFD) return '#';
return cps[0] >= 0x20 && cps[0] < 0x7f ? (char)cps[0] : '?';
}
-static int run(const struct spec *c, struct term_snapshot *s, bool bytes)
+static int run(const struct spec *c, struct wsap_vtcore_snapshot *s, bool bytes)
{
struct replies got = {0};
- struct term_options opt = {
+ struct wsap_vtcore_options opt = {
.size = { .x = c->cols, .y = c->rows }, .scrollback = 100,
.callbacks = { .ud = &got, .reply = on_reply },
};
- struct term *t = term_new(&opt);
+ struct wsap_vtcore *t = wsap_vtcore_new(&opt);
if (!t) return 1;
size_t len = strlen(c->input);
if (bytes)
- for (size_t i = 0; i < len; i++) term_feed(t, c->input + i, 1, 0);
+ for (size_t i = 0; i < len; i++) wsap_vtcore_feed(t, c->input + i, 1, 0);
else
- term_feed(t, c->input, len, 0);
+ wsap_vtcore_feed(t, c->input, len, 0);
const char *mode = bytes ? "byte by byte" : "whole";
int bad = 0;
- struct term_cursor cursor = term_cursor(t);
+ struct wsap_vtcore_cursor cursor = wsap_vtcore_cursor(t);
if (cursor.pos.x != c->x || cursor.pos.y != c->y) {
fprintf(stderr, "%s (%s): cursor %d,%d; expected %d,%d\n", c->name, mode,
cursor.pos.x, cursor.pos.y, c->x, c->y);
bad = 1;
}
- if (!term_snapshot_update(s, t)) return 1;
+ if (!wsap_vtcore_snapshot_update(s, t)) return 1;
for (int y = 0; y < c->rows && y < 4; y++) {
- const struct term_cell *row = term_snapshot_row(s, y);
+ const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, y);
char text[64];
int n = 0;
for (int x = 0; x < c->cols && n < 63; x++) text[n++] = cell_char(s, &row[x]);
@@ -316,66 +316,66 @@ static int run(const struct spec *c, struct term_snapshot *s, bool bytes)
}
}
if (c->attr_x >= 0) {
- const struct term_cell *cell = &term_snapshot_row(s, c->attr_y)[c->attr_x];
+ const struct wsap_vtcore_cell *cell = &wsap_vtcore_snapshot_row(s, c->attr_y)[c->attr_x];
if (cell->attrs != c->attrs || cell->fg != c->fg || cell->bg != c->bg) {
fprintf(stderr, "%s (%s): attributes %x fg %x bg %x; expected %x %x %x\n",
c->name, mode, cell->attrs, cell->fg, cell->bg, c->attrs, c->fg, c->bg);
bad = 1;
}
}
- if (c->history >= 0 && term_scrollback(t).total != c->history) {
+ if (c->history >= 0 && wsap_vtcore_scrollback(t).total != c->history) {
fprintf(stderr, "%s (%s): history %d; expected %d\n", c->name, mode,
- term_scrollback(t).total, c->history);
+ wsap_vtcore_scrollback(t).total, c->history);
bad = 1;
}
if (c->reply && (got.len != strlen(c->reply) || memcmp(got.s, c->reply, got.len))) {
fprintf(stderr, "%s (%s): reply differs\n", c->name, mode);
bad = 1;
}
- term_free(t);
+ wsap_vtcore_free(t);
return bad;
}
int main(void)
{
- struct term_snapshot *s = term_snapshot_new();
+ struct wsap_vtcore_snapshot *s = wsap_vtcore_snapshot_new();
if (!s) return 1;
int failed = 0;
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
failed += run(&cases[i], s, false) | run(&cases[i], s, true);
/* ONLCR is a feed option. A plain line feed keeps the column. */
- struct term_options opt = { .size = { .x = 8, .y = 2 } };
- struct term *t = term_new(&opt);
+ struct wsap_vtcore_options opt = { .size = { .x = 8, .y = 2 } };
+ struct wsap_vtcore *t = wsap_vtcore_new(&opt);
if (!t) return 1;
- term_feed(t, "ab\nZ", 4, TERM_FEED_ONLCR);
- if (term_cursor(t).pos.x != 1 || term_cursor(t).pos.y != 1) {
+ wsap_vtcore_feed(t, "ab\nZ", 4, WSAP_VTCORE_FEED_ONLCR);
+ if (wsap_vtcore_cursor(t).pos.x != 1 || wsap_vtcore_cursor(t).pos.y != 1) {
fprintf(stderr, "ONLCR: line feed did not return to column zero\n");
failed++;
}
- term_free(t);
+ wsap_vtcore_free(t);
/* A long stream can skip old rows. A bare CR must keep the last rows. */
- opt.size = (struct term_vector2i){ .x = 8, .y = 3 };
+ opt.size = (struct wsap_vtcore_vector2i){ .x = 8, .y = 3 };
opt.scrollback = 5;
- t = term_new(&opt);
+ t = wsap_vtcore_new(&opt);
if (!t) return 1;
char *stream = malloc(13000u * 9u + 8u);
if (!stream) return 1;
for (int i = 0; i < 13000; i++) memcpy(stream + (size_t)i * 9, "1234567\r\n", 9);
memcpy(stream + 13000u * 9u, "broken\rY", 8);
- term_feed(t, stream, 13000u * 9u + 8u, 0);
+ wsap_vtcore_feed(t, stream, 13000u * 9u + 8u, 0);
free(stream);
- if (term_scrollback(t).total != 5) {
+ if (wsap_vtcore_scrollback(t).total != 5) {
fprintf(stderr, "long stream: history count differs\n");
failed++;
}
for (int offset = 5;; offset = offset > 3 ? offset - 3 : 0) {
- term_scroll_to(t, offset);
- if (!term_snapshot_update(s, t)) return 1;
+ wsap_vtcore_scroll_to(t, offset);
+ if (!wsap_vtcore_snapshot_update(s, t)) return 1;
for (int y = 0; y < 3; y++) {
const char *want = offset == 0 && y == 2 ? "Yroken" : "1234567";
- const struct term_cell *row = term_snapshot_row(s, y);
+ const struct wsap_vtcore_cell *row = wsap_vtcore_snapshot_row(s, y);
for (int x = 0; x < 8; x++) {
uint32_t cp = x < (int)strlen(want) ? (unsigned char)want[x] : ' ';
if (row[x].text != cp) {
@@ -388,8 +388,8 @@ int main(void)
}
if (!offset) break;
}
- term_free(t);
- term_snapshot_free(s);
+ wsap_vtcore_free(t);
+ wsap_vtcore_snapshot_free(s);
if (failed) fprintf(stderr, "%d spec failures\n", failed);
return failed != 0;
}