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

/scalate-core/src/test/scala/org/fusesource/scalate/scaml/ScamlBugTest.scala

http://github.com/scalate/scalate
Scala | 201 lines | 165 code | 16 blank | 20 comment | 0 complexity | c5f05a1dad9260ee0c4d2966ea4872e4 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.scaml
 19
 20/**
 21 * Some tests for Scaml bugs reported
 22 */
 23class ScamlBugTest extends ScamlTestSupport {
 24
 25  testRender(
 26    "#155: Scaml :!plain filter breaks when used with multiple content lines",
 27    """
 28- val msg = "hello"
 29:!plain
 30  #{msg}, user
 31  The greeting is #{msg}.
 32""", """
 33hello, user
 34The greeting is hello.
 35""")
 36
 37  testRender(
 38    "#99: error if a comment containing just one space is used",
 39    "-#\n-# \ntest\n/\n/ \ntest\n", """
 40test
 41<!--  -->
 42<!--  -->
 43test
 44""")
 45
 46  testRender(
 47    "#98: Error with a statement followed by an attribute declaration",
 48    """
 49- attributes("title") = "foo"
 50-@ import val title: String
 51= length
 52""", """
 533
 54""")
 55
 56  testRender(
 57    "#77: attribute sanitized twice",
 58    """
 59- val amp = "&"
 60%div(attr1="#{amp}")
 61""", """
 62<div attr1="&amp;"></div>
 63""")
 64
 65  testRender(
 66    "#78: null class attribute not removed",
 67    """
 68%div(id={null} attr1={null} class={null})
 69""", """
 70<div></div>
 71""")
 72
 73  testRender(
 74    "#74: scaml id or class + dynamic attribute produces an error",
 75    """
 76%div.some(attr1={"value"})
 77%div#some(attr1={"value"})
 78""", """
 79<div class="some" attr1="value"></div>
 80<div id="some" attr1="value"></div>
 81""")
 82
 83  testRender(
 84    "SCALATE-44 test1",
 85    """
 86- if (name == "Hiram")
 87  - if (title == "MyPage")
 88    Worked!
 89
 90  - else
 91    Failed
 92
 93- else
 94  Failed
 95""", """
 96Worked!
 97""")
 98
 99  testRender(
100    "SCALATE-45: creating a link with a title seems to remove whitespace from inside the title attribute",
101    """
102%a(href={1+2} title="foo bar")
103""", """
104<a href="3" title="foo bar"></a>
105""")
106
107  testRender(
108    "SCALATE-48: odd compile error when whitespace added to end of '-@ val: x: String '",
109    """
110-@ val label: String
111%p #{label}
112""", """
113<p>Scalate</p>
114""")
115
116  testRender(
117    "SCALATE-49: using a #{foo} expression inside a HTML attribute causes strangeness",
118    """
119- var x="blue"
120%div(class="line #{x}")
121""", """
122<div class="line blue"></div>
123""")
124
125  testRender(
126    "SCALATE-49: simple case",
127    """
128%pre(class="brush: html")<
129  test
130""", """
131<pre class="brush: html">test</pre>
132""")
133
134  testRender(
135    "SCALATE-71: Internation characters",
136    """
137%div<
138  1 한글 Hello &
139%div<
140  = "2 한글 Hello &"
141%div<
142  != "3 한글 Hello &"
143%div<
144  &= "4 한글 Hello &"
145%div<
146  ~~ "5 한글 Hello &"
147%div<
148  !~~ "6 한글 Hello &"
149%div<
150  &~~ "7 한글 Hello &"
151""", """
152<div>1 한글 Hello &</div>
153<div>2 한글 Hello &amp;</div>
154<div>3 한글 Hello &</div>
155<div>4 한글 Hello &amp;</div>
156<div>5 한글 Hello &amp;</div>
157<div>6 한글 Hello &</div>
158<div>7 한글 Hello &amp;</div>
159""")
160
161  testRender(
162    "SCALATE-71: Internation characters with escapeMarkup=false ",
163    """
164%div<
165  1 한글 Hello &
166%div<
167  = "2 한글 Hello &"
168%div<
169  != "3 한글 Hello &"
170%div<
171  &= "4 한글 Hello &"
172%div<
173  ~~ "5 한글 Hello &"
174%div<
175  !~~ "6 한글 Hello &"
176%div<
177  &~~ "7 한글 Hello &"
178""", """
179<div>1 한글 Hello &</div>
180<div>2 한글 Hello &</div>
181<div>3 한글 Hello &</div>
182<div>4 한글 Hello &amp;</div>
183<div>5 한글 Hello &</div>
184<div>6 한글 Hello &</div>
185<div>7 한글 Hello &amp;</div>
186""",
187    () => {
188      engine.escapeMarkup = false
189    }, () => {
190      engine.escapeMarkup = true
191    })
192
193  testRender(
194    "SCALATE-72: Spaces stripped in an attribute expression",
195    """
196%p(class={"a b"}) a b
197""", """
198<p class="a b">a b</p>
199""")
200
201}