PageRenderTime 42ms CodeModel.GetById 38ms RepoModel.GetById 0ms 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. */
  18. package org.fusesource.scalate.support
  19. import org.fusesource.scalate.FunSuiteSupport
  20. class ConvertAbsoluteLinkTest extends FunSuiteSupport {
  21. List(
  22. "http://fusesource.com",
  23. "foo.html",
  24. "bar/whatnot/foo.html") foreach assertUnchanged
  25. assertChanged("/foo.html", "/bar.html", "foo.html")
  26. assertChanged("/foo.html", "/a/bar.html", "../foo.html")
  27. assertChanged("/foo.html", "/a/b/bar.html", "../../foo.html")
  28. assertChanged("/a/foo.html", "/a/bar.html", "foo.html")
  29. assertChanged("/a/foo.html", "/b/bar.html", "../a/foo.html")
  30. assertChanged("/a/foo.html", "/b/c/d/bar.html", "../../../a/foo.html")
  31. assertChanged("/a/b/foo.html", "/a/c/d/bar.html", "../../b/foo.html")
  32. protected def assertChanged(link: String, requestUri: String, expected: String): Unit = {
  33. test(link + " from " + requestUri) {
  34. val answer = Links.convertAbsoluteLinks(link, requestUri)
  35. info("should convert " + link + " at " + requestUri + " -> " + answer)
  36. assertResult(expected) { answer }
  37. }
  38. }
  39. protected def assertUnchanged(link: String): Unit = {
  40. test(link) {
  41. val answer = Links.convertAbsoluteLinks(link, "/foo/bar.html")
  42. info("should be unchanged " + link + " -> " + answer)
  43. assertResult(link, "Should not be changed") { answer }
  44. }
  45. }
  46. }