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:
2
fn.h
2
fn.h
@@ -29,6 +29,8 @@ int pagemarker(char*, int, int, int, int);
|
|||||||
void popuplayout(Drawcmd*, int, int, Popup*);
|
void popuplayout(Drawcmd*, int, int, Popup*);
|
||||||
void popupdraw(u32int*, Drawcmd*, Popup*);
|
void popupdraw(u32int*, Drawcmd*, Popup*);
|
||||||
void imthread(void*);
|
void imthread(void*);
|
||||||
|
void impre(Im*, Str*);
|
||||||
|
void transstr(Lang*, Str*, Str*);
|
||||||
Emit transmap(Im*, Rune);
|
Emit transmap(Im*, Rune);
|
||||||
Emit transko(Im*, Rune);
|
Emit transko(Im*, Rune);
|
||||||
Emit transvi(Im*, Rune);
|
Emit transvi(Im*, Rune);
|
||||||
|
|||||||
18
strans.c
18
strans.c
@@ -148,13 +148,13 @@ haspre(Im *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The preedit as clients see it: Telex keys read back through the map. */
|
/* The preedit as clients see it: Telex keys read back through the map. */
|
||||||
static void
|
void
|
||||||
impre(Str *s)
|
impre(Im *p, Str *s)
|
||||||
{
|
{
|
||||||
if(isjp(&im))
|
if(isjp(p))
|
||||||
jpreading(im.l->map, &im.pre, &im.raw, s);
|
jpreading(p->l->map, &p->pre, &p->raw, s);
|
||||||
else if(!mapget(im.l->map, &im.pre, s))
|
else if(!mapget(p->l->map, &p->pre, s))
|
||||||
*s = im.pre;
|
*s = p->pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -167,7 +167,7 @@ snapshot(Drawcmd *dc)
|
|||||||
if(search.lang)
|
if(search.lang)
|
||||||
pre = search.text;
|
pre = search.text;
|
||||||
else
|
else
|
||||||
impre(&pre);
|
impre(&im, &pre);
|
||||||
if(!(activecap & Cclientpreedit))
|
if(!(activecap & Cclientpreedit))
|
||||||
dc->pre = pre;
|
dc->pre = pre;
|
||||||
first = pagefirst();
|
first = pagefirst();
|
||||||
@@ -456,7 +456,7 @@ foldascii(Str *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* What typing raw in language l would produce, composition included. */
|
/* What typing raw in language l would produce, composition included. */
|
||||||
static void
|
void
|
||||||
transstr(Lang *l, Str *raw, Str *out)
|
transstr(Lang *l, Str *raw, Str *out)
|
||||||
{
|
{
|
||||||
Im q;
|
Im q;
|
||||||
@@ -827,7 +827,7 @@ imhandlekey(Keyreq *kr)
|
|||||||
if(search.lang)
|
if(search.lang)
|
||||||
res.preedit = search.text;
|
res.preedit = search.text;
|
||||||
else
|
else
|
||||||
impre(&res.preedit);
|
impre(&im, &res.preedit);
|
||||||
}
|
}
|
||||||
chansend(kr->reply, &res);
|
chansend(kr->reply, &res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ extern Lang testvi;
|
|||||||
|
|
||||||
Str mkstr(char*);
|
Str mkstr(char*);
|
||||||
int checkstr(struct ct*, char*, char*, Str*);
|
int checkstr(struct ct*, char*, char*, Str*);
|
||||||
Str shownpre(Im*);
|
|
||||||
|
|
||||||
static int typekeys(struct ct*, char*, Str*);
|
static int typekeys(struct ct*, char*, Str*);
|
||||||
static int draindraw(Drawcmd*);
|
static int draindraw(Drawcmd*);
|
||||||
@@ -43,7 +42,7 @@ testengineowner(void)
|
|||||||
void
|
void
|
||||||
testenginepreedit(Str *preedit)
|
testenginepreedit(Str *preedit)
|
||||||
{
|
{
|
||||||
impre(preedit);
|
impre(&im, preedit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -116,7 +115,7 @@ engine_backspace_clears_candidates(struct ct *t)
|
|||||||
sclear(&com);
|
sclear(&com);
|
||||||
CT_CHECK(t, keystroke('n', 0, &com));
|
CT_CHECK(t, keystroke('n', 0, &com));
|
||||||
CT_CHECK(t, keystroke('a', 0, &com));
|
CT_CHECK(t, keystroke('a', 0, &com));
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "before backspace", "な", &shown);
|
checkstr(t, "before backspace", "な", &shown);
|
||||||
im.kouho[0] = mkstr("stale-candidate");
|
im.kouho[0] = mkstr("stale-candidate");
|
||||||
im.nkouho = 1;
|
im.nkouho = 1;
|
||||||
@@ -124,7 +123,7 @@ engine_backspace_clears_candidates(struct ct *t)
|
|||||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||||
checkstr(t, "backspace commit", "", &com);
|
checkstr(t, "backspace commit", "", &com);
|
||||||
checkstr(t, "pending romaji after backspace", "n", &im.raw);
|
checkstr(t, "pending romaji after backspace", "n", &im.raw);
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "shown preedit after backspace", "ん", &shown);
|
checkstr(t, "shown preedit after backspace", "ん", &shown);
|
||||||
CT_EQ_INT(t, 0, im.nkouho);
|
CT_EQ_INT(t, 0, im.nkouho);
|
||||||
CT_EQ_INT(t, -1, im.sel);
|
CT_EQ_INT(t, -1, im.sel);
|
||||||
@@ -238,7 +237,7 @@ engine_active_owner_lifecycle(struct ct *t)
|
|||||||
CT_EQ_PTR(t, &b, activeowner);
|
CT_EQ_PTR(t, &b, activeowner);
|
||||||
res = ownerrequest(&a, Keyreset, 0, 0);
|
res = ownerrequest(&a, Keyreset, 0, 0);
|
||||||
CT_EQ_INT(t, 0, res.preedit.n);
|
CT_EQ_INT(t, 0, res.preedit.n);
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "stale reset preserves owner", "ん", &shown);
|
checkstr(t, "stale reset preserves owner", "ん", &shown);
|
||||||
CT_EQ_PTR(t, &b, activeowner);
|
CT_EQ_PTR(t, &b, activeowner);
|
||||||
|
|
||||||
@@ -246,7 +245,7 @@ engine_active_owner_lifecycle(struct ct *t)
|
|||||||
res = ownerrequest(&b, Keypress, 'a', 0);
|
res = ownerrequest(&b, Keypress, 'a', 0);
|
||||||
checkstr(t, "current owner continues", "にゃ", &res.preedit);
|
checkstr(t, "current owner continues", "にゃ", &res.preedit);
|
||||||
ownerrequest(&a, Keyrelease, 0, 0);
|
ownerrequest(&a, Keyrelease, 0, 0);
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "stale release preserves owner", "にゃ", &shown);
|
checkstr(t, "stale release preserves owner", "にゃ", &shown);
|
||||||
CT_EQ_PTR(t, &b, activeowner);
|
CT_EQ_PTR(t, &b, activeowner);
|
||||||
|
|
||||||
@@ -1074,7 +1073,7 @@ engine_japanese_readings(struct ct *t)
|
|||||||
if(!typekeys(t, cases[i].keys, &com))
|
if(!typekeys(t, cases[i].keys, &com))
|
||||||
continue;
|
continue;
|
||||||
checkstr(t, cases[i].keys, "", &com);
|
checkstr(t, cases[i].keys, "", &com);
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, cases[i].keys, cases[i].want, &shown);
|
checkstr(t, cases[i].keys, cases[i].want, &shown);
|
||||||
CT_CHECK(t, keystroke(Kret, 0, &com));
|
CT_CHECK(t, keystroke(Kret, 0, &com));
|
||||||
checkstr(t, "committed reading", cases[i].want, &com);
|
checkstr(t, "committed reading", cases[i].want, &com);
|
||||||
@@ -1102,7 +1101,7 @@ engine_japanese_candidates(struct ct *t)
|
|||||||
sclear(&com);
|
sclear(&com);
|
||||||
if(!typekeys(t, "kanji", &com))
|
if(!typekeys(t, "kanji", &com))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "complete Japanese reading", "かんじ", &shown);
|
checkstr(t, "complete Japanese reading", "かんじ", &shown);
|
||||||
if(!CT_EQ_INT(t, 2, im.nkouho))
|
if(!CT_EQ_INT(t, 2, im.nkouho))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -1138,13 +1137,13 @@ engine_japanese_backspace_and_boundaries(struct ct *t)
|
|||||||
sclear(&com);
|
sclear(&com);
|
||||||
if(typekeys(t, "kanji", &com)){
|
if(typekeys(t, "kanji", &com)){
|
||||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "backspace pending i", "かんj", &shown);
|
checkstr(t, "backspace pending i", "かんj", &shown);
|
||||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "backspace pending j", "かん", &shown);
|
checkstr(t, "backspace pending j", "かん", &shown);
|
||||||
CT_CHECK(t, keystroke(Kback, 0, &com));
|
CT_CHECK(t, keystroke(Kback, 0, &com));
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "backspace accumulated kana", "か", &shown);
|
checkstr(t, "backspace accumulated kana", "か", &shown);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1198,7 +1197,7 @@ engine_katakana_sequences(struct ct *t)
|
|||||||
if(!typekeys(t, cases[i].keys, &com))
|
if(!typekeys(t, cases[i].keys, &com))
|
||||||
continue;
|
continue;
|
||||||
checkstr(t, cases[i].keys, "", &com);
|
checkstr(t, cases[i].keys, "", &com);
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, cases[i].keys, cases[i].want, &shown);
|
checkstr(t, cases[i].keys, cases[i].want, &shown);
|
||||||
CT_EQ_INT(t, 0, im.nkouho);
|
CT_EQ_INT(t, 0, im.nkouho);
|
||||||
CT_CHECK(t, keystroke(Kret, 0, &com));
|
CT_CHECK(t, keystroke(Kret, 0, &com));
|
||||||
@@ -1492,7 +1491,7 @@ engine_emoji_preedit_languages(struct ct *t)
|
|||||||
sclear(&com);
|
sclear(&com);
|
||||||
if(typekeys(t, "ka", &com)){
|
if(typekeys(t, "ka", &com)){
|
||||||
CT_CHECK(t, !keystroke(Kmodfirst+2, 0, &com));
|
CT_CHECK(t, !keystroke(Kmodfirst+2, 0, &com));
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "modifier preserves Japanese", "か", &shown);
|
checkstr(t, "modifier preserves Japanese", "か", &shown);
|
||||||
CT_CHECK(t, keystroke('E', Mctrl|Mshift, &com));
|
CT_CHECK(t, keystroke('E', Mctrl|Mshift, &com));
|
||||||
checkstr(t, "committed Japanese preedit", "か", &com);
|
checkstr(t, "committed Japanese preedit", "か", &com);
|
||||||
@@ -1513,7 +1512,7 @@ engine_emoji_preedit_languages(struct ct *t)
|
|||||||
CT_CHECK(t, !search.lang);
|
CT_CHECK(t, !search.lang);
|
||||||
sclear(&com);
|
sclear(&com);
|
||||||
if(typekeys(t, "na", &com)){
|
if(typekeys(t, "na", &com)){
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "Japanese resumed", "な", &shown);
|
checkstr(t, "Japanese resumed", "な", &shown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1544,7 +1543,7 @@ engine_emoji_preedit_languages(struct ct *t)
|
|||||||
CT_EQ_PTR(t, &testvi, im.l);
|
CT_EQ_PTR(t, &testvi, im.l);
|
||||||
sclear(&com);
|
sclear(&com);
|
||||||
if(typekeys(t, "as", &com)){
|
if(typekeys(t, "as", &com)){
|
||||||
shown = shownpre(&im);
|
impre(&im, &shown);
|
||||||
checkstr(t, "Telex resumed", "á", &shown);
|
checkstr(t, "Telex resumed", "á", &shown);
|
||||||
checkstr(t, "Telex raw resumed", "as", &im.raw);
|
checkstr(t, "Telex raw resumed", "as", &im.raw);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,10 @@
|
|||||||
static Str
|
static Str
|
||||||
kotrans(char *keys)
|
kotrans(char *keys)
|
||||||
{
|
{
|
||||||
Emit e;
|
Str out, raw;
|
||||||
Im state;
|
|
||||||
Str out;
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
memset(&state, 0, sizeof state);
|
raw = mkstr(keys);
|
||||||
state.l = getlang(LangKO);
|
transstr(getlang(LangKO), &raw, &out);
|
||||||
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);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ extern Lang testvi;
|
|||||||
|
|
||||||
Str mkstr(char*);
|
Str mkstr(char*);
|
||||||
int checkstr(struct ct*, char*, char*, Str*);
|
int checkstr(struct ct*, char*, char*, Str*);
|
||||||
Str shownpre(Im*);
|
|
||||||
|
|
||||||
void str_init_utf8(struct ct*);
|
void str_init_utf8(struct ct*);
|
||||||
void str_edit_and_alias(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\"",
|
return CT_ERRORF(t, "%s: want \"%s\", got \"%s\"",
|
||||||
where, want, buf);
|
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
|
static void
|
||||||
typevi(struct ct *t, char *keys, char *want)
|
typevi(struct ct *t, char *keys, char *want)
|
||||||
{
|
{
|
||||||
Emit e;
|
Str out, raw;
|
||||||
Im state;
|
|
||||||
Str out, shown;
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
memset(&state, 0, sizeof state);
|
raw = mkstr(keys);
|
||||||
state.l = &testvi;
|
transstr(&testvi, &raw, &out);
|
||||||
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);
|
checkstr(t, keys, want, &out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +65,7 @@ vietnamese_backspace(struct ct *t)
|
|||||||
state.raw = mkstr(cases[i].raw);
|
state.raw = mkstr(cases[i].raw);
|
||||||
backvi(&state);
|
backvi(&state);
|
||||||
checkstr(t, cases[i].raw, cases[i].rawafter, &state.raw);
|
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);
|
checkstr(t, cases[i].raw, cases[i].after, &shown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user