Skip to content

Commit

Permalink
feat: add test for annotator
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 16, 2023
1 parent 8f1b760 commit e046f4f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
25 changes: 22 additions & 3 deletions src/main/kotlin/cc/unitmesh/devti/language/DevtiAnnotator.kt
Expand Up @@ -7,10 +7,29 @@ import com.intellij.psi.PsiElement
class DevtiAnnotator : Annotator {
override fun annotate(element: PsiElement, holder: AnnotationHolder) {


}

companion object {
val DEVTI_REGEX = Regex("^//\\sdevti://story/github/\\d+(/.*)?$")
val DEVTI_REGEX = Regex("^//\\sdevti://story/(github)/(\\d+)(/.*)?$")

// examples: // devti://story/github/1234
fun matchByString(input: String): StoryConfig? {
val matchResult = DEVTI_REGEX.find(input)
if (matchResult != null) {
val (storySource, storyIdStr, acs) = matchResult.destructured
val storyId = storyIdStr.toIntOrNull()
if (storyId != null) {
val acList = acs.split(",").filter { it.isNotEmpty() }
return StoryConfig(storyId, storySource, acList)
}
}
return null
}
}
}
}

class StoryConfig(
val storyId: Int,
val storySource: String,
val acs: List<String> = listOf()
)
Expand Up @@ -12,10 +12,13 @@ class DisplayStoryLineMarkerContributor : RunLineMarkerContributor() {
if (element !is PsiComment) return null

val commentText = element.text
val regex = DevtiAnnotator.DEVTI_REGEX
val matchResult = regex.find(commentText) ?: return null
// val regex = DevtiAnnotator.DEVTI_REGEX
// val matchResult = regex.find(commentText) ?: return null

val storyConfig = DevtiAnnotator.matchByString(commentText) ?: return null

val state = CreateStoryConfigurationProducer().findConfig(listOf(element)) ?: return null
state.storyConfig = storyConfig

val actions = ExecutorAction.getActions(0)
return Info(
Expand Down
@@ -1,5 +1,6 @@
package cc.unitmesh.devti.runconfig.command

import cc.unitmesh.devti.language.StoryConfig
import cc.unitmesh.devti.runconfig.config.DevtiCreateStoryConfigure
import com.intellij.psi.PsiElement

Expand Down
@@ -1,13 +1,15 @@
package cc.unitmesh.devti.runconfig.config

import cc.unitmesh.devti.ai.OpenAIVersion
import cc.unitmesh.devti.language.StoryConfig
import cc.unitmesh.devti.runconfig.command.BaseConfig

class DevtiCreateStoryConfigure(
var githubToken: String,
var openAiApiKey: String,
var aiVersion: OpenAIVersion,
var aiMaxTokens: Int,
var storyConfig: StoryConfig? = null
) : BaseConfig() {
override val configurationName = "DevTi Configure"

Expand Down
Expand Up @@ -63,7 +63,6 @@ class DtSettingsEditor(project: Project) : SettingsEditor<DtRunConfiguration>()
}

override fun applyEditorTo(configuration: DtRunConfiguration) {
logger.warn("github text:${githubInput.text}")
configuration.setOptions(
DevtiCreateStoryConfigure(
githubInput.text,
Expand Down
14 changes: 14 additions & 0 deletions src/test/kotlin/cc/unitmesh/devti/language/DevtiAnnotatorTest.kt
@@ -0,0 +1,14 @@
package cc.unitmesh.devti.language

import org.junit.Test

class DevtiAnnotatorTest {
@Test
fun testMatchByString() {
val input = "// devti://story/github/1234"
val result = DevtiAnnotator.matchByString(input)
assert(result != null)
assert(result?.storyId == 1234)
assert(result?.storySource == "github")
}
}

0 comments on commit e046f4f

Please sign in to comment.