Commit Diff
Commit:
9987c6fb4f2e1754d290359f08988d29304f9d19
From:
Omar Polo <op@omarpolo.com>
Date:
Mon Dec 26 14:49:33 2022 UTC
Message
add some tests for iri_setquery
commit - 3f2ab305cab249cabbe914b0d8770b50688c5d4c
commit + 9987c6fb4f2e1754d290359f08988d29304f9d19
blob - a7bfe0bc450040c5c679f92580564daf119fd32d
blob + 4ea3e341eac2e5da3dbb6b8d98bde95e82e0d7de
--- test/iritest.c
+++ test/iritest.c
@@ -51,12 +51,52 @@ int
return (0);
}
+static int
+setquery(const char *iri, const char *query, const char *expected)
+{
+ static struct iri i;
+ char buf[512];
+
+ if (iri_parse(NULL, iri, &i) == -1) {
+ fprintf(stderr, "FAIL can't parse <%s>: %s\n", iri,
+ strerror(errno));
+ return (1);
+ }
+
+ if (iri_setquery(&i, query) == -1) {
+ fprintf(stderr, "FAIL setting query \"%s\": %s\n", query,
+ strerror(errno));
+ return (1);
+ }
+
+ if (iri_unparse(&i, buf, sizeof(buf)) == -1) {
+ fprintf(stderr, "FAIL unparsing <%s> with query %s\n",
+ iri, query);
+ return (1);
+ }
+
+ if (strcmp(buf, expected) != 0) {
+ fprintf(stderr, "FAIL setquery(\"%s\", \"%s\")\n", iri, query);
+ fprintf(stderr, "got:\t%s\n", buf);
+ fprintf(stderr, "want:\t%s\n", expected);
+ return (1);
+ }
+
+ fprintf(stderr, "OK setquery(\"%s\", \"%s\") -> %s\n", iri, query,
+ expected);
+ return (0);
+}
+
int
main(void)
{
- const char *base = "http://a/b/c/d;p?q";
+ const char *base;
int ret = 0;
+ /* RFC 3986 tests */
+
+ base = "http://a/b/c/d;p?q";
+
ret |= resolve(base, "g:h", "g:h");
ret |= resolve(base, "g", "http://a/b/c/g");
ret |= resolve(base, "./g", "http://a/b/c/g");
@@ -110,5 +150,14 @@ main(void)
ret |= resolve(base, "http:g", "http:g");
+ /* extra tests */
+
+ base = "gemini://a/b/c";
+
+ ret |= setquery(base, "hw", "gemini://a/b/c?hw");
+ ret |= setquery(base, "h w", "gemini://a/b/c?h%20w");
+ ret |= setquery(base, "100%", "gemini://a/b/c?100%25");
+ ret |= setquery(base, "%20", "gemini://a/b/c?%2520");
+
return (ret);
}
Omar Polo