forked from github/server
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:
parent
99124f3d6d
commit
59ccf23db6
|
@ -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>
|
||||||
|
@ -2198,7 +2198,7 @@
|
||||||
<text locale="de">MACHEN</text>
|
<text locale="de">MACHEN</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="maketemp">
|
<string name="maketemp">
|
||||||
<text locale="de">MACHE TEMP</text>
|
<text locale="de">MACHETEMP</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="move">
|
<string name="move">
|
||||||
<text locale="de">NACH</text>
|
<text locale="de">NACH</text>
|
||||||
|
|
|
@ -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">
|
||||||
|
@ -1476,7 +1476,7 @@
|
||||||
<text locale="en">MAKE</text>
|
<text locale="en">MAKE</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="maketemp">
|
<string name="maketemp">
|
||||||
<text locale="de">MAKE TEMP</text>
|
<text locale="de">MAKETEMP</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="move">
|
<string name="move">
|
||||||
<text locale="en">MOVE</text>
|
<text locale="en">MOVE</text>
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
#ifndef CLASS_LANGUAGE_STRUCT
|
#ifndef CLASS_LANGUAGE_STRUCT
|
||||||
#define CLASS_LANGUAGE_STRUCT
|
#define CLASS_LANGUAGE_STRUCT
|
||||||
|
|
||||||
/* This file should not be included by anything in the server. If you
|
/* This file should not be included by anything in the server. If you
|
||||||
* feel that you need to include it, it's a sure sign that you're trying to
|
* feel that you need to include it, it's a sure sign that you're trying to
|
||||||
* do something BAD. */
|
* do something BAD. */
|
||||||
|
|
||||||
#define SMAXHASH 2048
|
#define SMAXHASH 2048
|
||||||
typedef struct locale_str {
|
typedef struct locale_str {
|
||||||
unsigned int hashkey;
|
unsigned int hashkey;
|
||||||
struct locale_str *nexthash;
|
struct locale_str *nexthash;
|
||||||
char *str;
|
char *str;
|
||||||
char *key;
|
char *key;
|
||||||
} locale_str;
|
} locale_str;
|
||||||
|
|
||||||
typedef struct locale {
|
typedef struct locale {
|
||||||
unsigned int index;
|
const char *name;
|
||||||
struct locale *next;
|
unsigned int index;
|
||||||
unsigned int hashkey;
|
struct locale *next;
|
||||||
const char *name;
|
unsigned int hashkey;
|
||||||
struct locale_str *strings[SMAXHASH];
|
struct locale_str *strings[SMAXHASH];
|
||||||
struct locale *fallback;
|
struct locale *fallback;
|
||||||
} locale;
|
} locale;
|
||||||
|
|
||||||
extern locale *default_locale;
|
extern locale *default_locale;
|
||||||
|
|
Loading…
Reference in New Issue