From ef242750c534f91c13bac1d49b8ebcf701814dda Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Tue, 10 Jan 2023 09:49:29 +0100 Subject: vsprintf: implement %pJP for printing JSONPaths We use an array of strings to represnt a JSONPath. Add a new %pJP format specifier that can be used to print them. This is useful for error messages when the lookup fails. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20230110084930.3439001-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- test/self/printf.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/self/printf.c b/test/self/printf.c index 7a74660868..eae40ed242 100644 --- a/test/self/printf.c +++ b/test/self/printf.c @@ -305,6 +305,22 @@ test_pointer(void) errptr(); } +static void __init +test_jsonpath(void) +{ + if (!IS_ENABLED(CONFIG_JSMN)) { + pr_info("skipping jsonpath tests: CONFIG_JSMN disabled in config\n"); + skipped_tests += 5; + return; + } + + test("", "%pJP", NULL); + test("$", "%pJP", &(char *[]){ NULL }); + test("$.1", "%pJP", &(char *[]){ "1", NULL }); + test("$.1.23", "%pJP", &(char *[]){ "1", "23", NULL }); + test("$.1.23.456", "%pJP", &(char *[]){ "1", "23", "456", NULL }); +} + static void __init test_printf(void) { alloced_buffer = malloc(BUF_SIZE + 2*PAD_SIZE); @@ -317,6 +333,7 @@ static void __init test_printf(void) test_string(); test_pointer(); test_hexstr(); + test_jsonpath(); free(alloced_buffer); } -- cgit v1.2.1