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

http://github.com/scalate/scalate · Scala · 138 lines · 86 code · 13 blank · 39 comment · 3 complexity · 55acf3b1c0d5f04a6914726452bb5e0f 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. * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  21. */
  22. class ScamlTemplateErrorTest extends ScamlTestSupport {
  23. testCompilerException(
  24. "Compile Error",
  25. """
  26. %html
  27. %body
  28. %ul
  29. - for (i <- unknown)
  30. %li= i
  31. """,
  32. "error: not found: value unknown")
  33. /////////////////////////////////////////////////////////////////////
  34. //
  35. // Tests for indentation inconsistencies
  36. //
  37. /////////////////////////////////////////////////////////////////////
  38. testRender(
  39. "valid indenting",
  40. """
  41. %html
  42. %two
  43. %three
  44. %two
  45. """, """
  46. <html>
  47. <two>
  48. <three></three>
  49. </two>
  50. <two></two>
  51. </html>
  52. """)
  53. testInvalidSyntaxException(
  54. "Inconsistent indent level detected: indented too shallow",
  55. """
  56. %html
  57. %two
  58. %tooshallow
  59. %two
  60. """,
  61. "Inconsistent indent level detected: indented too shallow at 3.4")
  62. testInvalidSyntaxException(
  63. "Inconsistent indent level detected: indented too shallow at root",
  64. """
  65. %html
  66. %two
  67. %toodeep
  68. %two
  69. """,
  70. "Inconsistent indent level detected: indented too shallow at 3.2")
  71. testInvalidSyntaxException(
  72. "Inconsistent indent level detected: indented too deep",
  73. """
  74. %html
  75. %two
  76. %toodeep
  77. %two
  78. """,
  79. "Inconsistent indent level detected: indented too deep at 3.6")
  80. testInvalidSyntaxException(
  81. "Inconsistent indent detected: indented with spaces but previous lines were indented with tabs",
  82. """
  83. %html
  84. %tab
  85. %spaces
  86. %tab
  87. """,
  88. "Inconsistent indent detected: indented with spaces but previous lines were indented with tabs at 3.3")
  89. // // https://github.com/scala/scala-parser-combinators/commit/a6b2b3999dab
  90. // if (!scala.util.Properties.versionNumberString.startsWith("2.10")) {
  91. // testInvalidSyntaxException(
  92. // "Unexpected comma in html attribute list",
  93. // """
  94. //%html
  95. // %tab(comma="common", error="true")
  96. // %p commas in attribute lists is a common errro
  97. //""",
  98. // "')' expected but ',' found at 2.22")
  99. // }
  100. // since scala-parser-combinators 1.1.2
  101. // https://github.com/scala/scala-parser-combinators/commit/a6b2b3999dab
  102. val scalaV = scala.util.Properties.versionNumberString
  103. if (!scalaV.startsWith("2.10")) {
  104. if (scalaV.startsWith("2.11")) {
  105. // scala-parser-combinators 1.1.1
  106. testInvalidSyntaxException(
  107. "Unexpected comma in html attribute list",
  108. """
  109. %html
  110. %tab(comma="common", error="true")
  111. %p commas in attribute lists is a common errro
  112. """,
  113. "')' expected but ',' found at 2.22")
  114. } else {
  115. testInvalidSyntaxException(
  116. "Unexpected comma in html attribute list",
  117. """
  118. %html
  119. %tab(comma="common", error="true")
  120. %p commas in attribute lists is a common errro
  121. """,
  122. "string matching regex '[ \\t]+' expected but '(' found at 2.7")
  123. }
  124. }
  125. }