forked from github/server
add test for keyword aliases, add keyword to strings for reverse lookup
This commit is contained in:
parent
0af5e96e3a
commit
b40ddaeaa1
|
@ -278,11 +278,15 @@ static void json_keyword(cJSON *json, struct locale *lang) {
|
||||||
if (kwd!=NOKEYWORD) {
|
if (kwd!=NOKEYWORD) {
|
||||||
if (child->type==cJSON_String) {
|
if (child->type==cJSON_String) {
|
||||||
init_keyword(lang, kwd, child->valuestring);
|
init_keyword(lang, kwd, child->valuestring);
|
||||||
|
locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring);
|
||||||
}
|
}
|
||||||
else if (child->type==cJSON_Array) {
|
else if (child->type==cJSON_Array) {
|
||||||
cJSON *entry;
|
cJSON *entry;
|
||||||
for (entry=child->child;entry;entry=entry->next) {
|
for (entry=child->child;entry;entry=entry->next) {
|
||||||
init_keyword(lang, kwd, entry->valuestring);
|
init_keyword(lang, kwd, entry->valuestring);
|
||||||
|
if ((entry==child->child)) {
|
||||||
|
locale_setstring(lang, mkname("keyword", keywords[kwd]), entry->valuestring);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_error_n("invalid type %d for keyword `%s`", child->type, child->string);
|
log_error_n("invalid type %d for keyword `%s`", child->type, child->string);
|
||||||
|
|
|
@ -169,7 +169,7 @@ static void test_directions(CuTest * tc)
|
||||||
|
|
||||||
static void test_keywords(CuTest * tc)
|
static void test_keywords(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"keywords\": { \"de\" : { \"move\" : \"nach\", \"study\" : \"lernen\" }}}";
|
const char * data = "{\"keywords\": { \"de\" : { \"move\" : \"NACH\", \"study\" : [ \"LERNEN\", \"STUDIEREN\" ] }}}";
|
||||||
const struct locale * lang;
|
const struct locale * lang;
|
||||||
|
|
||||||
cJSON *json = cJSON_Parse(data);
|
cJSON *json = cJSON_Parse(data);
|
||||||
|
@ -180,9 +180,12 @@ static void test_keywords(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
|
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
|
||||||
|
|
||||||
json_config(json);
|
json_config(json);
|
||||||
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("studiere", lang));
|
||||||
CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
|
||||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
||||||
|
|
||||||
|
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study"));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
|
||||||
if (kwd != NOKEYWORD) {
|
if (kwd != NOKEYWORD) {
|
||||||
const struct locale *lang = ORD_LOCALE(ord);
|
const struct locale *lang = ORD_LOCALE(ord);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
const char *str = (const char *)LOC(lang, keywords[kwd]);
|
const char *str = (const char *)LOC(lang, mkname("keyword", keywords[kwd]));
|
||||||
assert(str);
|
assert(str);
|
||||||
if (text) --size;
|
if (text) --size;
|
||||||
bytes = (int)strlcpy(bufp, str, size);
|
bytes = (int)strlcpy(bufp, str, size);
|
||||||
|
|
|
@ -53,8 +53,9 @@ void init_tokens_str(const char *initstr, char *cmd)
|
||||||
{
|
{
|
||||||
if (states == NULL) {
|
if (states == NULL) {
|
||||||
states = malloc(sizeof(parser_state));
|
states = malloc(sizeof(parser_state));
|
||||||
} else if (states->current_cmd)
|
} else if (states->current_cmd) {
|
||||||
free(states->current_cmd);
|
free(states->current_cmd);
|
||||||
|
}
|
||||||
states->current_cmd = cmd;
|
states->current_cmd = cmd;
|
||||||
states->current_token = initstr;
|
states->current_token = initstr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue