evgenyigumnov / rustsn

This Rust-based tool generates, compiles, and tests code using LLMs, resolves dependencies, and provides explanations of existing code through embeddings.
Apache License 2.0
60 stars 15 forks source link

Add Kotlin support #7

Closed evgenyigumnov closed 1 month ago

evgenyigumnov commented 1 month ago
  1. Create folder "kotlin"
  2. Create copies of "prompt.txt" in the "kotlin" folder

Launch example

rustsn --lang=kotlin

Example query:

take 2 params and add them and return result

Example generation:

build.gradle.kts

plugins {
    kotlin("jvm") version "1.8.0"
    application
}

group = "com.example"
version = "1.0.0"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(kotlin("test"))
}

application {
    mainClass.set("com.example.SolutionKt")
}

tasks.test {
    useJUnitPlatform()
}

src/main/kotlin/com/example/Solution.kt

fun solution(a: Any, b: Any): Any {
    return when {
        a is Int && b is Int -> a + b
        a is String && b is Int -> a + b.toString()
        else -> throw IllegalArgumentException("Unsupported parameter types")
    }
}

fun main() {
    println(solution(1, 2))        // Outputs: 3
    println(solution(-1, -2))      // Outputs: -3
    println(solution("1", 2))      // Outputs: 12
}

src/test/kotlin/com/example/SolutionTest.kt

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

class SolutionTest {

    @Test
    fun test1() {
        assertEquals(3, solution(1, 2))
    }

    @Test
    fun test2() {
        assertEquals(-3, solution(-1, -2))
    }

    @Test
    fun test3() {
        assertEquals("12", solution("1", 2))
    }

    @Test
    fun testInvalidParams() {
        assertFailsWith<IllegalArgumentException> {
            solution(1.0, 2.0)
        }
    }
}

Example install dependencies

./gradlew build

Example launch compilation

./gradlew build

Example launch tests

./gradlew test