diff options
Diffstat (limited to 'scalatexApi/src/test/scala/scalaparser/SyntaxTest.scala')
-rw-r--r-- | scalatexApi/src/test/scala/scalaparser/SyntaxTest.scala | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/scalatexApi/src/test/scala/scalaparser/SyntaxTest.scala b/scalatexApi/src/test/scala/scalaparser/SyntaxTest.scala new file mode 100644 index 0000000..d9f4820 --- /dev/null +++ b/scalatexApi/src/test/scala/scalaparser/SyntaxTest.scala @@ -0,0 +1,205 @@ +package scalaparser + +import org.parboiled2.ParseError +import utest._ +import utest.framework.Test +import utest.util.Tree + +import scala.util.{Failure, Success} + +object SyntaxTest extends TestSuite{ + def check[T](input: String) = { + new ScalaSyntax(input).CompilationUnit.run() match{ + case Failure(f: ParseError) => + println(f.position) + println(f.formatExpectedAsString) + println(f.formatTraces) + throw new Exception(f.position + "\t" + f.formatTraces) + case Success(parsed) => + assert(parsed == input) + } + } + def tests = TestSuite{ + 'unit { + * - check( + "package torimatomeru" + + ) + * - check( + """ + |package torimatomeru + | + |import org.parboiled2.ParseError + |import utest._ + |import utest.framework.Test + """.stripMargin + + ) + * - check( + """ + |package torimatomeru + | + |import org.parboiled2.ParseError + |import utest._ + |import utest.framework.Test + |import utest.util.Tree + | + |import scala.util.{Failure, Success} + | + |object SyntaxTest extends TestSuite + """.stripMargin + ) + * - check( + """ + |object SyntaxTest extends TestSuite{ + | def check[T](input: String) = { + | + | } + |} + """.stripMargin + ) + * - check( + """ + |object SyntaxTest{ + | a() + | throw 1 + |} + """.stripMargin + ) + * - check( + """ + |object SyntaxTest extends TestSuite{ + | def check[T](input: String) = { + | new ScalaSyntax(input).CompilationUnit.run() match{ + | case Failure(f: ParseError) => + | println(f.position) + | println(f.formatExpectedAsString) + | println(f.formatTraces) + | throw new Exception(f.position + "\t" + f.formatTraces) + | case Success(parsed) => + | assert(parsed == input) + | } + | } + |} + """.stripMargin + ) + * - check( + """package scalatex + | + | + |import org.parboiled2._ + |import torimatomeru.ScalaSyntax + | + |import scalatex.stages.{Trim, Parser, Ast} + |import scalatex.stages.Ast.Block.{IfElse, For, Text} + |import Ast.Chain.Args + | + |object ParserTests extends utest.TestSuite{ + | import Ast._ + | import utest._ + | def check[T](input: String, parse: Parser => scala.util.Try[T], expected: T) = { + | val parsed = parse(new Parser(input)).get + | assert(parsed == expected) + | } + | def tests = TestSuite{} + |} + """.stripMargin + ) + * - check( + """ + |object Moo{ + | a + | .b + | + | c + |} + """.stripMargin + ) + * - check( + """ + |object Moo{ + | filename + | .asInstanceOf[Literal] + |10 + |} + """.stripMargin + ) + * - check( + """ + |object Cow{ + | ().mkString + | + | 1 + |} + """.stripMargin + ) + * - check( + """ + |object O{ + | private[this] val applyMacroFull = 1 + |} + """.stripMargin + ) + * - check( + """ + |object O{ + | private[this] def applyMacroFull(c: Context) + | (expr: c.Expr[String], + | runtimeErrors: Boolean, + | debug: Boolean) + | : c.Expr[Frag] = { + | } + |} + """.stripMargin + ) + * - check( + """ + |object O{ + | class DebugFailure extends Exception + | + | 1 + |} + """.stripMargin + ) + * - check( + """ + |package torimatomeru + | + |package syntax + | + |import org.parboiled2._ + | + """.stripMargin + ) + * - check( + """ + |object Foo{ + | 0 match { + | case A | B => 0 + | } + |} + """.stripMargin + ) + } + 'file{ + def checkFile(path: String) = + check(io.Source.fromFile(path).mkString) + * - checkFile("scalatexApi/src/test/scala/scalaparser/SyntaxTest.scala") + * - checkFile("scalatexApi/src/main/scala/scalaparser/syntax/Basic.scala") + * - checkFile("scalatexApi/src/main/scala/scalaparser/syntax/Identifiers.scala") + * - checkFile("scalatexApi/src/main/scala/scalaparser/syntax/Literals.scala") + // All the commented files seem to make the parser run forever. There's probably + // some exponential performance somewhere in there, but I can't see it =/ + // * - check(io.Source.fromFile("scalatexApi/src/main/scala/scalaparser/ScalaSyntax.scala").mkString) + * - checkFile("scalatexApi/src/test/scala/scalatex/TestUtil.scala") + + + // * - check(io.Source.fromFile("scalatexApi/src/main/scala/scalatex/stages/Compiler.scala").mkString) + * - check(io.Source.fromFile("scalatexApi/src/main/scala/scalatex/stages/Parser.scala").mkString) // * - check(io.Source.fromFile("scalatexApi/src/test/scala/scalatex/ParserTests.scala").mkString) + // * - check(io.Source.fromFile("scalatexApi/src/main/scala/scalatex/stages/Trim.scala").mkString) + // * - check(io.Source.fromFile("scalatexApi/src/main/scala/scalatex/package.scala").mkString) + + } + } + +} |