From 6818b362a776f0cc5a6068ed119dc2ebcbc5a9cc Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 24 Feb 2022 00:47:05 +0000 Subject: 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). --- test/kv.test.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test/kv.test.c') 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; } -- cgit v1.2.3