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