test: Telex goes in the language table like every other map

The unit suite built a Lang of its own for Telex and loaded telex.map
into it, so the tests that drive the real table had to swap the map in
and out around themselves.  testmapinit loads it where it belongs.
This commit is contained in:
2026-08-17 12:20:39 +09:00
parent 3a90826238
commit e54783dc92
4 changed files with 14 additions and 39 deletions

View File

@@ -52,7 +52,7 @@ vietnamese_state_lifetime(struct ct *t)
Str com; Str com;
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
im.pre = mkstr("as"); im.pre = mkstr("as");
im.raw = mkstr("as"); im.raw = mkstr("as");
sclear(&com); sclear(&com);
@@ -62,7 +62,7 @@ vietnamese_state_lifetime(struct ct *t)
CT_EQ_INT(t, 0, im.raw.n); CT_EQ_INT(t, 0, im.raw.n);
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
im.pre = mkstr("as"); im.pre = mkstr("as");
im.raw = mkstr("as"); im.raw = mkstr("as");
sclear(&com); sclear(&com);
@@ -72,7 +72,7 @@ vietnamese_state_lifetime(struct ct *t)
CT_EQ_INT(t, 0, im.raw.n); CT_EQ_INT(t, 0, im.raw.n);
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
im.pre = mkstr("as"); im.pre = mkstr("as");
im.raw = mkstr("as"); im.raw = mkstr("as");
sclear(&com); sclear(&com);
@@ -357,7 +357,7 @@ engine_vietnamese_client_preedit(struct ct *t)
for(i = 0; i < nelem(cases); i++){ for(i = 0; i < nelem(cases); i++){
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
draindraw(nil); draindraw(nil);
sclear(&com); sclear(&com);
for(k = cases[i].keys; *k != '\0'; k++){ for(k = cases[i].keys; *k != '\0'; k++){
@@ -488,7 +488,7 @@ engine_telex_history_bound(struct ct *t)
int i; int i;
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
sclear(&com); sclear(&com);
CT_CHECK(t, keystroke('a', 0, &com)); CT_CHECK(t, keystroke('a', 0, &com));
for(i = 0; i < Maxrunes; i++){ for(i = 0; i < Maxrunes; i++){
@@ -620,16 +620,9 @@ engine_language_switch_state(struct ct *t)
{ "commit Vietnamese", 't', Mctrl, LangEN, "", "", "á", 0 }, { "commit Vietnamese", 't', Mctrl, LangEN, "", "", "á", 0 },
}; };
char where[80]; char where[80];
Lang *vi;
Trie *saved;
Str com; Str com;
int eaten, i; int eaten, i;
vi = getlang(LangVI);
if(!CT_CHECK(t, vi != nil))
return;
saved = vi->map;
vi->map = testvi.map;
init(); init();
for(i = 0; i < nelem(steps); i++){ for(i = 0; i < nelem(steps); i++){
if(steps[i].stale){ if(steps[i].stale){
@@ -675,7 +668,7 @@ engine_language_switch_state(struct ct *t)
CT_EQ_INT(t, 0, im.pre.n); CT_EQ_INT(t, 0, im.pre.n);
} }
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
sclear(&com); sclear(&com);
if(typekeys(t, "as", &com)){ if(typekeys(t, "as", &com)){
CT_CHECK(t, !keystroke('p', Mctrl, &com)); CT_CHECK(t, !keystroke('p', Mctrl, &com));
@@ -683,7 +676,6 @@ engine_language_switch_state(struct ct *t)
CT_EQ_INT(t, 0, im.pre.n); CT_EQ_INT(t, 0, im.pre.n);
CT_EQ_INT(t, 0, im.raw.n); CT_EQ_INT(t, 0, im.raw.n);
} }
vi->map = saved;
} }
typedef struct Searchfix Searchfix; typedef struct Searchfix Searchfix;
@@ -1694,14 +1686,14 @@ engine_emoji_preedit_languages(struct ct *t)
} }
init(); init();
im.l = &testvi; im.l = getlang(LangVI);
sclear(&com); sclear(&com);
if(typekeys(t, "as", &com)){ if(typekeys(t, "as", &com)){
CT_CHECK(t, keystroke('e', Mctrl, &com)); CT_CHECK(t, keystroke('e', Mctrl, &com));
checkstr(t, "committed Telex preedit", "á", &com); checkstr(t, "committed Telex preedit", "á", &com);
CT_CHECK(t, keystroke(Kesc, 0, &com)); CT_CHECK(t, keystroke(Kesc, 0, &com));
CT_CHECK(t, !search.lang); CT_CHECK(t, !search.lang);
CT_EQ_PTR(t, &testvi, im.l); CT_EQ_PTR(t, getlang(LangVI), im.l);
sclear(&com); sclear(&com);
if(typekeys(t, "as", &com)){ if(typekeys(t, "as", &com)){
impre(&im, &shown); impre(&im, &shown);
@@ -2051,8 +2043,6 @@ engine_randomized_stress(struct ct *t)
}; };
static Rune modes[] = { 't', 'n', 'k', 's', 'v' }; static Rune modes[] = { 't', 'n', 'k', 's', 'v' };
Searchfix f; Searchfix f;
Lang *vi;
Trie *vimap;
Keyres res; Keyres res;
Caret pos; Caret pos;
u32int rnd, mod; u32int rnd, mod;
@@ -2060,11 +2050,6 @@ engine_randomized_stress(struct ct *t)
void *owner, *owners[3]; void *owner, *owners[3];
int i, j, op; int i, j, op;
vi = getlang(LangVI);
if(!CT_CHECK(t, vi != nil))
return;
vimap = vi->map;
vi->map = testvi.map;
emojibegin(&f, 0); emojibegin(&f, 0);
owners[0] = &contexts[0]; owners[0] = &contexts[0];
owners[1] = &contexts[1]; owners[1] = &contexts[1];
@@ -2140,7 +2125,6 @@ engine_randomized_stress(struct ct *t)
} }
} }
searchend(&f); searchend(&f);
vi->map = vimap;
} }
void void

View File

@@ -1,8 +1,6 @@
/* Included after dat.h and fn.h (or after the source under test). */ /* Included after dat.h and fn.h (or after the source under test). */
#include "cutest/cutest.h" #include "cutest/cutest.h"
extern Lang testvi;
/* /*
* A test's stand-in for imthread: handles engine requests from keyc, * A test's stand-in for imthread: handles engine requests from keyc,
* tracing each one first. Requests whose op is holdop (every request * tracing each one first. Requests whose op is holdop (every request

View File

@@ -7,7 +7,6 @@
Channel *drawc; Channel *drawc;
Channel *keyc; Channel *keyc;
Lang testvi;
void void
die(char *fmt, ...) die(char *fmt, ...)
@@ -45,20 +44,16 @@ erealloc(void *p, ulong n)
static void static void
testmapinit(void) testmapinit(void)
{ {
Lang *jp, *kata; Lang *jp, *kata, *vi;
jp = getlang(LangJP); jp = getlang(LangJP);
kata = getlang(LangJPK); kata = getlang(LangJPK);
if(jp == nil || kata == nil) vi = getlang(LangVI);
if(jp == nil || kata == nil || vi == nil)
die("test language is not registered"); die("test language is not registered");
jp->map = trieopen("../map/hira.map"); jp->map = trieopen("../map/hira.map");
kata->map = trieopen("../map/kata.map"); kata->map = trieopen("../map/kata.map");
memset(&testvi, 0, sizeof testvi); vi->map = trieopen("../map/telex.map");
testvi.lang = LangVI;
testvi.mapname = "telex";
testvi.trans = transvi;
testvi.back = backvi;
testvi.map = trieopen("../map/telex.map");
} }
#ifndef STRESS #ifndef STRESS
@@ -170,8 +165,6 @@ threadmain(int argc, char **argv)
trieclose(langs[i].map); trieclose(langs[i].map);
langs[i].map = nil; langs[i].map = nil;
} }
trieclose(testvi.map);
testvi.map = nil;
chanfree(drawc); chanfree(drawc);
chanfree(keyc); chanfree(keyc);
threadexitsall(status == 0 ? nil : "tests failed"); threadexitsall(status == 0 ? nil : "tests failed");

View File

@@ -8,7 +8,7 @@ typevi(struct ct *t, char *keys, char *want)
Str out, raw; Str out, raw;
raw = mkstr(keys); raw = mkstr(keys);
transstr(&testvi, nil, &raw, &out); transstr(getlang(LangVI), nil, &raw, &out);
checkstr(t, keys, want, &out); checkstr(t, keys, want, &out);
} }
@@ -67,7 +67,7 @@ vietnamese_backspace(struct ct *t)
for(i = 0; i < nelem(cases); i++){ for(i = 0; i < nelem(cases); i++){
memset(&state, 0, sizeof state); memset(&state, 0, sizeof state);
state.l = &testvi; state.l = getlang(LangVI);
state.pre = mkstr(cases[i].pre); state.pre = mkstr(cases[i].pre);
state.raw = mkstr(cases[i].raw); state.raw = mkstr(cases[i].raw);
backvi(&state); backvi(&state);