Sha256: 5636f768658576e1748def738214cd911e3914b1b410f381ec8ff022221093cd

Contents?: true

Size: 1.75 KB

Versions: 95

Compression:

Stored size: 1.75 KB

Contents

import java.io.File

import testgen.TestSuiteBuilder._
import testgen._

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

    def toString(expected: CanonicalDataParser.Expected): String = {
      expected match {
        case Left(_) => throw new IllegalStateException
        case Right(null) => throw new IllegalStateException
        case Right(n) => s""""$n""""
      }
    }

    def fromLabeledTest(argNames: String*): ToTestCaseData =
      withLabeledTest { sut =>
        labeledTest =>
          val args = sutArgs(labeledTest.result, argNames: _*)
          val property = labeledTest.property
          val expected = toString(labeledTest.expected)

          val useDateTime = labeledTest.result("input").asInstanceOf[String].length > "xxxx-xx-xx".length
          val sutCall = if (useDateTime) {
            s"""val input = dateTime($args)
    val expected = dateTime($expected)
    $sut.$property(input)"""
            }
            else {
              s"""val input = date($args)
    val expected = dateTime($expected)
    $sut.$property(input)"""
            }

          TestCaseData(labeledTest.description, sutCall, "expected")
      }

    val dateTimeFn = "private def dateTime(str: String): LocalDateTime =\n    LocalDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(str))"
    val dateFn = "private def date(str: String): LocalDate =\n    LocalDate.from(DateTimeFormatter.ISO_DATE.parse(str))"
    val code = TestSuiteBuilder.build(file, fromLabeledTest("input"),
      Seq("java.time.LocalDate", "java.time.LocalDateTime", "java.time.format.DateTimeFormatter"),
      Seq(dateTimeFn, dateFn))
    println(s"-------------")
    println(code)
    println(s"-------------")
  }
}

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
trackler-2.2.1.107 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.106 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.105 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.104 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.103 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.102 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.101 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.100 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.99 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.98 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.97 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.96 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.95 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.94 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.93 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.92 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.91 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.90 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.89 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.88 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala