PageRenderTime 10ms CodeModel.GetById 6ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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