shithub: castor9

Download patch

ref: 897c1238599c245a3d499283a51605e410021149
parent: 118b13927067729a06ecbf923ec6d634d4a8358c
author: Shawn Nock <shawn@provisoire.ca>
date: Thu Dec 17 15:57:17 EST 2020

Adds a few regression tests for parseurl

diff: cannot open b/tests//null: file does not exist: 'b/tests//null'
--- a/mkfile
+++ b/mkfile
@@ -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
+++ b/tests/testurl.c
@@ -1,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);
+}