-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix after block issue & write test for after block
- Loading branch information
Showing
3 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...src/test/kotlin/cc/unitmesh/pick/prompt/completion/AfterBlockCodeCompletionBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cc.unitmesh.pick.prompt.completion; | ||
|
||
import cc.unitmesh.pick.builder.BuilderConfig | ||
import cc.unitmesh.pick.builder.InstructionFileJob | ||
import cc.unitmesh.pick.prompt.CodeCompletionIns | ||
import cc.unitmesh.pick.prompt.JobContext | ||
import chapi.domain.core.CodeFunction | ||
import chapi.domain.core.CodePosition | ||
import io.kotest.matchers.shouldBe | ||
import org.archguard.scanner.analyser.count.FileJob | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class AfterBlockCodeCompletionBuilderTest { | ||
|
||
@Test | ||
fun should_success_split_after_block_code() { | ||
val codeFunction = CodeFunction( | ||
Position = CodePosition(1, 0, 3) | ||
) | ||
val codeLines = """ | ||
fun myFunction() { | ||
println("Hello, world!") | ||
} | ||
// other code here | ||
""".trimIndent().lines() | ||
val job = InstructionFileJob( | ||
fileSummary = FileJob(), | ||
codeLines = codeLines, | ||
code = codeLines.joinToString("\n") | ||
) | ||
val jobContext = JobContext(job, emptyList(), hashMapOf("" to job), BuilderConfig(), emptyList()) | ||
val builder = AfterBlockCodeCompletionBuilder(jobContext) | ||
|
||
val result = builder.build(codeFunction) | ||
|
||
result shouldBe listOf( | ||
CodeCompletionIns( | ||
beforeCursor = codeLines.subList(0, 3).joinToString("\n"), | ||
afterCursor = "// other code here" | ||
) | ||
) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...er/src/test/kotlin/cc/unitmesh/pick/prompt/completion/InBlockCodeCompletionBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cc.unitmesh.pick.prompt.completion; | ||
|
||
import cc.unitmesh.pick.builder.BuilderConfig | ||
import cc.unitmesh.pick.builder.InstructionFileJob | ||
import cc.unitmesh.pick.prompt.CodeCompletionIns | ||
import cc.unitmesh.pick.prompt.JobContext | ||
import chapi.domain.core.CodeFunction | ||
import chapi.domain.core.CodePosition | ||
import io.kotest.matchers.shouldBe | ||
import org.archguard.scanner.analyser.count.FileJob | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.Assertions.* | ||
|
||
class InBlockCodeCompletionBuilderTest { | ||
|
||
@Test | ||
fun should_return_single_CodeCompletionIns() { | ||
val codeFunction = CodeFunction( | ||
Position = CodePosition(1, 0, 3) | ||
) | ||
val codeLines = """ | ||
fun myFunction() { | ||
println("Hello, world!") | ||
} | ||
// other code here | ||
""".trimIndent().lines() | ||
val job = InstructionFileJob( | ||
fileSummary = FileJob(), | ||
codeLines = codeLines, | ||
code = codeLines.joinToString("\n") | ||
) | ||
val jobContext = JobContext(job, emptyList(), hashMapOf("" to job), BuilderConfig(), emptyList()) | ||
val builder = InBlockCodeCompletionBuilder(jobContext) | ||
|
||
// when | ||
val result = builder.build(codeFunction) | ||
|
||
// then | ||
result.size shouldBe 1 | ||
result[0] shouldBe CodeCompletionIns( | ||
beforeCursor = codeLines.subList(0, 1).joinToString("\n"), | ||
afterCursor = codeLines.subList(1, 3).joinToString("\n") | ||
) | ||
} | ||
} |