Files
strans/tests/vi_test.c
Hojun-Cho a557fb114a engine: one trans contract for every language
Japanese was never dispatched through the Lang table: dotrans and
transstr both special-cased it into transjp, which edited Im in place
and wrote commits through a side argument, while transko popped and
cleared a pre that every caller overwrote anyway, and Vietnamese kept
its key history in dotrans. Emit now carries the new raw state next to
the new pre; transjp, transko and transvi are pure functions of (Im,
key), and dotrans and transstr have a single path. Vietnamese history
bookkeeping lives in vi.c, where the full-history flush no longer
resets the caret as a side effect; istone was toneidx() >= 0.
2026-08-16 16:04:57 +09:00

86 lines
1.7 KiB
C

#include "test.h"
static void
typevi(struct ct *t, char *keys, char *want)
{
Emit e;
Im state;
Str out, shown;
char *p;
memset(&state, 0, sizeof state);
state.l = &testvi;
sclear(&out);
for(p = keys; *p != '\0'; p++){
e = transvi(&state, (uchar)*p);
sappend(&out, &e.s);
state.pre = e.next;
state.raw = e.raw;
if(!e.eat)
sputr(&out, (uchar)*p);
}
shown = shownpre(&state);
sappend(&out, &shown);
checkstr(t, keys, want, &out);
}
void
vietnamese_transitions(struct ct *t)
{
static const struct { char *keys, *want; } cases[] = {
{ "as", "á" },
{ "As", "Á" },
{ "ans", "án" },
{ "Ans", "Án" },
{ "aws", "" },
{ "asw", "" },
{ "aww", "aw" },
{ "ddd", "dd" },
{ "ddas", "đá" },
{ "dds", "đs" },
{ "quas", "quá" },
{ "quaf", "quà" },
{ "quar", "quả" },
{ "quax", "quã" },
{ "quaj", "quạ" },
{ "Quas", "Quá" },
{ "gias", "giá" },
{ "Gias", "Giá" },
{ "gif", "" },
{ "\\s", "s" },
{ "a\\s", "as" },
};
int i;
for(i = 0; i < nelem(cases); i++)
typevi(t, cases[i].keys, cases[i].want);
}
void
vietnamese_backspace(struct ct *t)
{
static const struct {
char *pre, *raw, *rawafter, *after;
} cases[] = {
{ "as", "as", "a", "a" },
{ "quá", "quas", "qua", "qua" },
{ "à", "asf", "as", "á" },
{ "a", "asz", "as", "á" },
{ "quà", "quasf", "quas", "quá" },
};
Im state;
Str shown;
int i;
for(i = 0; i < nelem(cases); i++){
memset(&state, 0, sizeof state);
state.l = &testvi;
state.pre = mkstr(cases[i].pre);
state.raw = mkstr(cases[i].raw);
backvi(&state);
checkstr(t, cases[i].raw, cases[i].rawafter, &state.raw);
shown = shownpre(&state);
checkstr(t, cases[i].raw, cases[i].after, &shown);
}
}