summaryrefslogtreecommitdiff
path: root/scalatexApi/src/test/scala/torimatomeru/SyntaxTest.scala
blob: 7f1794c47bb5a46676371ec4d47e4e8180ae5f04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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{
  def check[T](input: String, parse: ScalaSyntax => scala.util.Try[T], expected: T) = {
    parse(new ScalaSyntax(input)) match{
      case Failure(f: ParseError) =>
        println(f.formatTraces)
        throw new Exception(f.formatTraces)
      case Success(parsed) =>
        assert(parsed == expected)
    }

  }
  def tests = TestSuite{

    * - check(
      """(1
        |)""".stripMargin,
      _.ArgumentExprs().run(), ()
    )
    * - check(
      """(1,
        |1)""".stripMargin,
      _.ArgumentExprs().run(), ()
    )
    * - check(
      """(1, 2,
        |3
        |,
        |4
        |)""".stripMargin,
      _.ArgumentExprs().run(), ()
    )
  }
}