From 64e67cfd70f18b67948fd3f7b03e39af9b5d31c3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 28 Feb 2013 23:28:55 -0600 Subject: cleanups --- src/test/scala/org/perl8/router/test.scala | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/scala/org/perl8/router/test.scala (limited to 'src/test/scala/org/perl8/router/test.scala') diff --git a/src/test/scala/org/perl8/router/test.scala b/src/test/scala/org/perl8/router/test.scala new file mode 100644 index 0000000..e1fff79 --- /dev/null +++ b/src/test/scala/org/perl8/router/test.scala @@ -0,0 +1,40 @@ +package org.perl8.router + +object test { + import language.implicitConversions + + class RouterHelperOps[T] (router: Router[T]) { + private def assert (condition: Boolean, msg: String) = { + if (condition) None else Some(msg) + } + + def matches (path: String) = { + assert(router.route(path).isDefined, s"route failed to match $path") + } + + def matches (path: String, mapping: Map[String, String]) = { + (router.uriFor(mapping), router.route(path)) match { + case (Some(uriFor), Some(m)) => { + None.orElse({ + assert(uriFor == path, s"uriFor returned $uriFor, expected $path") + }).orElse({ + assert( + m.mapping.size == mapping.size && + m.mapping.forall { case (k, v) => mapping(k) == v }, + s"route returned ${m.mapping}, expected $mapping" + ) + }) + } + case (None, None) => + Some(s"uriFor and route both failed to match $path") + case (None, _) => + Some(s"uriFor failed to match $path") + case (_, None) => + Some(s"route failed to match $path") + } + } + } + + implicit def routerToOps[T] (router: Router[T]): RouterHelperOps[T] = + new RouterHelperOps(router) +} -- cgit v1.2.3-54-g00ecf