Sha256: f4d5aa3de55b578156eab60cfd12747568dcbfa046b3ff2e593af55bd05e5bae

Contents?: true

Size: 1.65 KB

Versions: 76

Compression:

Stored size: 1.65 KB

Contents

import java.io.File

import testgen.TestSuiteBuilder._
import testgen._

object ConnectTestGenerator {
  def main(args: Array[String]): Unit = {
    val file = new File("src/main/resources/connect.json")

    def toString(expected: CanonicalDataParser.Expected): String = {
      expected match {
        case Right("") => "None"
        case Right("X") => s"""Some(Color.Black)"""
        case Right("O") => s"""Some(Color.White)"""
        case _ => throw new IllegalArgumentException
      }
    }

    def sutArgs(parseResult: CanonicalDataParser.ParseResult, argNames: String*): String =
      argNames map (name => toArgString(parseResult(name))) mkString ", "

    def toArgString(any: Any): String = {
      any match {
        case list: List[_] =>
          val vals = list.map(s => TestSuiteBuilder.toString(s)).mkString(", ")
          s"mkBoard(List($vals))"
        case _ => any.toString
      }
    }

    def fromLabeledTest(argNames: String*): ToTestCaseData =
      withLabeledTest { sut =>
        labeledTest =>
          val args = sutArgs(labeledTest.result, argNames: _*)
          val property = labeledTest.property
          val sutCall =
            s"""$sut($args).$property"""
          val expected = toString(labeledTest.expected)
          TestCaseData(labeledTest.description, sutCall, expected)
      }

    val code = TestSuiteBuilder.build(file, fromLabeledTest("board"),
      Seq(),
      Seq("// Filter readable board into valid input",
          "private def mkBoard(lines: List[String]): List[String] =",
          "lines.map(l => l.filter(!_.isSpaceChar))"))

    println(s"-------------")
    println(code)
    println(s"-------------")
  }
}

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
trackler-2.2.1.46 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.45 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.44 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.43 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.42 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.41 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.40 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.39 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.38 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.37 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.36 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.35 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.34 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.33 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.32 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.31 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala