~julienxx/castor9-devel

1

[PATCH] Adds a few regression tests for parseurl

Details
Message ID
<4D3AB945128E47B3BFC5724798879138@provisoire.ca>
DKIM signature
missing
Download raw message
---

I'm not certain this kind of contribution is wanted.  I wrote this when
I was isolating / fixing the mailto: parsing.

diff e099cb2cd012f13108efec70cce1ea1cfcdcd208 a39b12260659360290b7ace50ca28bc51fb607ab
--- a/mkfile	Thu Dec 17 14:25:08 2020
+++ b/mkfile	Thu Dec 17 15:53:12 2020
@@ -4,6 +4,7 @@
 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/
 
 </sys/src/cmd/mkone
@@ -16,4 +17,14 @@
 
 clean nuke:V:
 	@{ cd libpanel; mk $target }
-	rm -f *.[$OS] [$OS].out $TARG
+	rm -f *.[$OS] [$OS].out tests/*.[$OS] $TARG
+	for (test in $TESTS)
+		rm -f tests/$test
+
+test:V: url.$O util.$O
+	for (test in $TESTS) {
+		$CC -o tests/$test.$O tests/$test.c
+		$LD -o tests/$test tests/$test.$O url.$O util.$O
+		if (./tests/$test);
+		if not echo 'FAIL'
+	}
--- /dev/null	Tue Dec 15 07:32:24 2020
+++ b/tests/testurl.c	Thu Dec 17 15:53:12 2020
@@ -0,0 +1,49 @@
+#include <u.h>
+#include <libc.h>
+
+#include <castor.h>
+
+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);
+}
Details
Message ID
<4d59801e-ce24-57d6-0ae0-24f6addaab74@typed-hole.org>
In-Reply-To
<4D3AB945128E47B3BFC5724798879138@provisoire.ca> (view parent)
DKIM signature
missing
Download raw message
Applied thanks a lot, this kind of contributions is definitely wanted!
Reply to thread Export thread (mbox)