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