<commit_before>package models.generator.kotlin

import com.fasterxml.jackson.databind.ObjectMapper
import io.apibuilder.generator.v0.models.{File, InvocationForm}
import org.scalatest.{FunSpec, Matchers}
import java.nio.file.Files.createTempDirectory

import KotlinTestHelper._
import io.apibuilder.spec.v0.models.Service

class KotlinGeneratorTest
  extends FunSpec
    with Matchers {

  import models.TestHelper._

  val serviceDefs = Seq(apidocApiService, generatorApiServiceWithUnionAndDescriminator, dateTimeService)

  describe("invoke should output Kotlin source files") {
    for (service <- serviceDefs) {
      it(s"for service [${service.name}]") {
        generateSourceFiles(service)
      }
    }
  }

  private def generateSourceFiles(service: Service): java.io.File = {
    val tmpDir = createTempDirectory(getClass().getSimpleName).toFile
    tmpDir.deleteOnExit()
    val invocationForm = InvocationForm(service, Seq.empty, None)
    val generator = new KotlinGenerator()
    val files = generator.invoke(invocationForm).right.get
    files.size shouldBe >(0)
    files.foreach(f => {
      f.contents.length shouldBe >(0)
      f.name should endWith(".kt")
    })<commit_msg>KotlinGeneratorTest:  invoke and compile Kotlin code [builtInTypesService]<commit_after>package models.generator.kotlin

import com.fasterxml.jackson.databind.ObjectMapper
import io.apibuilder.generator.v0.models.{File, InvocationForm}
import org.scalatest.{FunSpec, Matchers}
import java.nio.file.Files.createTempDirectory

import KotlinTestHelper._
import io.apibuilder.spec.v0.models.Service

class KotlinGeneratorTest
  extends FunSpec
    with Matchers {

  import models.TestHelper._

  val serviceDefs = Seq(apidocApiService, generatorApiServiceWithUnionAndDescriminator, dateTimeService)

  describe("invoke should output Kotlin source files") {
    for (service <- serviceDefs) {
      it(s"for service [${service.name}]") {
        generateSourceFiles(service)
      }
    }
  }

  describe("built-in-types") {
    val service = builtInTypesService
    it(s"code compiles") {
      val dir = generateSourceFiles(service)
      assertValidKotlinSourceCode(dir.toPath)
    }
  }

  private def generateSourceFiles(service: Service): java.io.File = {
    val tmpDir = createTempDirectory(getClass().getSimpleName).toFile
    tmpDir.deleteOnExit()
    val invocationForm = InvocationForm(service, Seq.empty, None)
    val generator = new KotlinGenerator()
    val files = generator.invoke(invocationForm).right.get
    files.size shouldBe >(0)
    files.foreach(f => {
      f.contents.length shouldBe >(0)
      f.name should endWith(".kt")
    })
{'fraction_non_alphanumeric': 0.1004152510381276, 'fraction_numerical': 0.003020007550018875, 'mean_word_length': 4.196078431372549, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3231898', 'n_tokens_mistral': 812, 'n_tokens_neox': 792, 'n_words': 162}