shithub: castor9

ref: 059574a9bdc29c5381e12ed18158f05320ad7cd7
dir: /tests/testurl.c/

View raw version
#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);
}