diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-02-24 00:47:05 +0000 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-03-19 03:51:45 +0000 |
commit | 6818b362a776f0cc5a6068ed119dc2ebcbc5a9cc (patch) | |
tree | d2f32f226229cdfce0c61540396f4a7d3a4a8ced /test | |
parent | 98378138a521fa52758f1ed3501900e6c323c474 (diff) |
Fix some old KV parser issues
- Implement conditionals in the lexer and reject or ignore them in
callbacks. This will allow something to use them later if needed.
- Make error handling less stupid (return a bool instead of using the
state struct).
Diffstat (limited to 'test')
-rw-r--r-- | test/kv.test.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/test/kv.test.c b/test/kv.test.c index cd08d16..12f2801 100644 --- a/test/kv.test.c +++ b/test/kv.test.c @@ -23,8 +23,14 @@ static void tokcb(enum kv_token type, const char *p, uint len, } static const char data[] = -"KeyValues {\n\tKey/1\tVal1! \tKey2\nVal2// comment\n\"String Key\"// also comment\nVal3 Key4{ Key5 \"Value Five\" } // one more\n\t\n}" -; +"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", 0) { @@ -36,12 +42,12 @@ TEST("parsing should work with any buffer size", 0) { if (chunk * chunksz + thischunk > sz) { thischunk = sz - chunk * chunksz; } - kv_parser_feed(&kvp, data + chunk * chunksz, thischunk, - tokcb, 0); - if (kvp.state == KV_PARSER_ERROR) die(&kvp); + if (!kv_parser_feed(&kvp, data + chunk * chunksz, thischunk, + tokcb, 0)) { + die(&kvp); + } } - kv_parser_done(&kvp); - if (kvp.state == KV_PARSER_ERROR) die(&kvp); + if (!kv_parser_done(&kvp)) die(&kvp); } return true; } |