Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ object MarkdownParser {

fun parse(lines: List<String>): List<StoryStepApi> {
var acc = -1
// Take care when moving the code, order matters for comparations!
return lines.map { it.trim() }
.filter { it.isNotEmpty() }
.mapIndexed { i, trimmed ->
acc++
when {
Expand Down Expand Up @@ -85,8 +85,17 @@ object MarkdownParser {
)
}

trimmed.startsWith("[] ") || trimmed.startsWith("-[] ") -> {
val type = StoryTypes.CHECK_ITEM.type
StoryStepApi(
type = StoryTypeApi(type.name, type.number),
text = trimmed.drop(3).trimStart(),
position = acc
)
}

trimmed.startsWith("- ") || trimmed.startsWith("* ") -> {
val type = StoryTypes.TEXT.type
val type = StoryTypes.UNORDERED_LIST_ITEM.type
StoryStepApi(
type = StoryTypeApi(type.name, type.number),
text = trimmed.drop(2).trimStart(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,60 @@ class MarkdownParserTest {

assertEquals(results.first().type.number, StoryTypes.TITLE.type.number)
}

@Test
fun `empty lines should not be removed`() {
val sample = listOf(
"# Sample Markdown Document",
"",
"Welcome to this **Markdown** example!",
)

val expected = listOf(
StoryTypes.TITLE.type.number to "Sample Markdown Document",
StoryTypes.TEXT.type.number to "",
StoryTypes.TEXT.type.number to "Welcome to this **Markdown** example!",
)

val results = MarkdownParser.parse(sample)
assertEquals(results.size, 3)
val parsedResults = results.map { storyStepApi ->
storyStepApi.type.number to storyStepApi.text
}

// It is necessary to compare like this because the ids won't match.
assertEquals(expected, parsedResults)
}

@Test
fun `all types should be parsed`() {
val sample = listOf(
"# Sample Markdown Document",
"",
"[] Checkitem",
"-[] Checkitem2",
"- Item list",
"#",
"---",
)

val expected = listOf(
StoryTypes.TITLE.type.number to "Sample Markdown Document",
StoryTypes.TEXT.type.number to "",
StoryTypes.CHECK_ITEM.type.number to "Checkitem",
StoryTypes.CHECK_ITEM.type.number to "Checkitem2",
StoryTypes.UNORDERED_LIST_ITEM.type.number to "Item list",
StoryTypes.TEXT.type.number to "",
StoryTypes.DIVIDER.type.number to null,
)

val results = MarkdownParser.parse(sample)
assertEquals(results.size, 7)
val parsedResults = results.map { storyStepApi ->
storyStepApi.type.number to storyStepApi.text
}

// It is necessary to compare like this because the ids won't match.
assertEquals(expected, parsedResults)
}
}