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/BasicTest.scala | 127 ++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/test/scala/org/perl8/router/BasicTest.scala (limited to 'src/test/scala/org/perl8/router/BasicTest.scala') diff --git a/src/test/scala/org/perl8/router/BasicTest.scala b/src/test/scala/org/perl8/router/BasicTest.scala new file mode 100644 index 0000000..b00d1ae --- /dev/null +++ b/src/test/scala/org/perl8/router/BasicTest.scala @@ -0,0 +1,127 @@ +package org.perl8.router + +import org.scalatest.FunSuite + +import org.perl8.router.test._ + +class BasicTest extends FunSuite { + val yearRx = """\d{4}""".r + val monthRx = """\d|10|11|12""".r + val dayRx = """\d|[12]\d|30|31""".r + + val router = new Router[Boolean] + + router addRoute ( + "blog", + true, + defaults = Map( + "controller" -> "blog", + "action" -> "index" + ) + ) + + router addRoute ( + "blog/:year/:month/:day", + true, + defaults = Map( + "controller" -> "blog", + "action" -> "show_date" + ), + validations = Map( + "year" -> yearRx, + "month" -> monthRx, + "day" -> dayRx + ) + ) + + router addRoute ( + "blog/:action/:id", + true, + defaults = Map( + "controller" -> "blog" + ), + validations = Map( + "action" -> """\D+""".r, + "id" -> """\d+""".r + ) + ) + + router addRoute ( + "test/?:x/?:y", + true, + defaults = Map( + "controller" -> "test", + "x" -> "x", + "y" -> "y" + ) + ) + + test ("routes match properly") { + assert( + router matches "blog", Map( + "controller" -> "blog", + "action" -> "index" + ) + ) + + assert( + router matches "blog/2006/12/5", Map( + "controller" -> "blog", + "action" -> "show_date", + "year" -> "2006", + "month" -> "12", + "day" -> "5" + ) + ) + + assert( + router matches "blog/1920/12/10", Map( + "controller" -> "blog", + "action" -> "show_date", + "year" -> "1920", + "month" -> "12", + "day" -> "10" + ) + ) + + assert( + router matches "blog/edit/5", Map( + "controller" -> "blog", + "action" -> "edit", + "id" -> "5" + ) + ) + + assert( + router matches "blog/show/123", Map( + "controller" -> "blog", + "action" -> "show", + "id" -> "123" + ) + ) + + assert( + router matches "blog/some_crazy_long_winded_action_name/12356789101112131151", Map( + "controller" -> "blog", + "action" -> "some_crazy_long_winded_action_name", + "id" -> "12356789101112131151" + ) + ) + + assert( + router matches "blog/delete/5", Map( + "controller" -> "blog", + "action" -> "delete", + "id" -> "5" + ) + ) + + assert( + router matches "test/x1", Map( + "controller" -> "test", + "x" -> "x1", + "y" -> "y" + ) + ) + } +} -- cgit v1.2.3-54-g00ecf