Files
strans/tests/dict_test.c
Hojun-Cho 795f11be22 test: one engine pump and one preedit check for the white-box suites
server_test, ibus_test and xim_adapter_test each ran their own copy of
the same alt loop that stands in for imthread, and two of them had
private checkstr/checkenginepreedit variants. test_util.c now provides
Pump (trace, optional hold on a chosen op, stop) in its own proc so a
test may block in socket I/O while the engine runs, and test.h declares
the engine hooks once; every .c includes dat.h and fn.h itself as the
rest of the tree does. server_test's three copies of fixture setup and
teardown became serverbegin/serverend.
2026-08-16 16:30:32 +09:00

83 lines
2.0 KiB
C

#include "dat.h"
#include "fn.h"
#include "test.h"
void
dictionary_candidates(struct ct *t)
{
char many[512], item[8];
char *p;
Str kouho[Maxkouho], key;
Trie *saved;
Lang *lang;
int i, n;
lang = getlang(LangJP);
saved = lang->dict;
lang->dict = trienew();
trieput(lang->dict, "かな", strlen("かな"), " 候補1 かな 候補2 ",
strlen(" 候補1 かな 候補2 "));
key = mkstr("かな");
n = dictlookup(lang, &key, kouho, Maxkouho);
if(CT_EQ_INT(t, 2, n)){
checkstr(t, "candidate 1", "候補1", &kouho[0]);
checkstr(t, "candidate 2", "候補2", &kouho[1]);
}
p = many;
for(i = 0; i < Maxkouho+1; i++){
snprint(item, sizeof item, "c%02d", i);
if(i > 0)
*p++ = ' ';
memmove(p, item, strlen(item));
p += strlen(item);
}
*p = '\0';
trieput(lang->dict, "key", 3, many, strlen(many));
key = mkstr("key");
n = dictlookup(lang, &key, kouho, Maxkouho);
if(CT_EQ_INT(t, Maxkouho, n)){
checkstr(t, "first capped candidate", "c00", &kouho[0]);
checkstr(t, "last capped candidate", "c31", &kouho[31]);
}
CT_EQ_INT(t, 3, dictlookup(lang, &key, kouho, 3));
trieclose(lang->dict);
lang->dict = saved;
}
void
dictionary_misses(struct ct *t)
{
Str kouho[Maxkouho], key;
Trie *saved;
Lang *lang;
lang = getlang(LangJP);
saved = lang->dict;
lang->dict = trienew();
key = mkstr("");
CT_EQ_INT(t, 0, dictlookup(lang, &key, kouho, Maxkouho));
key = mkstr("missing");
CT_EQ_INT(t, 0, dictlookup(lang, &key, kouho, Maxkouho));
CT_EQ_INT(t, 0, dictlookup(getlang(LangKO), &key, kouho, Maxkouho));
trieclose(lang->dict);
lang->dict = saved;
}
void
dictionary_emoji_identity(struct ct *t)
{
Str kouho[Maxkouho], key;
Trie *saved;
Lang *lang;
lang = getlang(LangEMOJI);
saved = lang->dict;
lang->dict = trienew();
trieput(lang->dict, "é", strlen("é"), "é", strlen("é"));
key = mkstr("é");
if(CT_EQ_INT(t, 1, dictlookup(lang, &key, kouho, Maxkouho)))
checkstr(t, "emoji identity candidate", "é", &kouho[0]);
trieclose(lang->dict);
lang->dict = saved;
}