Skip to content

Commit f7244e4

Browse files
committed
feat(tasking): add Tasking class and test cases #79
- Add Tasking class with properties id, name, and status. - Add TaskingStatus enum with values TODO, DOING, and DONE. - Implement fromMarkdown function in Tasking class to parse GitHub Markdown into Tasking objects. - Add test cases for creating Tasking objects from valid markdown and checking the name and status.
1 parent 2a11e29 commit f7244e4

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

kotlin/src/main/kotlin/cc/unitmesh/kotlin/provider/KotlinWriteTestService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class KotlinWriteTestService : WriteTestService() {
9090

9191
project.guessProjectDir()?.refresh(true, true)
9292

93-
val currentClass: String = runReadAction {
93+
val currentClass: String = ReadAction.compute<String, Throwable> {
9494
val classContext = when (element) {
9595
is KtClassOrObject -> ClassContextProvider(false).from(element)
9696
is KtNamedFunction -> {
@@ -102,7 +102,7 @@ class KotlinWriteTestService : WriteTestService() {
102102
else -> null
103103
}
104104

105-
return@runReadAction classContext?.format() ?: ""
105+
return@compute classContext?.format() ?: ""
106106
}
107107

108108
val imports: List<String> = runReadAction {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cc.unitmesh.devti.pair.tasking
2+
3+
enum class TaskingStatus {
4+
TODO,
5+
DOING,
6+
DONE,
7+
}
8+
9+
data class Tasking(
10+
val id: Int,
11+
val name: String,
12+
val status: TaskingStatus,
13+
) {
14+
companion object {
15+
/**
16+
* Parse GitHub Markdown to Tasking
17+
* Example input:
18+
* ```markdown
19+
* - [ ] Task 1
20+
* - [ ] Task 2
21+
* ```
22+
*/
23+
fun fromMarkdown(markdown: String): List<Tasking> {
24+
val taskRegex = Regex("^[\\s*-]*\\[([\\s*x])\\] (.+)", RegexOption.MULTILINE)
25+
val matches = taskRegex.findAll(markdown)
26+
27+
val tasks = matches.map { matchResult ->
28+
val (statusChar, taskName) = matchResult.destructured
29+
val status = when (statusChar.trim()) {
30+
"x" -> TaskingStatus.DONE
31+
else -> TaskingStatus.TODO
32+
}
33+
34+
Tasking(id = 0, name = taskName.trim(), status = status)
35+
}.toList()
36+
37+
return tasks
38+
}
39+
}
40+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cc.unitmesh.devti.pair.tasking;
2+
3+
import junit.framework.TestCase.assertEquals
4+
import org.junit.Test
5+
6+
class TaskingTest {
7+
@Test
8+
fun `should create Tasking object from valid markdown`() {
9+
// given
10+
val markdown = """
11+
- [ ] Task 1
12+
- [ ] Task 2
13+
""".trimIndent()
14+
15+
// when
16+
val tasking = Tasking.fromMarkdown(markdown)[0]
17+
18+
// then
19+
assertEquals("Task 1", tasking.name)
20+
assertEquals(TaskingStatus.TODO, tasking.status)
21+
}
22+
23+
@Test
24+
fun `should create Tasking object with status DONE from valid markdown`() {
25+
// given
26+
val markdown = """
27+
- [x] Task 1
28+
- [ ] Task 2
29+
""".trimIndent()
30+
31+
// when
32+
val tasks = Tasking.fromMarkdown(markdown)
33+
val tasking = tasks[0]
34+
35+
// then
36+
assertEquals("Task 1", tasking.name)
37+
assertEquals(TaskingStatus.DONE, tasking.status)
38+
39+
val tasking2 = tasks[1]
40+
assertEquals("Task 2", tasking2.name)
41+
assertEquals(TaskingStatus.TODO, tasking2.status)
42+
}
43+
}

0 commit comments

Comments
 (0)