fix(engine): make composition transitions deterministic

This commit is contained in:
2026-08-14 22:13:16 +09:00
parent f2fb71cd89
commit 5dc2530951
2 changed files with 199 additions and 82 deletions

View File

@@ -8,6 +8,7 @@ int checkstr(struct ct*, char*, char*, Str*);
Str shownpre(Im*);
static int typekeys(struct ct*, char*, Str*);
static int draindraw(Drawcmd*);
void
testengineinit(int lang)
@@ -417,7 +418,8 @@ engine_commit_contract(struct ct *t)
im.kouho[0] = mkstr("c1");
im.kouho[1] = mkstr("c2");
im.nkouho = 2;
im.sel = 1;
im.sel = 0;
CT_CHECK(t, keystroke(Kdown, 0, &com));
CT_CHECK(t, keystroke(Kret, 0, &com));
checkstr(t, "selected candidate", "c2", &com);
CT_EQ_INT(t, 0, im.pre.n);
@@ -484,6 +486,7 @@ engine_korean_modifiers_and_backspace(struct ct *t)
{ 'w', "", "" }, { 'o', "", "" },
{ 'p', "", "" },
};
Drawcmd dc;
Str com;
int i;
@@ -518,8 +521,11 @@ engine_korean_modifiers_and_backspace(struct ct *t)
sclear(&com);
if(typekeys(t, "rkr", &com)){
checkstr(t, "Korean engine preedit", "", &im.pre);
draindraw(nil);
CT_CHECK(t, keystroke(Kback, 0, &com));
checkstr(t, "Korean final backspace", "", &im.pre);
if(CT_CHECK(t, draindraw(&dc) == 1))
checkstr(t, "Korean backspace redraw", "", &dc.pre);
CT_CHECK(t, keystroke(Kback, 0, &com));
checkstr(t, "Korean vowel backspace", "", &im.pre);
CT_CHECK(t, keystroke(Kback, 0, &com));
@@ -578,10 +584,10 @@ engine_language_switch_state(struct ct *t)
{ "select Vietnamese", 'v', Mctrl, LangVI, "", "", "", 0 },
{ "Vietnamese a", 'a', 0, LangVI, "a", "a", "", 0 },
{ "Vietnamese tone", 's', 0, LangVI, "as", "as", "", 0 },
{ "switch to Korean", 's', Mctrl, LangKO, "", "", "", 1 },
{ "switch to Korean", 's', Mctrl, LangKO, "", "", "á", 1 },
{ "Korean initial", 'r', 0, LangKO, "", "", "", 0 },
{ "Korean syllable", 'k', 0, LangKO, "", "", "", 0 },
{ "switch to Vietnamese", 'v', Mctrl, LangVI, "", "", "", 0 },
{ "switch to Vietnamese", 'v', Mctrl, LangVI, "", "", "", 0 },
{ "Vietnamese a again", 'a', 0, LangVI, "a", "a", "", 0 },
{ "Vietnamese tone again", 's', 0, LangVI, "as", "as", "", 0 },
{ "commit Vietnamese", Kret, 0, LangVI, "", "", "á", 0 },
@@ -632,6 +638,24 @@ engine_language_switch_state(struct ct *t)
break;
}
}
init();
im.l = getlang(LangKO);
sclear(&com);
if(typekeys(t, "rk", &com)){
CT_CHECK(t, !keystroke('p', Mctrl, &com));
checkstr(t, "Korean Ctrl passthrough", "", &com);
CT_EQ_INT(t, 0, im.pre.n);
}
init();
im.l = &testvi;
sclear(&com);
if(typekeys(t, "as", &com)){
CT_CHECK(t, !keystroke('p', Mctrl, &com));
checkstr(t, "Vietnamese Ctrl passthrough", "á", &com);
CT_EQ_INT(t, 0, im.pre.n);
CT_EQ_INT(t, 0, im.raw.n);
}
vi->map = saved;
}
@@ -644,6 +668,7 @@ struct Searchfix
Hmap *dict;
int activecap;
int visible;
int candidatechosen;
};
static int
@@ -691,7 +716,7 @@ checkcandidatepage(struct ct *t, char *where, int first, int n, int sel)
Drawcmd dc;
char want[8];
show();
redraw();
if(!CT_CHECK(t, draindraw(&dc) > 0))
return 0;
if(!CT_EQ_INT(t, n, dc.nkouho) || !CT_EQ_INT(t, sel, dc.sel) ||
@@ -732,10 +757,10 @@ engine_candidate_page_metadata(struct ct *t)
/* A clearing draw is the observable zero-candidate snapshot. */
candidatebegin(1);
show();
redraw();
draindraw(nil);
setcandidates(0);
show();
redraw();
if(CT_CHECK(t, draindraw(&dc) > 0)){
CT_EQ_INT(t, 0, dc.nkouho);
CT_EQ_INT(t, -1, dc.sel);
@@ -761,7 +786,7 @@ engine_candidate_page_snapshots(struct ct *t)
candidatebegin(totals[i]);
CT_EQ_INT(t, totals[i] == 0 ? -1 : 0, im.sel);
if(totals[i] == 0){
show();
redraw();
CT_EQ_INT(t, 0, draindraw(nil));
continue;
}
@@ -815,17 +840,39 @@ engine_candidate_page_movement(struct ct *t)
void
engine_candidate_completion(struct ct *t)
{
static Rune keys[] = { Kret, Ktab };
Dictres res;
Str com;
int arrived, i;
for(i = 0; i < nelem(keys); i++)
for(arrived = 0; arrived < 2; arrived++){
init();
im.l = getlang(LangJP);
im.pre = mkstr("reading");
memset(&res, 0, sizeof res);
res.key = im.pre;
res.lang = LangJP;
res.seq = dictseq;
res.kouho[0] = mkstr("candidate");
res.nkouho = 1;
if(arrived)
dictresult(&res);
sclear(&com);
CT_CHECK(t, keystroke(keys[i], 0, &com));
if(!arrived)
dictresult(&res);
checkstr(t, "unselected candidate commits reading",
"reading", &com);
CT_EQ_INT(t, 0, im.nkouho);
}
candidatebegin(2);
im.pre = mkstr("reading");
sclear(&com);
CT_CHECK(t, keystroke(Kdown, 0, &com));
CT_CHECK(t, keystroke(Kret, 0, &com));
checkstr(t, "default candidate", "c1", &com);
candidatebegin(2);
sclear(&com);
CT_CHECK(t, keystroke(Ktab, 0, &com));
checkstr(t, "ordinary Tab candidate", "c1", &com);
checkstr(t, "explicit candidate", "c2", &com);
candidatebegin(2);
im.pre = mkstr("reading");
@@ -866,6 +913,7 @@ searchsave(Searchfix *f, int lang)
f->dict = f->dictlang->dict;
f->activecap = activecap;
f->visible = visible;
f->candidatechosen = candidatechosen;
draindraw(nil);
}
@@ -908,6 +956,7 @@ searchend(Searchfix *f)
search = f->search;
activecap = f->activecap;
visible = f->visible;
candidatechosen = f->candidatechosen;
}
void
@@ -931,7 +980,7 @@ engine_popup_preedit_capability(struct ct *t)
res.nkouho = 1;
dictresult(&res);
im.sel = 0;
show();
redraw();
if(CT_CHECK(t, draindraw(&dc) > 0)){
CT_EQ_INT(t, 0, dc.pre.n);
CT_EQ_INT(t, 1, dc.nkouho);
@@ -1018,7 +1067,15 @@ engine_japanese_readings(struct ct *t)
{ "nnya", "んにゃ" },
{ "kin'youbi", "きんようび" },
};
Str com, shown;
static const struct {
char *raw;
char *want;
} replay[] = {
{ "kitte", "きって" },
{ "kanj", "かんj" },
{ "n'ya", "んや" },
};
Str com, raw, shown;
int i;
for(i = 0; i < nelem(cases); i++){
@@ -1033,6 +1090,11 @@ engine_japanese_readings(struct ct *t)
CT_CHECK(t, keystroke(Kret, 0, &com));
checkstr(t, "committed reading", cases[i].want, &com);
}
for(i = 0; i < nelem(replay); i++){
raw = mkstr(replay[i].raw);
transstr(getlang(LangJP), &raw, &shown);
checkstr(t, replay[i].raw, replay[i].want, &shown);
}
}
static int
@@ -1194,7 +1256,7 @@ engine_emoji_single_candidate(struct ct *t)
checkstr(t, "explicit candidate commit", "α", &com);
CT_CHECK(t, !search.lang);
CT_EQ_INT(t, LangKO, im.l->lang);
show();
redraw();
CT_CHECK(t, draindraw(&dc) > 0);
CT_EQ_INT(t, 0, dc.pre.n);
CT_EQ_INT(t, 0, dc.nkouho);