PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/scalate-core/src/test/scala/org/fusesource/scalate/support/ConvertAbsoluteLinkTest.scala

http://github.com/scalate/scalate
Scala | 53 lines | 29 code | 7 blank | 17 comment | 0 complexity | 3e3e604fb0eb3ef6163f390b621ce0cc MD5 | raw file
 1/**
 2 * Copyright (C) 2009-2011 the original author or authors.
 3 * See the notice.md file distributed with this work for additional
 4 * information regarding copyright ownership.
 5 *
 6 * Licensed under the Apache License, Version 2.0 (the "License");
 7 * you may not use this file except in compliance with the License.
 8 * You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.fusesource.scalate.support
19
20import org.fusesource.scalate.FunSuiteSupport
21
22class ConvertAbsoluteLinkTest extends FunSuiteSupport {
23  List(
24    "http://fusesource.com",
25    "foo.html",
26    "bar/whatnot/foo.html") foreach assertUnchanged
27
28  assertChanged("/foo.html", "/bar.html", "foo.html")
29  assertChanged("/foo.html", "/a/bar.html", "../foo.html")
30  assertChanged("/foo.html", "/a/b/bar.html", "../../foo.html")
31  assertChanged("/a/foo.html", "/a/bar.html", "foo.html")
32  assertChanged("/a/foo.html", "/b/bar.html", "../a/foo.html")
33  assertChanged("/a/foo.html", "/b/c/d/bar.html", "../../../a/foo.html")
34  assertChanged("/a/b/foo.html", "/a/c/d/bar.html", "../../b/foo.html")
35
36  protected def assertChanged(link: String, requestUri: String, expected: String): Unit = {
37    test(link + " from " + requestUri) {
38      val answer = Links.convertAbsoluteLinks(link, requestUri)
39
40      info("should convert " + link + " at " + requestUri + " -> " + answer)
41      assertResult(expected) { answer }
42    }
43  }
44
45  protected def assertUnchanged(link: String): Unit = {
46    test(link) {
47      val answer = Links.convertAbsoluteLinks(link, "/foo/bar.html")
48
49      info("should be unchanged " + link + " -> " + answer)
50      assertResult(link, "Should not be changed") { answer }
51    }
52  }
53}