~julienxx/castor9

897c1238599c245a3d499283a51605e410021149 — Shawn Nock 3 years ago 118b139
Adds a few regression tests for parseurl
2 files changed, 61 insertions(+), 1 deletions(-)

M mkfile
A tests/testurl.c
M mkfile => mkfile +12 -1
@@ 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/

</sys/src/cmd/mkone


@@ 16,4 17,14 @@ $LIB:V:

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'
	}

A tests/testurl.c => tests/testurl.c +49 -0
@@ 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);
}