[ai-completion] ML-3971 add a test case for preProcessLines

GitOrigin-RevId: 5a050504c56542aabdafe5d3b4a8fc11ce3d1150
This commit is contained in:
Oleg Taratukhin
2024-09-27 20:00:12 +02:00
committed by intellij-monorepo-bot
parent d61150f7b8
commit 5eba1ea80b

View File

@@ -4,14 +4,42 @@ import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class RelaxedExactMatchTest {
@Test
fun `test line pre-processing`() {
val processed = RelaxedSimilarityUtils.preProcessLines(
completion = "turn main\ndef fun",
private data class ProcessingTestCase(
val prefix: String,
val completion: String,
val suffix: String,
val strip: Boolean,
)
private val processingCases = listOf(
ProcessingTestCase(
prefix = "hi\nre",
completion = "turn main\ndef fun",
suffix = "ction()::\nendfun",
stripChars = false,
)
Assertions.assertEquals(listOf("return main", "def function()::"), processed)
strip = false,
) to listOf("return main", "def function()::"),
ProcessingTestCase(
prefix = "class MyClas",
completion = "s:\ndef __init__(self):\npass\n",
suffix = "\n def method(self):\n pass\n",
strip = false,
) to listOf("class MyClass:", "def __init__(self):", "pass"),
ProcessingTestCase(
prefix = "class MyClas",
completion = "s:\ndef __init__(self):\npass\n",
suffix = "",
strip = true,
) to listOf("classMyClass", "def__init__self", "pass"),
)
private fun ProcessingTestCase.process(): List<String> = RelaxedSimilarityUtils.preProcessLines(
completion = completion,
prefix = prefix,
suffix = suffix,
stripChars = strip,
)
@Test
fun `test line pre-processing`() = processingCases.forEach {
(inputs, outputs) -> Assertions.assertEquals(outputs, inputs.process())
}
}