Blame


1 3300cbe0 2021-01-27 op /*
2 3300cbe0 2021-01-27 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 3300cbe0 2021-01-27 op *
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.
7 3300cbe0 2021-01-27 op *
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.
15 3300cbe0 2021-01-27 op */
16 3300cbe0 2021-01-27 op
17 3300cbe0 2021-01-27 op #include <stdio.h>
18 3300cbe0 2021-01-27 op #include <string.h>
19 3300cbe0 2021-01-27 op
20 3300cbe0 2021-01-27 op #include "../gmid.h"
21 3300cbe0 2021-01-27 op
22 319b7fa9 2021-02-08 op /* to make the linker happy */
23 319b7fa9 2021-02-08 op struct conf conf;
24 319b7fa9 2021-02-08 op
25 3300cbe0 2021-01-27 op struct suite {
26 3300cbe0 2021-01-27 op const char *src;
27 3300cbe0 2021-01-27 op const char *res;
28 3300cbe0 2021-01-27 op } t[] = {
29 3300cbe0 2021-01-27 op {"foo", "foo"},
30 44ee1bac 2021-01-27 op {"h.n", "h.n"},
31 3300cbe0 2021-01-27 op {"xn-invalid", "xn-invalid"},
32 3300cbe0 2021-01-27 op {"naïve", "naïve"},
33 3300cbe0 2021-01-27 op {"xn--8ca", "è"},
34 3300cbe0 2021-01-27 op {"xn--caff-8oa", "caffè"},
35 3300cbe0 2021-01-27 op {"xn--nave-6pa", "naïve"},
36 3300cbe0 2021-01-27 op {"xn--e-0mbbc", "τeστ"},
37 3300cbe0 2021-01-27 op {"xn--8ca67lbac", "τèστ"},
38 3300cbe0 2021-01-27 op {"xn--28j2a3ar1p", "こんにちは"},
39 3300cbe0 2021-01-27 op {"xn--hello--ur7iy09x", "hello-世界"},
40 3300cbe0 2021-01-27 op {"xn--hi--hi-rr7iy09x", "hi-世界-hi"},
41 3300cbe0 2021-01-27 op {"xn--caf-8la.foo.org", "cafè.foo.org"},
42 3300cbe0 2021-01-27 op /* 3 bytes */
43 3300cbe0 2021-01-27 op {"xn--j6h", "♨"},
44 3300cbe0 2021-01-27 op /* 4 bytes */
45 3300cbe0 2021-01-27 op {"xn--x73l", "𩸽"},
46 3300cbe0 2021-01-27 op {"xn--x73laaa", "𩸽𩸽𩸽𩸽"},
47 3300cbe0 2021-01-27 op {NULL, NULL}
48 3300cbe0 2021-01-27 op };
49 3300cbe0 2021-01-27 op
50 3300cbe0 2021-01-27 op int
51 3300cbe0 2021-01-27 op main(int argc, char **argv)
52 3300cbe0 2021-01-27 op {
53 3300cbe0 2021-01-27 op struct suite *i;
54 3300cbe0 2021-01-27 op int failed;
55 3300cbe0 2021-01-27 op char buf[64]; /* name len */
56 1e7591a9 2021-02-01 op const char *parse_err;
57 3300cbe0 2021-01-27 op
58 3300cbe0 2021-01-27 op failed = 0;
59 3300cbe0 2021-01-27 op for (i = t; i->src != NULL; ++i) {
60 3300cbe0 2021-01-27 op memset(buf, 0, sizeof(buf));
61 cef60084 2021-01-29 op if (!puny_decode(i->src, buf, sizeof(buf), &parse_err)) {
62 cef60084 2021-01-29 op printf("decode: failure with %s: %s\n",
63 cef60084 2021-01-29 op i->src, parse_err);
64 3300cbe0 2021-01-27 op failed = 1;
65 3300cbe0 2021-01-27 op continue;
66 3300cbe0 2021-01-27 op }
67 3300cbe0 2021-01-27 op
68 3300cbe0 2021-01-27 op if (strcmp(buf, i->res)) {
69 3300cbe0 2021-01-27 op printf("ERR: expected \"%s\", got \"%s\"\n",
70 3300cbe0 2021-01-27 op i->res, buf);
71 3300cbe0 2021-01-27 op failed = 1;
72 3300cbe0 2021-01-27 op continue;
73 3300cbe0 2021-01-27 op } else
74 3300cbe0 2021-01-27 op printf("OK: %s => %s\n", i->src, buf);
75 3300cbe0 2021-01-27 op }
76 3300cbe0 2021-01-27 op
77 3300cbe0 2021-01-27 op return failed;
78 3300cbe0 2021-01-27 op }