diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2024-08-22 00:02:48 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2024-08-23 20:40:01 +0100 |
commit | cf0354eb8e043fcd9c6c17756701972f948a16f1 (patch) | |
tree | de931afc161f43e95d040ae655a6a2081aeb4ff2 /test | |
parent | 78323e416f79ef9c26bbd742082627bc45e116c1 (diff) |
Rewrite the gamedata and entprops systems entirely
This removes the horrible janky old KeyValues parser and replaces it
with a couple of trivial ad-hoc text parsers. In doing so, make the
format of the actual gamedata files more human-friendly too.
We also gain support for nested SendTables in mkentprops, which are
required to get at various things like player velocity. And, the actual
string matching is made more efficient (or, at least, more scalable) by
way of a cool radix tree thing which generates a bunch of switch cases
on distinct characters.
Diffstat (limited to 'test')
-rw-r--r-- | test/kv.test.c | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/test/kv.test.c b/test/kv.test.c deleted file mode 100644 index 1bd1784..0000000 --- a/test/kv.test.c +++ /dev/null @@ -1,55 +0,0 @@ -/* This file is dedicated to the public domain. */ - -{.desc = "the KeyValues parser"}; - -// undef conflicting macros -#undef ERROR // windows.h -#undef OUT // " -#undef EOF // stdio.h -#include "../src/kv.c" - -#include "../src/intdefs.h" -#include "../src/langext.h" - -static noreturn die(const struct kv_parser *kvp) { - fprintf(stderr, "parse error: %d:%d: %s\n", kvp->line, kvp->col, - kvp->errmsg); - exit(1); -} - -static void tokcb(enum kv_token type, const char *p, uint len, - void *ctxt) { - // nop - we're just testing the tokeniser -} - -static const char data[] = -"KeyValues {\n\ - Key/1 Val1![conditional]\n\ - Key2\n\ -Val2// comment\n\ - \"String Key\" // also comment\n\ - Val3 Key4 [conditional!]{ Key5 \"Value Five\" } // one more\n\ -} \n\ -"; -static const int sz = sizeof(data) - 1; - -TEST("parsing should work with any buffer size") { - for (int chunksz = 3; chunksz <= sz; ++chunksz) { - struct kv_parser kvp = {0}; - // sending data in chunks to test reentrancy - for (int chunk = 0; chunk * chunksz < sz; ++chunk) { - int thischunk = chunksz; - if (chunk * chunksz + thischunk > sz) { - thischunk = sz - chunk * chunksz; - } - if (!kv_parser_feed(&kvp, data + chunk * chunksz, thischunk, - tokcb, 0)) { - die(&kvp); - } - } - if (!kv_parser_done(&kvp)) die(&kvp); - } - return true; -} - -// vi: sw=4 ts=4 noet tw=80 cc=80 |