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