Skip to content

Commit deaed8d

Browse files
committed
Better test coverage
1 parent 9f254ac commit deaed8d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ following routines:
2222

2323
Printing to a buffer: https://github.com/cesanta/str/blob/873b39dd14b074bf0779f5d06f5c5bfe3bcb416b/test/main.c#L174-L177
2424

25-
Print to the UART, JSON and base64 format: https://github.com/cesanta/str/blob/7e05d658a0f89b2bda67dda8cc1a912d0e2b7cba/test/main.ino#L11-L12
25+
Print to the UART. Use JSON and base64 format: https://github.com/cesanta/str/blob/7e05d658a0f89b2bda67dda8cc1a912d0e2b7cba/test/main.ino#L11-L12
2626

2727
Parse JSON: https://github.com/cesanta/str/blob/813e08acf4e389690830bfb5ff525c9e79bdb362/test/main.c#L183-L190
2828

test/main.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ static void test_m(void) {
181181

182182
static void test_json(void) {
183183
char buf[100];
184-
const char *json = "{ \"a\": -42, \"b\": \"hi\", \"c\": true }";
185-
int b = 0;
186-
assert(json_get_long(json, (int) strlen(json), "$.a", 0) == -42);
187-
assert(json_get_str(json, (int) strlen(json), "$.b", buf, sizeof(buf)) == 2);
188-
assert(strcmp(buf, "hi") == 0);
189-
assert(json_get_bool(json, (int) strlen(json), "$.c", &b) == 1);
184+
const char *json = "{ \"a\": -42, \"b\": [ \"hi\\t\\u0020\", true, { } ] }";
185+
int ofs, n, b = 0, len = (int) strlen(json);
186+
assert(json_get_long(json, len, "$.a", 0) == -42);
187+
assert(json_get_str(json, len, "$.b[0]", buf, sizeof(buf)) == 4);
188+
assert(strcmp(buf, "hi\t ") == 0);
189+
assert(json_get_bool(json, len, "$.b[1]", &b) == 1);
190190
assert(b == 1);
191+
assert(json_get(json, len, "$.c", &n) < 0);
192+
assert((ofs = json_get(json, len, "$.b[2]", &n)) > 0 && n == 3 &&
193+
json[ofs] == '{' && json[ofs + 2] == '}');
191194
}
192195

193196
int main(void) {

0 commit comments

Comments
 (0)