/scalate-wikitext/src/test/scala/org/fusesource/scalate/wikitext/SwizzleLinkFilterTest.scala

http://github.com/scalate/scalate · Scala · 81 lines · 46 code · 15 blank · 20 comment · 0 complexity · 0f9aee81796692328f2088de5a935ce7 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
  19. package wikitext
  20. import org.fusesource.scalate.test.FunSuiteSupport
  21. import java.io.File
  22. class SwizzleLinkFilterTest extends FunSuiteSupport {
  23. val transformer = new SwizzleLinkFilter(List(new File(".")), new TemplateEngine().extensions)
  24. // valid replacements
  25. testReplaces(
  26. """hello <a href='building'>Building</a> there!""",
  27. """hello <a href='building.html'>Building</a> there!""")
  28. testReplaces(
  29. """hello <a href="building">Building</a> there!""",
  30. """hello <a href="building.html">Building</a> there!""")
  31. testReplaces(
  32. """hello <a href="building">Building</a> something <a href="source">Source</a> there!""",
  33. """hello <a href="building.html">Building</a> something <a href="source.html">Source</a> there!""")
  34. // upper case versions
  35. testReplaces(
  36. """hello <A href='building'>Building</A> there!""",
  37. """hello <A href='building.html'>Building</A> there!""")
  38. testReplaces(
  39. """hello <A href="building">Building</A> there!""",
  40. """hello <A href="building.html">Building</A> there!""")
  41. testReplaces(
  42. """hello <A href="building">Building</A> something <A href="source">Source</A> there!""",
  43. """hello <A href="building.html">Building</A> something <A href="source.html">Source</A> there!""")
  44. testReplaces(
  45. """hello <A href="user' guide">Building</A>""",
  46. """hello <A href="user' guide.html">Building</A>""")
  47. // should not replace these...
  48. testReplaces(
  49. """hello <a href="http://fusesource.com/">FuseSource</a> there!""",
  50. """hello <a href="http://fusesource.com/">FuseSource</a> there!""")
  51. testReplaces(
  52. """hello <link href="css/style.css.html" rel="stylesheet" type="text/css"/> there!""",
  53. """hello <link href="css/style.css.html" rel="stylesheet" type="text/css"/> there!""")
  54. testReplaces(
  55. """hello <script src="foo.js" type="text/javascript"></script> there!""",
  56. """hello <script src="foo.js" type="text/javascript"></script> there!""")
  57. protected def testReplaces(html: String, expected: String): Unit = {
  58. test("replaces: " + html) {
  59. val context = new DefaultRenderContext("foo.html", new TemplateEngine)
  60. val answer = transformer.filter(context, html)
  61. info("converted " + html)
  62. info("into: " + answer)
  63. assertResult(expected) { answer }
  64. }
  65. }
  66. }