summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 11:37:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 11:37:31 +0300
commitaf6a37b1c4509c7766933a7cb45d2ee9a3a23f98 (patch)
treee7b0294ebf0d9b124b8885a76c119d7f46d5b0fb /tests
parentacd338ea33de36d223cc6d301712eed4a9501e6c (diff)
Return owned text and share cell attribute flags with snapshots
Make text queries return allocated strings released with term_text_free, keeping each capture atomic. Align public attributes with the write core, remove snapshot conversion tables, and migrate tests and the Kitty adapter.
Diffstat (limited to 'tests')
-rw-r--r--tests/extern/kitty/screen.py14
-rw-r--r--tests/helpers/term_api.h23
-rw-r--r--tests/model.c11
-rw-r--r--tests/osc_test.c10
-rw-r--r--tests/spec_test.c2
-rw-r--r--tests/term_test.c11
6 files changed, 29 insertions, 42 deletions
diff --git a/tests/extern/kitty/screen.py b/tests/extern/kitty/screen.py
index cc7289b..a3336d8 100644
--- a/tests/extern/kitty/screen.py
+++ b/tests/extern/kitty/screen.py
@@ -71,14 +71,13 @@ TERM_DEFAULT_BG = 0xFF1E1E2E
# Cell attributes (must match enum term_attr in term.h)
TERM_ATTR_BOLD = 1 << 0
TERM_ATTR_ITALIC = 1 << 1
-TERM_ATTR_FAINT = 1 << 2
+TERM_ATTR_FAINT = 1 << 10
TERM_ATTR_STRIKE = 1 << 3
TERM_ATTR_OVERLINE = 1 << 4
-TERM_ATTR_LINK = 1 << 5
-TERM_ATTR_EMOJI = 1 << 6
-TERM_ATTR_TEXT = 1 << 7
-TERM_ATTR_UNDERLINE_SHIFT = 8
-TERM_ATTR_UNDERLINE_MASK = 7 << TERM_ATTR_UNDERLINE_SHIFT
+TERM_ATTR_LINK = 1 << 15
+TERM_ATTR_EMOJI = 1 << 5
+TERM_ATTR_TEXT = 1 << 6
+TERM_UNDERLINE_FLAGS = (1 << 2, 1 << 11, 1 << 12, 1 << 13, 1 << 14)
# The longest grapheme cluster that a cell's text is read with.
_CLUSTER_CAP = 32
@@ -276,7 +275,8 @@ class CellCursor:
def decoration(self):
# enum term_underline uses Kitty's numbers: 0=none, 1=straight,
# 2=double, 3=curly, 4=dotted, 5=dashed.
- return (self._cell.attrs & TERM_ATTR_UNDERLINE_MASK) >> TERM_ATTR_UNDERLINE_SHIFT
+ return next((i for i, flag in enumerate(TERM_UNDERLINE_FLAGS, 1)
+ if self._cell.attrs & flag), 0)
@property
def fg(self):
diff --git a/tests/helpers/term_api.h b/tests/helpers/term_api.h
index bfa8d71..f2d6a5d 100644
--- a/tests/helpers/term_api.h
+++ b/tests/helpers/term_api.h
@@ -137,35 +137,18 @@ static inline void tt_select(struct term *t, int x1, int y1, int x2, int y2)
/* NULL when nothing is selected. */
static inline char *tt_selection_text(const struct term *t)
{
- size_t n = term_selection_text(t, NULL, 0);
- if (!n)
- return NULL;
- char *text = malloc(n + 1);
- if (text)
- term_selection_text(t, text, n + 1);
- return text;
+ return term_selection_text(t);
}
static inline char *tt_history_text(struct term *t, int max_rows)
{
- size_t n = term_history_text(t, max_rows, NULL, 0);
- char *text = malloc(n + 1);
- if (text)
- term_history_text(t, max_rows, text, n + 1);
- return text;
+ return term_history_text(t, max_rows);
}
/* NULL when there is no link. */
static inline char *tt_link_at(struct term *t, int col, int row)
{
- struct term_vector2i cell = { .x = col, .y = row };
- size_t n = term_link_at(t, cell, NULL, 0);
- if (!n)
- return NULL;
- char *url = malloc(n + 1);
- if (url)
- term_link_at(t, cell, url, n + 1);
- return url;
+ return term_link_at(t, (struct term_vector2i){ .x = col, .y = row });
}
static inline bool tt_resize(struct term *t, int cols, int rows)
diff --git a/tests/model.c b/tests/model.c
index 4fd3737..8dead6c 100644
--- a/tests/model.c
+++ b/tests/model.c
@@ -727,9 +727,12 @@ static void pen_reset(struct pen *p)
static void set_underline(uint16_t *attrs, int style)
{
- if (style > 5) style = 1;
- *attrs = (uint16_t)((*attrs & ~TERM_ATTR_UNDERLINE_MASK) |
- (unsigned)style << TERM_ATTR_UNDERLINE_SHIFT);
+ static const uint16_t flags[] = {
+ 0, TERM_ATTR_UNDERLINE, TERM_ATTR_DOUBLE_UNDERLINE,
+ TERM_ATTR_CURLY_UNDERLINE, TERM_ATTR_DOTTED_UNDERLINE, TERM_ATTR_DASHED_UNDERLINE,
+ };
+ if ((unsigned)style > 5) style = 1;
+ *attrs = (uint16_t)((*attrs & ~TERM_ATTR_UNDERLINE_MASK) | flags[style]);
}
/* 38, 48, and 58. Returns the parameters it used after the first. */
@@ -814,7 +817,7 @@ static void sgr_report(const struct model *m, char *out, size_t cap)
size_t n = 0;
out[0] = 0;
#define ADD(...) do { int k = snprintf(out + n, cap - n, __VA_ARGS__); if (k > 0) n += (size_t)k; } while (0)
- int ul = (int)((p->attrs & TERM_ATTR_UNDERLINE_MASK) >> TERM_ATTR_UNDERLINE_SHIFT);
+ int ul = term_attr_underline(p->attrs);
if (!(p->attrs & (TERM_ATTR_BOLD | TERM_ATTR_FAINT | TERM_ATTR_ITALIC | TERM_ATTR_STRIKE |
TERM_ATTR_OVERLINE | TERM_ATTR_UNDERLINE_MASK)) &&
!p->inverse && p->fg == TERM_COLOR_FG && p->bg == TERM_COLOR_BG && !p->ul)
diff --git a/tests/osc_test.c b/tests/osc_test.c
index 91b51d6..41a9247 100644
--- a/tests/osc_test.c
+++ b/tests/osc_test.c
@@ -259,11 +259,13 @@ static void test_osc8(void)
term_free(t);
}
-static bool text_is(size_t (*get)(const struct term *, char *, size_t),
+static bool text_is(char *(*get)(const struct term *),
const struct term *t, const char *want)
{
- char buf[256];
- return get(t, buf, sizeof(buf)) == strlen(want) && !strcmp(buf, want);
+ char *text = get(t);
+ bool same = text && !strcmp(text, want);
+ term_text_free(text);
+ return same;
}
static void test_osc_misc(void)
@@ -304,7 +306,7 @@ static void test_osc_misc(void)
write_seq(t, "\033]22;text\007");
assert(text_is(term_pointer_shape, t, "text"));
write_seq(t, "\033]22;\033\\");
- assert(!term_pointer_shape(t, NULL, 0));
+ assert(!term_pointer_shape(t));
term_free(t);
}
diff --git a/tests/spec_test.c b/tests/spec_test.c
index ec9d45d..202f9ba 100644
--- a/tests/spec_test.c
+++ b/tests/spec_test.c
@@ -175,7 +175,7 @@ static const struct spec cases[] = {
.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_UNDERLINE_SINGLE << TERM_ATTR_UNDERLINE_SHIFT),
+ TERM_ATTR_OVERLINE | TERM_ATTR_UNDERLINE,
.fg = TERM_COLOR_SLOT | 123, .bg = 0xff010203u, .history = -1,
},
{
diff --git a/tests/term_test.c b/tests/term_test.c
index 3721720..66dbd96 100644
--- a/tests/term_test.c
+++ b/tests/term_test.c
@@ -1811,16 +1811,15 @@ static void test_concurrent_feed_and_snapshot(void)
(void)c;
/* Every reader is safe while another thread feeds. */
- char buf[256];
term_select_start(t, (struct term_vector2i){ .x = 0, .y = 0 }, false, TERM_SELECT_WORD);
term_select_extend(t, (struct term_vector2i){ .x = 40, .y = 10 }, false);
(void)term_has_selection(t);
- (void)term_selection_text(t, buf, sizeof(buf));
- (void)term_link_at(t, (struct term_vector2i){ .x = 1, .y = 1 }, buf, sizeof(buf));
- (void)term_cwd(t, buf, sizeof(buf));
- (void)term_pointer_shape(t, buf, sizeof(buf));
+ term_text_free(term_selection_text(t));
+ term_text_free(term_link_at(t, (struct term_vector2i){ .x = 1, .y = 1 }));
+ term_text_free(term_cwd(t));
+ term_text_free(term_pointer_shape(t));
(void)term_history_rows(t);
- (void)term_history_text(t, 5, buf, sizeof(buf));
+ term_text_free(term_history_text(t, 5));
struct term_scrollback sb = term_scrollback(t);
assert(sb.offset >= 0 && sb.total >= 0);
}