ImportParserSpec.scala 2.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//
// Copyright (C) 2017 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco.  If not, see <http://www.gnu.org/licenses/>.
//
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package de.tu_darmstadt.cs.esa.tapasco.parser
import  org.scalacheck._
import  org.scalatest._
import  org.scalatest.prop.Checkers
import  fastparse.all._

class ImportParserSpec extends FlatSpec with Matchers with Checkers {
  import org.scalacheck.Prop._
  import ImportParser._, ImportParserSpec._, Common._
  implicit val cfg = PropertyCheckConfiguration(minSize = 10000)

  "All valid Import jobs" should "be correctly parsed by importzip" in
    check(forAllNoShrink(importGen) { i =>
      checkParsed(P( importzip ~ End ).parse(i))
    })
}

private object ImportParserSpec {
  import BasicParserSpec._, CommonArgParsersSpec._, GlobalOptionsSpec.pathGen

  val descriptionGen: Gen[String] = join(Seq(
    genLongOption("description"),
    qstringGen
  ))

  val avgClockCyclesGen: Gen[String] = join(Seq(
    genLongOption("averageClockCycles"),
    Gen.posNum[Int] map (_.toString)
  ))

49
50
51
52
53
54
55
56
57
58
  val synthOptionsGen: Gen[String] = join(Seq(
    genLongOption("synthOptions"),
    qstringGen
  ))

  val optimizationGen: Gen[String] = join(Seq(
    genLongOption("optimization"),
    Gen.posNum[Int] map (_.toString)
  ))

59
60
61
62
  val optionGen: Gen[String] = Gen.oneOf(
    descriptionGen,
    avgClockCyclesGen,
    architecturesGen,
63
64
65
    platformsGen,
    synthOptionsGen,
    optimizationGen
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  )

  val optionsGen: Gen[String] = for {
    n <- Gen.choose(0, 10)
    s <- join(0 until n map (_ => optionGen))
  } yield s

  val importGen: Gen[String] = join(Seq(
    anyCase("import"),
    pathGen map (_.toString),
    "as",
    Gen.posNum[Int] map (_.toString),
    optionsGen
  ))
}