mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 02:27:51 +01:00
d7e233e47d
json_escaped.[ch], param.[ch] and jsonrpc_errors.h move from lightningd/ to common/. Tests moved too. We add a new 'common/json_tok.[ch]' for the common parameter parsing routines which a plugin might want, taking them out of lightningd/json.c (which now only contains the lightningd-specific ones). The rest is mainly fixing up includes. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
47 lines
1.6 KiB
C
47 lines
1.6 KiB
C
#include "../json_escaped.c"
|
|
#include <assert.h>
|
|
#include <common/utils.h>
|
|
#include <stdio.h>
|
|
|
|
static void test_json_partial(void)
|
|
{
|
|
const tal_t *ctx = tal(NULL, char);
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\")->s, "\\\\"));
|
|
assert(streq(json_partial_escape(ctx, "\\\\")->s, "\\\\"));
|
|
assert(streq(json_partial_escape(ctx, "\\\\\\")->s, "\\\\\\\\"));
|
|
assert(streq(json_partial_escape(ctx, "\\\\\\\\")->s, "\\\\\\\\"));
|
|
assert(streq(json_partial_escape(ctx, "\\n")->s, "\\n"));
|
|
assert(streq(json_partial_escape(ctx, "\n")->s, "\\n"));
|
|
assert(streq(json_partial_escape(ctx, "\\\"")->s, "\\\""));
|
|
assert(streq(json_partial_escape(ctx, "\"")->s, "\\\""));
|
|
assert(streq(json_partial_escape(ctx, "\\t")->s, "\\t"));
|
|
assert(streq(json_partial_escape(ctx, "\t")->s, "\\t"));
|
|
assert(streq(json_partial_escape(ctx, "\\b")->s, "\\b"));
|
|
assert(streq(json_partial_escape(ctx, "\b")->s, "\\b"));
|
|
assert(streq(json_partial_escape(ctx, "\\r")->s, "\\r"));
|
|
assert(streq(json_partial_escape(ctx, "\r")->s, "\\r"));
|
|
assert(streq(json_partial_escape(ctx, "\\f")->s, "\\f"));
|
|
assert(streq(json_partial_escape(ctx, "\f")->s, "\\f"));
|
|
/* You're allowed to escape / according to json.org. */
|
|
assert(streq(json_partial_escape(ctx, "\\/")->s, "\\/"));
|
|
assert(streq(json_partial_escape(ctx, "/")->s, "/"));
|
|
|
|
assert(streq(json_partial_escape(ctx, "\\u0FFF")->s, "\\u0FFF"));
|
|
assert(streq(json_partial_escape(ctx, "\\u0FFFx")->s, "\\u0FFFx"));
|
|
|
|
/* Unknown escapes should be escaped. */
|
|
assert(streq(json_partial_escape(ctx, "\\x")->s, "\\\\x"));
|
|
tal_free(ctx);
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
setup_locale();
|
|
|
|
test_json_partial();
|
|
assert(!taken_any());
|
|
take_cleanup();
|
|
}
|