skip to content
==> tests/debug_str.c <==
1/* mesh-debug-str: the escapes Rust's {:?} uses (values printed by `format!("{:?}", s)`). */
2#include "mesh/debug_str.h"
3#include "mesh/check.h"
4
5#include <stdlib.h>
6
7static void is(const char *in, const char *want) {
8    char *got = mdebug(in);
9    CHECK_S(got, want);
10    free(got);
11}
12
13int main(void) {
14    is("x", "\"x\"");
15    is("", "\"\"");
16    is("a\"b\\c", "\"a\\\"b\\\\c\"");
17    is("tab\there\nline\r", "\"tab\\there\\nline\\r\"");
18    is("\x1b[0m", "\"\\u{1b}[0m\"");
19    is("\x7f", "\"\\u{7f}\"");
20    is("caf\xc3\xa9", "\"caf\xc3\xa9\"");
21    msb b = {0};
22    mdebug_str(&b, "a\0b", 3);
23    CHECK_S(msb_str(&b), "\"a\\0b\"");
24    msb_free(&b);
25    return mesh_check_done();
26}