forked from scalatra/scalatra
/
UrlGeneratorTest.scala
52 lines (38 loc) · 1.71 KB
/
UrlGeneratorTest.scala
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.scalatra
import test.scalatest.ScalatraFunSuite
class UrlGeneratorTest extends ScalatraFunSuite {
addServlet(classOf[UrlGeneratorTestServlet], "/*")
object TestUrlGenerator extends UrlGenerator
import TestUrlGenerator._
object TestServlet extends UrlGeneratorTestServlet
import TestServlet._
test("Simple string route reverses to the same url") {
generate(simpleString) should equal ("/foo")
}
test("Route with one named parameter replaces the parameter") {
generate(singleNamed, "bar" -> "bryan") should equal ("/foo/bryan")
}
test("Route with two named parameters replaces both parameters") {
generate(multipleNameds, "bar" -> "moonless", "rebar" -> "midnight") should equal ("/foo/moonless/and/midnight")
}
test("Named of path containing a dot get replaced anyway") {
generate(dotOutsideNamedParam, "file" -> "TroutLauncher", "ext" -> "scala") should equal ("/dot-outside-named-param/TroutLauncher.scala")
}
test("Missing parameter produces an exception") {
evaluating {
generate(multipleNameds, "bar" -> "moonless")
} should produce [Exception]
}
test("Unexpected parameters are just ignored at the moment") {
generate(singleNamed, "bar" -> "pepper", "unexpected" -> "surprise") should equal ("/foo/pepper")
}
test("One splat parameter gets replaced") {
generate(singleSplat, "malt") should equal ("/single-splat/malt")
}
test("Many splat parameters get replaced") {
generate(multipleSplats, "made", "in", "japan") should equal ("/mixing-multiple-splats/made/foo/in/japan")
}
test("Mix named and splat") {
generate(mixNamedAndSplat, Map("foo" -> "deep"), Seq("purple")) should equal ("/mix-named-and-splat-params/deep/purple")
}
}