Blob


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