AnmlParsingTest.scala 1.52 KB
Newer Older
1
package dahu.planning.anml.parser
2 3 4 5 6

import org.scalatest.FunSuite

class AnmlParsingTest extends FunSuite {

Arthur Bit-Monnot's avatar
Arthur Bit-Monnot committed
7
  for(anml <- InputAnmlModels.valid) {
8 9
    test("valid: " + anml) {
      Parser.parse(anml) match {
10
        case ParseSuccess(module) =>
11 12
          println("PARSED:\n" + anml + "\n")
          println("AS:\n" + module + "\n\n")
13
        case x: ParserFailure =>
14
          fail(s"Could not parse anml string: $anml\n\n${x.format}")
15
        case ParserCrash(err, _) =>
16
          err.printStackTrace()
17
          fail(s"Exception raised while parsing")
18
        case x: FileAccessError => ???
19 20 21 22
      }
    }
  }

Arthur Bit-Monnot's avatar
Arthur Bit-Monnot committed
23
  for(anml <- InputAnmlModels.invalid) {
24 25
    test("invalid: " + anml) {
      Parser.parse(anml) match {
26
        case ParseSuccess(module) =>
27
          fail(s"Following anml string should be invalid:\n$anml\n\nParsed to:\n $module")
28
        case x: ParserFailure =>
29
          println(s"Detected invalid ANML:\n${x.format}")
30
        case x => fail(s"Unexpected output: $x")
31 32 33 34
      }
    }
  }

35
  val tmp = "constant integer i; i == 2 implies (-i + 16) * 2 == -4 implies true;"
36

37 38 39 40
  test("debug: temporary") {

    /** Dummy text to facilitate testing. */
    println(tmp)
41
    Parser.parse(tmp) match {
42 43 44
      case ParseSuccess(module) =>
        println("PARSED:\n")
        println("AS:\n" + module + "\n\n")
45
      case x: ParserFailure =>
46
        fail(s"Could not parse anml string:\n${x.format}")
47
      case ParserCrash(err, _) =>
48 49
        err.printStackTrace()
        fail(s"Exception raised while parsing")
50
      case _ => ???
51
    }
52 53
  }
}