2 3300cbe0 2021-01-27 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 3300cbe0 2021-01-27 op * Permission to use, copy, modify, and distribute this software for any
5 3300cbe0 2021-01-27 op * purpose with or without fee is hereby granted, provided that the above
6 3300cbe0 2021-01-27 op * copyright notice and this permission notice appear in all copies.
8 3300cbe0 2021-01-27 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3300cbe0 2021-01-27 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3300cbe0 2021-01-27 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3300cbe0 2021-01-27 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3300cbe0 2021-01-27 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3300cbe0 2021-01-27 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3300cbe0 2021-01-27 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 3300cbe0 2021-01-27 op #include <stdio.h>
18 3300cbe0 2021-01-27 op #include <string.h>
20 3300cbe0 2021-01-27 op #include "../gmid.h"
22 e5d82d94 2022-03-19 op const struct suite {
23 3300cbe0 2021-01-27 op const char *src;
24 3300cbe0 2021-01-27 op const char *res;
26 3300cbe0 2021-01-27 op {"foo", "foo"},
27 44ee1bac 2021-01-27 op {"h.n", "h.n"},
28 3300cbe0 2021-01-27 op {"xn-invalid", "xn-invalid"},
29 3300cbe0 2021-01-27 op {"naïve", "naïve"},
30 3300cbe0 2021-01-27 op {"xn--8ca", "è"},
31 3300cbe0 2021-01-27 op {"xn--caff-8oa", "caffè"},
32 3300cbe0 2021-01-27 op {"xn--nave-6pa", "naïve"},
33 3300cbe0 2021-01-27 op {"xn--e-0mbbc", "τeστ"},
34 3300cbe0 2021-01-27 op {"xn--8ca67lbac", "τèστ"},
35 3300cbe0 2021-01-27 op {"xn--28j2a3ar1p", "こんにちは"},
36 3300cbe0 2021-01-27 op {"xn--hello--ur7iy09x", "hello-世界"},
37 3300cbe0 2021-01-27 op {"xn--hi--hi-rr7iy09x", "hi-世界-hi"},
38 3300cbe0 2021-01-27 op {"xn--caf-8la.foo.org", "cafè.foo.org"},
40 3300cbe0 2021-01-27 op {"xn--j6h", "♨"},
42 3300cbe0 2021-01-27 op {"xn--x73l", "𩸽"},
43 3300cbe0 2021-01-27 op {"xn--x73laaa", "𩸽𩸽𩸽𩸽"},
48 62e001b0 2021-03-20 op sandbox_logger_process(void)
50 62e001b0 2021-03-20 op /* to make the linker happy! */
55 3300cbe0 2021-01-27 op main(int argc, char **argv)
57 e5d82d94 2022-03-19 op const struct suite *i;
59 3300cbe0 2021-01-27 op char buf[64]; /* name len */
60 1e7591a9 2021-02-01 op const char *parse_err;
63 3300cbe0 2021-01-27 op for (i = t; i->src != NULL; ++i) {
64 3300cbe0 2021-01-27 op memset(buf, 0, sizeof(buf));
65 cef60084 2021-01-29 op if (!puny_decode(i->src, buf, sizeof(buf), &parse_err)) {
66 cef60084 2021-01-29 op printf("decode: failure with %s: %s\n",
67 cef60084 2021-01-29 op i->src, parse_err);
72 3300cbe0 2021-01-27 op if (strcmp(buf, i->res)) {
73 3300cbe0 2021-01-27 op printf("ERR: expected \"%s\", got \"%s\"\n",
78 3300cbe0 2021-01-27 op printf("OK: %s => %s\n", i->src, buf);
81 3300cbe0 2021-01-27 op return failed;