Browse Source

Apply https://github.com/cesanta/frozen/pull/27

CL: frozen/pull/27 - fix json_setf

PUBLISHED_FROM=95704b536b9d2c5c8af1c2eda529053334af617d
Sergey Lyubka 7 years ago
parent
commit
b2745ad46f
1 changed files with 10 additions and 0 deletions
  1. 10 0
      unit_test.c

+ 10 - 0
unit_test.c

@@ -760,6 +760,16 @@ static const char *test_json_setf(void) {
     ASSERT(strcmp(buf, s2) == 0);
   }
 
+  {
+    /* Add Key with length > 1 */
+    struct json_out out = JSON_OUT_BUF(buf, sizeof(buf));
+    const char *s2 =
+        "{ \"a\": 123, \"b\": [ 1 ], \"c\": true,\"foo\":{\"bar\":42} }";
+    int res = json_setf(s1, strlen(s1), &out, ".foo.bar", "%d", 42);
+    ASSERT(res == 0);
+    ASSERT(strcmp(buf, s2) == 0);
+  }
+
   {
     struct json_out out = JSON_OUT_BUF(buf, sizeof(buf));
     const char *s2 = "{ \"a\": 123, \"b\": false, \"c\": true }";