test that whitespace is ignored when parsing orders

This commit is contained in:
Enno Rehling 2017-09-25 22:04:16 +02:00
parent 9f97ee2dd7
commit 6bf2ac34e3
2 changed files with 23 additions and 7 deletions

View File

@ -41,17 +41,17 @@ extern "C" {
} order; } order;
/* constructor */ /* constructor */
extern order *create_order(keyword_t kwd, const struct locale *lang, order *create_order(keyword_t kwd, const struct locale *lang,
const char *params, ...); const char *params, ...);
extern order *parse_order(const char *s, const struct locale *lang); order *parse_order(const char *s, const struct locale *lang);
extern void replace_order(order ** dst, order * orig, const order * src); void replace_order(order ** dst, order * orig, const order * src);
/* reference counted copies of orders: */ /* reference counted copies of orders: */
extern order *copy_order(const order * ord); order *copy_order(const order * ord);
extern void free_order(order * ord); void free_order(order * ord);
extern void free_orders(order ** olist); void free_orders(order ** olist);
extern void push_order(struct order **olist, struct order *ord); void push_order(struct order **olist, struct order *ord);
/* access functions for orders */ /* access functions for orders */
keyword_t getkeyword(const order * ord); keyword_t getkeyword(const order * ord);

View File

@ -49,24 +49,40 @@ static void test_parse_order(CuTest *tc) {
ord = parse_order("!MOVE NORTH", lang); ord = parse_order("!MOVE NORTH", lang);
CuAssertPtrNotNull(tc, ord); CuAssertPtrNotNull(tc, ord);
CuAssertPtrNotNull(tc, ord->data);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
CuAssertTrue(tc, ord->_noerror); CuAssertTrue(tc, ord->_noerror);
CuAssertTrue(tc, !ord->_persistent); CuAssertTrue(tc, !ord->_persistent);
free_order(ord); free_order(ord);
ord = parse_order("@MOVE NORTH", lang); ord = parse_order("@MOVE NORTH", lang);
CuAssertPtrNotNull(tc, ord); CuAssertPtrNotNull(tc, ord);
CuAssertPtrNotNull(tc, ord->data);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
CuAssertTrue(tc, !ord->_noerror); CuAssertTrue(tc, !ord->_noerror);
CuAssertTrue(tc, ord->_persistent); CuAssertTrue(tc, ord->_persistent);
free_order(ord); free_order(ord);
ord = parse_order("@!MOVE NORTH", lang); ord = parse_order("@!MOVE NORTH", lang);
CuAssertPtrNotNull(tc, ord); CuAssertPtrNotNull(tc, ord);
CuAssertPtrNotNull(tc, ord->data);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
CuAssertTrue(tc, ord->_noerror); CuAssertTrue(tc, ord->_noerror);
CuAssertTrue(tc, ord->_persistent); CuAssertTrue(tc, ord->_persistent);
free_order(ord); free_order(ord);
ord = parse_order("!@MOVE NORTH", lang); ord = parse_order("!@MOVE NORTH", lang);
CuAssertPtrNotNull(tc, ord); CuAssertPtrNotNull(tc, ord);
CuAssertPtrNotNull(tc, ord->data);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
CuAssertTrue(tc, ord->_noerror);
CuAssertTrue(tc, ord->_persistent);
free_order(ord);
ord = parse_order(" !@MOVE NORTH", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertPtrNotNull(tc, ord->data);
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
CuAssertTrue(tc, ord->_noerror); CuAssertTrue(tc, ord->_noerror);
CuAssertTrue(tc, ord->_persistent); CuAssertTrue(tc, ord->_persistent);
free_order(ord); free_order(ord);