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.106 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.105 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.104 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.103 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.102 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.101 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.100 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.99 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.98 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.97 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.96 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.95 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.94 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.93 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.92 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.91 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.90 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.89 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.88 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala
trackler-2.2.1.87 tracks/scala/testgen/src/main/scala/ConnectTestGenerator.scala