test: drive Korean and Vietnamese through the engine's own transstr
ko_test and vi_test replayed keys with private copies of transstr's loop, and test_util reimplemented the shown preedit; the engine exports impre(Im*, Str*) and transstr() instead, so a change to composition rules is one edit.
This commit is contained in:
@@ -5,7 +5,6 @@ extern Lang testvi;
|
||||
|
||||
Str mkstr(char*);
|
||||
int checkstr(struct ct*, char*, char*, Str*);
|
||||
Str shownpre(Im*);
|
||||
|
||||
static int typekeys(struct ct*, char*, Str*);
|
||||
static int draindraw(Drawcmd*);
|
||||
@@ -43,7 +42,7 @@ testengineowner(void)
|
||||
void
|
||||
testenginepreedit(Str *preedit)
|
||||
{
|
||||
impre(preedit);
|
||||
impre(&im, preedit);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -116,7 +115,7 @@ engine_backspace_clears_candidates(struct ct *t)
|
||||
sclear(&com);
|
||||
CT_CHECK(t, keystroke('n', 0, &com));
|
||||
CT_CHECK(t, keystroke('a', 0, &com));
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "before backspace", "な", &shown);
|
||||
im.kouho[0] = mkstr("stale-candidate");
|
||||
im.nkouho = 1;
|
||||
@@ -124,7 +123,7 @@ engine_backspace_clears_candidates(struct ct *t)
|
||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||
checkstr(t, "backspace commit", "", &com);
|
||||
checkstr(t, "pending romaji after backspace", "n", &im.raw);
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "shown preedit after backspace", "ん", &shown);
|
||||
CT_EQ_INT(t, 0, im.nkouho);
|
||||
CT_EQ_INT(t, -1, im.sel);
|
||||
@@ -238,7 +237,7 @@ engine_active_owner_lifecycle(struct ct *t)
|
||||
CT_EQ_PTR(t, &b, activeowner);
|
||||
res = ownerrequest(&a, Keyreset, 0, 0);
|
||||
CT_EQ_INT(t, 0, res.preedit.n);
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "stale reset preserves owner", "ん", &shown);
|
||||
CT_EQ_PTR(t, &b, activeowner);
|
||||
|
||||
@@ -246,7 +245,7 @@ engine_active_owner_lifecycle(struct ct *t)
|
||||
res = ownerrequest(&b, Keypress, 'a', 0);
|
||||
checkstr(t, "current owner continues", "にゃ", &res.preedit);
|
||||
ownerrequest(&a, Keyrelease, 0, 0);
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "stale release preserves owner", "にゃ", &shown);
|
||||
CT_EQ_PTR(t, &b, activeowner);
|
||||
|
||||
@@ -1074,7 +1073,7 @@ engine_japanese_readings(struct ct *t)
|
||||
if(!typekeys(t, cases[i].keys, &com))
|
||||
continue;
|
||||
checkstr(t, cases[i].keys, "", &com);
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, cases[i].keys, cases[i].want, &shown);
|
||||
CT_CHECK(t, keystroke(Kret, 0, &com));
|
||||
checkstr(t, "committed reading", cases[i].want, &com);
|
||||
@@ -1102,7 +1101,7 @@ engine_japanese_candidates(struct ct *t)
|
||||
sclear(&com);
|
||||
if(!typekeys(t, "kanji", &com))
|
||||
goto cleanup;
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "complete Japanese reading", "かんじ", &shown);
|
||||
if(!CT_EQ_INT(t, 2, im.nkouho))
|
||||
goto cleanup;
|
||||
@@ -1138,13 +1137,13 @@ engine_japanese_backspace_and_boundaries(struct ct *t)
|
||||
sclear(&com);
|
||||
if(typekeys(t, "kanji", &com)){
|
||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "backspace pending i", "かんj", &shown);
|
||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "backspace pending j", "かん", &shown);
|
||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "backspace accumulated kana", "か", &shown);
|
||||
}
|
||||
|
||||
@@ -1198,7 +1197,7 @@ engine_katakana_sequences(struct ct *t)
|
||||
if(!typekeys(t, cases[i].keys, &com))
|
||||
continue;
|
||||
checkstr(t, cases[i].keys, "", &com);
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, cases[i].keys, cases[i].want, &shown);
|
||||
CT_EQ_INT(t, 0, im.nkouho);
|
||||
CT_CHECK(t, keystroke(Kret, 0, &com));
|
||||
@@ -1492,7 +1491,7 @@ engine_emoji_preedit_languages(struct ct *t)
|
||||
sclear(&com);
|
||||
if(typekeys(t, "ka", &com)){
|
||||
CT_CHECK(t, !keystroke(Kmodfirst+2, 0, &com));
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "modifier preserves Japanese", "か", &shown);
|
||||
CT_CHECK(t, keystroke('E', Mctrl|Mshift, &com));
|
||||
checkstr(t, "committed Japanese preedit", "か", &com);
|
||||
@@ -1513,7 +1512,7 @@ engine_emoji_preedit_languages(struct ct *t)
|
||||
CT_CHECK(t, !search.lang);
|
||||
sclear(&com);
|
||||
if(typekeys(t, "na", &com)){
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "Japanese resumed", "な", &shown);
|
||||
}
|
||||
}
|
||||
@@ -1544,7 +1543,7 @@ engine_emoji_preedit_languages(struct ct *t)
|
||||
CT_EQ_PTR(t, &testvi, im.l);
|
||||
sclear(&com);
|
||||
if(typekeys(t, "as", &com)){
|
||||
shown = shownpre(&im);
|
||||
impre(&im, &shown);
|
||||
checkstr(t, "Telex resumed", "á", &shown);
|
||||
checkstr(t, "Telex raw resumed", "as", &im.raw);
|
||||
}
|
||||
|
||||
@@ -3,22 +3,10 @@
|
||||
static Str
|
||||
kotrans(char *keys)
|
||||
{
|
||||
Emit e;
|
||||
Im state;
|
||||
Str out;
|
||||
char *p;
|
||||
Str out, raw;
|
||||
|
||||
memset(&state, 0, sizeof state);
|
||||
state.l = getlang(LangKO);
|
||||
sclear(&out);
|
||||
for(p = keys; *p != '\0'; p++){
|
||||
e = transko(&state, (uchar)*p);
|
||||
sappend(&out, &e.s);
|
||||
state.pre = e.next;
|
||||
if(!e.eat)
|
||||
sputr(&out, (uchar)*p);
|
||||
}
|
||||
sappend(&out, &state.pre);
|
||||
raw = mkstr(keys);
|
||||
transstr(getlang(LangKO), &raw, &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ extern Lang testvi;
|
||||
|
||||
Str mkstr(char*);
|
||||
int checkstr(struct ct*, char*, char*, Str*);
|
||||
Str shownpre(Im*);
|
||||
|
||||
void str_init_utf8(struct ct*);
|
||||
void str_edit_and_alias(struct ct*);
|
||||
|
||||
@@ -20,23 +20,3 @@ checkstr(struct ct *t, char *where, char *want, Str *got)
|
||||
return CT_ERRORF(t, "%s: want \"%s\", got \"%s\"",
|
||||
where, want, buf);
|
||||
}
|
||||
|
||||
Str
|
||||
shownpre(Im *state)
|
||||
{
|
||||
Str mapped, shown;
|
||||
|
||||
if(state->l->lang == LangJP || state->l->lang == LangJPK){
|
||||
shown = state->pre;
|
||||
if(state->raw.n == 0)
|
||||
return shown;
|
||||
if(mapget(state->l->map, &state->raw, &mapped))
|
||||
sappend(&shown, &mapped);
|
||||
else
|
||||
sappend(&shown, &state->raw);
|
||||
return shown;
|
||||
}
|
||||
if(state->l->map != nil && mapget(state->l->map, &state->pre, &shown))
|
||||
return shown;
|
||||
return state->pre;
|
||||
}
|
||||
|
||||
@@ -3,24 +3,10 @@
|
||||
static void
|
||||
typevi(struct ct *t, char *keys, char *want)
|
||||
{
|
||||
Emit e;
|
||||
Im state;
|
||||
Str out, shown;
|
||||
char *p;
|
||||
Str out, raw;
|
||||
|
||||
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);
|
||||
raw = mkstr(keys);
|
||||
transstr(&testvi, &raw, &out);
|
||||
checkstr(t, keys, want, &out);
|
||||
}
|
||||
|
||||
@@ -79,7 +65,7 @@ vietnamese_backspace(struct ct *t)
|
||||
state.raw = mkstr(cases[i].raw);
|
||||
backvi(&state);
|
||||
checkstr(t, cases[i].raw, cases[i].rawafter, &state.raw);
|
||||
shown = shownpre(&state);
|
||||
impre(&state, &shown);
|
||||
checkstr(t, cases[i].raw, cases[i].after, &shown);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user