From 897c1238599c245a3d499283a51605e410021149 Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Thu, 17 Dec 2020 20:57:17 +0000 Subject: [PATCH] Adds a few regression tests for parseurl --- mkfile | 13 ++++++++++++- tests/testurl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/testurl.c diff --git a/mkfile b/mkfile index 642a3d0..6553e32 100644 --- a/mkfile +++ b/mkfile @@ -4,6 +4,7 @@ TARG=castor LIB=libpanel/libpanel.$O.a OFILES=url.$O util.$O castor.$O HFILES=castor.h libpanel/panel.h libpanel/rtext.h +TESTS=testurl BIN=/$objtype/bin/ +#include + +#include + +static void assertstreql(char *a, char *b){ + int r; + r = strcmp(a, b); + assert(r == 0); +} + +static void geminiabs(void){ + Url *u; + u = urlparse(nil, "gemini://host:port/path"); + assert(u != nil); + assertstreql(u->host, "host"); + assertstreql(u->port, "port"); + assertstreql(u->scheme, "gemini"); + freeurl(u); +} + +static void geminirel(void){ + Url *base, *u; + base = urlparse(nil, "gemini://host/"); + u = urlparse(base, "/path"); + assert(u != nil); + assertstreql(u->host, "host"); + assertstreql(u->scheme, "gemini"); + assertstreql(u->path, "/path"); + freeurl(u); +} + +static void mailto(void){ + Url *u; + u = urlparse(nil, "mailto:user@email.com"); + assert(u != nil); + assertstreql(u->scheme, "mailto"); + assertstreql(u->path, "user@email.com"); + freeurl(u); +} + +void main(void) { + print("testurl: "); + geminiabs(); + geminirel(); + mailto(); + print("PASS\n"); + exits(0); +} -- 2.45.2