All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj at gmail.com>
To: iwd at lists.01.org
Subject: [PATCH 8/8] unit: add test for nested arrays
Date: Wed, 05 Jan 2022 10:46:27 -0800	[thread overview]
Message-ID: <20220105184627.329505-8-prestwoj@gmail.com> (raw)
In-Reply-To: 20220105184627.329505-1-prestwoj@gmail.com

[-- Attachment #1: Type: text/plain, Size: 1382 bytes --]

These are not yet supported, but test anyway to ensure iteration
does not work and doesn't result in any unexpected behavior.
---
 unit/test-json.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/unit/test-json.c b/unit/test-json.c
index 52e3f675..5ffd36ec 100644
--- a/unit/test-json.c
+++ b/unit/test-json.c
@@ -424,6 +424,27 @@ static void test_json_arrays(const void *data)
 	json_contents_free(c);
 }
 
+static void test_json_nested_arrays(const void *data)
+{
+	char json[] = "{\"array\":[[1, 2], [3, 4]]}";
+	int count = 0;
+	struct json_iter iter;
+	struct json_iter array;
+	struct json_contents *c = json_contents_new(json, strlen(json));
+
+	json_iter_init(&iter, c);
+	assert(json_iter_parse(&iter,
+			JSON_MANDATORY("array", JSON_ARRAY, &array),
+			JSON_UNDEFINED));
+
+	while (json_iter_next(&array))
+		count++;
+
+	assert(count == 0);
+
+	json_contents_free(c);
+}
+
 int main(int argc, char *argv[])
 {
 	l_test_init(&argc, &argv);
@@ -436,6 +457,7 @@ int main(int argc, char *argv[])
 	l_test_add("json larger object", test_json_larger_object, NULL);
 	l_test_add("json test primitives", test_json_primitives, NULL);
 	l_test_add("json test arrays", test_json_arrays, NULL);
+	l_test_add("json test nested arrays", test_json_nested_arrays, NULL);
 
 	return l_test_run();
 }
-- 
2.31.1

                 reply	other threads:[~2022-01-05 18:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105184627.329505-8-prestwoj@gmail.com \
    --to=unknown@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.