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.87 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.86 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.85 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.84 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.83 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.82 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.81 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.80 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.79 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.78 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.77 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.76 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.75 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.74 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.73 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.72 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.71 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.70 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.69 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.68 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala