2014-06-16 17:01:59 +02:00
|
|
|
#include <platform.h>
|
2014-09-19 19:49:44 +02:00
|
|
|
#include "kernel/config.h"
|
2014-10-23 16:37:00 +02:00
|
|
|
#include "kernel/order.h"
|
2014-06-16 17:01:59 +02:00
|
|
|
#include "keyword.h"
|
|
|
|
#include "util/language.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
2014-09-19 19:49:44 +02:00
|
|
|
#include <critbit.h>
|
2014-06-16 17:01:59 +02:00
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
static void test_init_keywords(CuTest *tc) {
|
|
|
|
struct locale *lang;
|
|
|
|
|
2016-11-14 02:21:49 +01:00
|
|
|
test_setup();
|
2014-06-16 17:01:59 +02:00
|
|
|
lang = get_or_create_locale("en");
|
2014-06-17 04:12:55 +02:00
|
|
|
locale_setstring(lang, "keyword::move", "MOVE");
|
2014-06-16 17:01:59 +02:00
|
|
|
init_keywords(lang);
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, get_keyword("move", lang));
|
2016-11-14 02:21:49 +01:00
|
|
|
CuAssertStrEquals(tc, "keyword::move", keyword(K_MOVE));
|
|
|
|
CuAssertPtrEquals(tc, NULL, (void *)keyword(NOKEYWORD));
|
2014-06-16 17:01:59 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-10-23 16:14:01 +02:00
|
|
|
static void test_infinitive(CuTest *tc) {
|
2014-10-23 16:37:00 +02:00
|
|
|
char buffer[32];
|
2014-10-23 16:14:01 +02:00
|
|
|
struct locale *lang;
|
2014-10-23 16:37:00 +02:00
|
|
|
struct order *ord;
|
2014-10-23 16:14:01 +02:00
|
|
|
test_cleanup();
|
|
|
|
|
|
|
|
lang = get_or_create_locale("de");
|
2014-10-23 16:37:00 +02:00
|
|
|
locale_setstring(lang, "keyword::study", "LERNE");
|
|
|
|
init_keyword(lang, K_STUDY, "LERNE");
|
2014-10-23 16:14:01 +02:00
|
|
|
init_keyword(lang, K_STUDY, "LERNEN");
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERN", lang));
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNE", lang));
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang));
|
2014-10-23 16:37:00 +02:00
|
|
|
|
|
|
|
ord = create_order(K_STUDY, lang, "");
|
|
|
|
CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer)));
|
2015-10-13 15:45:38 +02:00
|
|
|
free_order(ord);
|
2014-10-23 16:14:01 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
static void test_init_keyword(CuTest *tc) {
|
|
|
|
struct locale *lang;
|
|
|
|
test_cleanup();
|
|
|
|
|
|
|
|
lang = get_or_create_locale("de");
|
2014-06-17 04:12:55 +02:00
|
|
|
init_keyword(lang, K_MOVE, "NACH");
|
|
|
|
init_keyword(lang, K_STUDY, "LERNEN");
|
2014-06-16 17:01:59 +02:00
|
|
|
init_keyword(lang, K_DESTROY, "ZERSTOEREN");
|
|
|
|
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
2014-06-17 04:12:55 +02:00
|
|
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERN", lang));
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang));
|
2014-06-16 17:01:59 +02:00
|
|
|
CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
|
2014-06-17 04:12:55 +02:00
|
|
|
CuAssertIntEquals(tc, K_DESTROY, get_keyword("zerst\xC3\xB6ren", lang));
|
2014-06-16 17:01:59 +02:00
|
|
|
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_findkeyword(CuTest *tc) {
|
|
|
|
test_cleanup();
|
2014-06-17 04:12:55 +02:00
|
|
|
CuAssertIntEquals(tc, K_MOVE, findkeyword("move"));
|
|
|
|
CuAssertIntEquals(tc, K_STUDY, findkeyword("study"));
|
2014-06-16 17:01:59 +02:00
|
|
|
CuAssertIntEquals(tc, NOKEYWORD, findkeyword(""));
|
|
|
|
CuAssertIntEquals(tc, NOKEYWORD, findkeyword("potato"));
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
2014-06-16 17:01:59 +02:00
|
|
|
}
|
|
|
|
|
2014-09-19 19:49:44 +02:00
|
|
|
static void test_get_shortest_match(CuTest *tc) {
|
|
|
|
struct locale *lang;
|
|
|
|
critbit_tree ** cb;
|
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
lang = get_or_create_locale("en");
|
|
|
|
|
|
|
|
cb = (critbit_tree **)get_translations(lang, UT_KEYWORDS);
|
|
|
|
/* note that the english order is FIGHT, not COMBAT, so this is a poor example */
|
|
|
|
add_translation(cb, "COMBAT", K_STATUS);
|
|
|
|
add_translation(cb, "COMBATSPELL", K_COMBATSPELL);
|
|
|
|
|
|
|
|
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("", lang));
|
|
|
|
CuAssertIntEquals(tc, K_STATUS, get_keyword("COM", lang));
|
|
|
|
CuAssertIntEquals(tc, K_STATUS, get_keyword("COMBAT", lang));
|
|
|
|
CuAssertIntEquals(tc, K_COMBATSPELL, get_keyword("COMBATS", lang));
|
2014-12-12 11:13:25 +01:00
|
|
|
test_cleanup();
|
2014-09-19 19:49:44 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
CuSuite *get_keyword_suite(void)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_infinitive);
|
|
|
|
SUITE_ADD_TEST(suite, test_init_keyword);
|
|
|
|
SUITE_ADD_TEST(suite, test_init_keywords);
|
|
|
|
SUITE_ADD_TEST(suite, test_findkeyword);
|
|
|
|
SUITE_ADD_TEST(suite, test_get_shortest_match);
|
|
|
|
return suite;
|
2014-06-16 17:01:59 +02:00
|
|
|
}
|