Repair MAKE, which broke when I changed MAKE TEMP.

You can now also write MAKETEMP as one word, and we treat it that way.
Added unit test coverage for MAKE order parsing.
This commit is contained in:
Enno Rehling 2014-08-17 14:24:19 +02:00
parent 99124f3d6d
commit 59ccf23db6
7 changed files with 84 additions and 19 deletions

View File

@ -1989,8 +1989,8 @@
<string name="STUFE">
<text locale="de">STUFE</text>
</string>
<string name="TEMPORAERE">
<text locale="de">TEMPORÄRE</text>
<string name="TEMP">
<text locale="de">TEMP</text>
</string>
<string name="TRAENKE">
<text locale="de">TRÄNKE</text>
@ -2198,7 +2198,7 @@
<text locale="de">MACHEN</text>
</string>
<string name="maketemp">
<text locale="de">MACHE TEMP</text>
<text locale="de">MACHETEMP</text>
</string>
<string name="move">
<text locale="de">NACH</text>

View File

@ -1274,7 +1274,7 @@
<string name="STUFE">
<text locale="en">LEVEL</text>
</string>
<string name="TEMPORAERE">
<string name="TEMP">
<text locale="en">TEMPORARY</text>
</string>
<string name="TRAENKE">
@ -1476,7 +1476,7 @@
<text locale="en">MAKE</text>
</string>
<string name="maketemp">
<text locale="de">MAKE TEMP</text>
<text locale="de">MAKETEMP</text>
</string>
<string name="move">
<text locale="en">MOVE</text>

View File

@ -346,7 +346,7 @@ const char *parameters[MAXPARAMS] = {
"SCHIFF",
"SILBER",
"STRASSEN",
"TEMPORAERE",
"TEMP",
"FLIEHE",
"GEBAEUDE",
"GIB", /* Für HELFE */
@ -1791,7 +1791,7 @@ void init_options_translation(const struct locale * lang) {
}
}
static void init_locale(const struct locale *lang)
void init_locale(const struct locale *lang)
{
variant var;
int i;

View File

@ -180,6 +180,7 @@ extern "C" {
int distribute(int old, int new_value, int n);
void init_locales(void);
void init_locale(const struct locale *lang);
int newunitid(void);
int forbiddenid(int id);

View File

@ -359,9 +359,11 @@ order *parse_order(const char *s, const struct locale * lang)
sptr = s;
kwd = get_keyword(parse_token(&sptr), lang);
if (kwd == K_MAKE) {
const char *s = parse_token(&sptr);
const char *s, *sp = sptr;
s = parse_token(&sp);
if (isparam(s, lang, P_TEMP)) {
kwd = K_MAKETEMP;
sptr = sp;
}
}
if (kwd != NOKEYWORD) {

View File

@ -1,4 +1,5 @@
#include <config.h>
#include <kernel/config.h>
#include "order.h"
#include <util/parser.h>
@ -39,10 +40,71 @@ static void test_parse_order(CuTest *tc) {
free_order(ord);
}
static void test_parse_make(CuTest *tc) {
char cmd[32];
order *ord;
struct locale * lang = get_or_create_locale("en");
locale_setstring(lang, keyword(K_MAKE), "MAKE");
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
init_locale(lang);
ord = parse_order("M hurrdurr", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_MAKE, getkeyword(ord));
init_tokens(ord);
CuAssertStrEquals(tc, "MAKE hurrdurr", get_command(ord, cmd, sizeof(cmd)));
CuAssertStrEquals(tc, "MAKE", getstrtoken());
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
free_order(ord);
}
static void test_parse_make_temp(CuTest *tc) {
char cmd[32];
order *ord;
struct locale * lang = get_or_create_locale("en");
locale_setstring(lang, keyword(K_MAKE), "MAKE");
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
locale_setstring(lang, "TEMP", "TEMP");
init_locale(lang);
ord = parse_order("M T herp", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
init_tokens(ord);
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
CuAssertStrEquals(tc, "MAKETEMP", getstrtoken());
CuAssertStrEquals(tc, "herp", getstrtoken());
free_order(ord);
}
static void test_parse_maketemp(CuTest *tc) {
char cmd[32];
order *ord;
struct locale * lang = get_or_create_locale("en");
locale_setstring(lang, keyword(K_MAKE), "MAKE");
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
locale_setstring(lang, "TEMP", "TEMP");
init_locale(lang);
ord = parse_order("MAKET herp", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
init_tokens(ord);
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
CuAssertStrEquals(tc, "MAKETEMP", getstrtoken());
CuAssertStrEquals(tc, "herp", getstrtoken());
free_order(ord);
}
CuSuite *get_order_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_create_order);
SUITE_ADD_TEST(suite, test_parse_order);
SUITE_ADD_TEST(suite, test_parse_make);
SUITE_ADD_TEST(suite, test_parse_make_temp);
SUITE_ADD_TEST(suite, test_parse_maketemp);
return suite;
}

View File

@ -7,19 +7,19 @@
#define SMAXHASH 2048
typedef struct locale_str {
unsigned int hashkey;
struct locale_str *nexthash;
char *str;
char *key;
unsigned int hashkey;
struct locale_str *nexthash;
char *str;
char *key;
} locale_str;
typedef struct locale {
unsigned int index;
struct locale *next;
unsigned int hashkey;
const char *name;
struct locale_str *strings[SMAXHASH];
struct locale *fallback;
const char *name;
unsigned int index;
struct locale *next;
unsigned int hashkey;
struct locale_str *strings[SMAXHASH];
struct locale *fallback;
} locale;
extern locale *default_locale;