Sha256: ab4c99772d437fdce5f953eedf6071001f4a74b919bcf794a7539026de615a6a

Contents?: true

Size: 1.85 KB

Versions: 71

Compression:

Stored size: 1.85 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 fromLabeledTestFromInput(argNames: String*): ToTestCaseData =
      withLabeledTest { sut =>
        labeledTest =>
          val args = sutArgsFromInput(labeledTest.result, argNames: _*)
          val property = labeledTest.property
          val expected = toString(labeledTest.expected)

          val useDateTime = labeledTest.result("input")
            .asInstanceOf[Map[String, Any]]("birthdate")
            .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, fromLabeledTestFromInput("birthdate"),
      Seq("java.time.LocalDate", "java.time.LocalDateTime", "java.time.format.DateTimeFormatter"),
      Seq(dateTimeFn, dateFn))
    println(s"-------------")
    println(code)
    println(s"-------------")
  }
}

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.179 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.178 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.177 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.176 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.175 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.174 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.173 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.172 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.171 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.170 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.169 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.167 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.166 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.165 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.164 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.163 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.162 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.161 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala
trackler-2.2.1.160 tracks/scala/testgen/src/main/scala/GigasecondTestGenerator.scala