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"> <string name="STUFE">
<text locale="de">STUFE</text> <text locale="de">STUFE</text>
</string> </string>
<string name="TEMPORAERE"> <string name="TEMP">
<text locale="de">TEMPORÄRE</text> <text locale="de">TEMP</text>
</string> </string>
<string name="TRAENKE"> <string name="TRAENKE">
<text locale="de">TRÄNKE</text> <text locale="de">TRÄNKE</text>

View File

@ -1274,7 +1274,7 @@
<string name="STUFE"> <string name="STUFE">
<text locale="en">LEVEL</text> <text locale="en">LEVEL</text>
</string> </string>
<string name="TEMPORAERE"> <string name="TEMP">
<text locale="en">TEMPORARY</text> <text locale="en">TEMPORARY</text>
</string> </string>
<string name="TRAENKE"> <string name="TRAENKE">

View File

@ -346,7 +346,7 @@ const char *parameters[MAXPARAMS] = {
"SCHIFF", "SCHIFF",
"SILBER", "SILBER",
"STRASSEN", "STRASSEN",
"TEMPORAERE", "TEMP",
"FLIEHE", "FLIEHE",
"GEBAEUDE", "GEBAEUDE",
"GIB", /* Für HELFE */ "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; variant var;
int i; int i;

View File

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

View File

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

View File

@ -1,4 +1,5 @@
#include <config.h> #include <config.h>
#include <kernel/config.h>
#include "order.h" #include "order.h"
#include <util/parser.h> #include <util/parser.h>
@ -39,10 +40,71 @@ static void test_parse_order(CuTest *tc) {
free_order(ord); 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 *get_order_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_create_order); SUITE_ADD_TEST(suite, test_create_order);
SUITE_ADD_TEST(suite, test_parse_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; return suite;
} }

View File

@ -14,10 +14,10 @@ typedef struct locale_str {
} locale_str; } locale_str;
typedef struct locale { typedef struct locale {
const char *name;
unsigned int index; unsigned int index;
struct locale *next; struct locale *next;
unsigned int hashkey; unsigned int hashkey;
const char *name;
struct locale_str *strings[SMAXHASH]; struct locale_str *strings[SMAXHASH];
struct locale *fallback; struct locale *fallback;
} locale; } locale;