read_order must use parse_order (not create) to properly handle make temp.

This commit is contained in:
Enno Rehling 2017-09-26 18:52:26 +02:00
parent 8b39133dbf
commit 86e99a560c
2 changed files with 28 additions and 4 deletions

View File

@ -122,10 +122,11 @@ char *rns(FILE * f, char *c, size_t size)
return c;
}
struct order *read_order(const char *s, const struct locale *lang) {
assert(s);
struct order *read_order(const char *in, const struct locale *lang) {
assert(in);
assert(lang);
if (s[0]) {
if (in[0]) {
const char *s = in;
keyword_t kwd;
char token[64];
const char *stok;
@ -152,7 +153,7 @@ struct order *read_order(const char *s, const struct locale *lang) {
/* Nun wird der Befehl erzeut und eingehängt */
kwd = get_keyword(stok, lang);
if (kwd != NOKEYWORD) {
return create_order(kwd, lang, s);
return parse_order(in, lang);
}
}
return NULL;

View File

@ -469,6 +469,29 @@ static void test_read_order(CuTest *tc) {
CuAssertStrEquals(tc, "move NORTH", get_command(ord, cmd, sizeof(cmd)));
free_order(ord);
ord = read_order("MAKE TEMP foo", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertTrue(tc, !ord->_noerror);
CuAssertTrue(tc, !ord->_persistent);
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
CuAssertStrEquals(tc, "maketemp foo", get_command(ord, cmd, sizeof(cmd)));
free_order(ord);
ord = read_order("MAKETEMP foo", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertTrue(tc, !ord->_noerror);
CuAssertTrue(tc, !ord->_persistent);
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
CuAssertStrEquals(tc, "maketemp foo", get_command(ord, cmd, sizeof(cmd)));
free_order(ord);
CuAssertPtrEquals(tc, NULL, read_order("HODOR HODOR HODOR", lang));
CuAssertPtrEquals(tc, NULL, read_order("FACTION abcd", lang));
CuAssertPtrEquals(tc, NULL, read_order("UNIT abcd", lang));
CuAssertPtrEquals(tc, NULL, read_order("ERESSEA abcd", lang));
CuAssertPtrEquals(tc, NULL, read_order("REGION 2,3", lang));
CuAssertPtrEquals(tc, NULL, read_order("NEXT", lang));
test_cleanup();
}