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.66 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.65 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.64 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.63 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.62 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.61 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.60 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.59 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.58 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.57 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.56 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.55 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.54 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.53 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.52 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.51 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.50 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.49 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.48 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.47 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala