summaryrefslogtreecommitdiffstats
path: root/src/test/scala/org/perl8/router/MessyTest.scala
blob: 4f1f879041440282f6472255510dd9722e26c992 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.perl8.router

import org.scalatest.FunSuite

import org.perl8.router.test._

class MessyTest extends FunSuite {
  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"  -> """\d{4}""".r,
      "month" -> """\d{1,2}""".r,
      "day"   -> """\d{1,2}""".r
    )
  )

  router addRoute (
    "blog/:action/:id",
    true,
    defaults = Map(
      "controller" -> "blog"
    ),
    validations = Map(
      "action" -> """\D+""".r,
      "id"     -> """\d+""".r
    )
  )

  test ("our routes match") {
    assert(router matches "/blog/")
    assert(router matches "./blog/")
    assert(router matches "///.///.///blog//.//")
    assert(router matches "/blog/./show/.//./20")
    assert(router matches "/blog/./2006/.//./20////////10")
  }
}