PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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