diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt index c6f80a8ef0..35d0bf6c86 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt @@ -93,7 +93,7 @@ class MarkdownParserTest : InstrumentedTest { @Test fun parseItalic2() { // Riot-Web format - "_italic_".let { markdownParser.parse(it) }.expect("italic", "italic") + "_italic_".let { markdownParser.parse(it).expect(it, "italic") } } /** @@ -113,9 +113,7 @@ class MarkdownParserTest : InstrumentedTest { testType( name = "code", markdownPattern = "`", - htmlExpectedTag = "code", - plainTextPrefix = "\"", - plainTextSuffix = "\"" + htmlExpectedTag = "code" ) } @@ -124,9 +122,7 @@ class MarkdownParserTest : InstrumentedTest { testType( name = "code", markdownPattern = "``", - htmlExpectedTag = "code", - plainTextPrefix = "\"", - plainTextSuffix = "\"" + htmlExpectedTag = "code" ) } @@ -135,9 +131,7 @@ class MarkdownParserTest : InstrumentedTest { testType( name = "code", markdownPattern = "```", - htmlExpectedTag = "code", - plainTextPrefix = "\"", - plainTextSuffix = "\"" + htmlExpectedTag = "code" ) } @@ -155,58 +149,58 @@ class MarkdownParserTest : InstrumentedTest { @Test fun parseHorizontalLine() { - "---".let { markdownParser.parse(it) }.expect("***", "
") + "---".let { markdownParser.parse(it).expect(it, "
") } } @Test fun parseH2AndContent() { - "a\n---\nb".let { markdownParser.parse(it) }.expect("a\nb", "

a

b

") + "a\n---\nb".let { markdownParser.parse(it).expect(it, "

a

b

") } } @Test fun parseQuote() { - "> quoted".let { markdownParser.parse(it) }.expect("«quoted»", "

quoted

") + "> quoted".let { markdownParser.parse(it).expect(it, "

quoted

") } } @Test fun parseQuote_not_passing() { - "> quoted\nline2".let { markdownParser.parse(it) }.expect("«quoted\nline2»", "

quoted
line2

") + "> quoted\nline2".let { markdownParser.parse(it).expect(it, "

quoted
line2

") } } @Test fun parseBoldItalic() { - "*italic* **bold**".let { markdownParser.parse(it) }.expect("italic bold", "italic bold") - "**bold** *italic*".let { markdownParser.parse(it) }.expect("bold italic", "bold italic") + "*italic* **bold**".let { markdownParser.parse(it).expect(it, "italic bold") } + "**bold** *italic*".let { markdownParser.parse(it).expect(it, "bold italic") } } @Test fun parseHead() { - "# head1".let { markdownParser.parse(it) }.expect("head1", "

head1

") - "## head2".let { markdownParser.parse(it) }.expect("head2", "

head2

") - "### head3".let { markdownParser.parse(it) }.expect("head3", "

head3

") - "#### head4".let { markdownParser.parse(it) }.expect("head4", "

head4

") - "##### head5".let { markdownParser.parse(it) }.expect("head5", "
head5
") - "###### head6".let { markdownParser.parse(it) }.expect("head6", "
head6
") + "# head1".let { markdownParser.parse(it).expect(it, "

head1

") } + "## head2".let { markdownParser.parse(it).expect(it, "

head2

") } + "### head3".let { markdownParser.parse(it).expect(it, "

head3

") } + "#### head4".let { markdownParser.parse(it).expect(it, "

head4

") } + "##### head5".let { markdownParser.parse(it).expect(it, "
head5
") } + "###### head6".let { markdownParser.parse(it).expect(it, "
head6
") } } @Test fun parseHeads() { - "# head1\n# head2".let { markdownParser.parse(it) }.expect("head1\nhead2", "

head1

head2

") + "# head1\n# head2".let { markdownParser.parse(it).expect(it, "

head1

head2

") } } @Test fun parseBoldNewLines_not_passing() { - "**bold**\nline2".let { markdownParser.parse(it) }.expect("bold\nline2", "bold
line2") + "**bold**\nline2".let { markdownParser.parse(it).expect(it, "bold
line2") } } @Test fun parseLinks() { - "[link](target)".let { markdownParser.parse(it) }.expect(""""link" (target)""", """link""") + "[link](target)".let { markdownParser.parse(it).expect(it, """link""") } } @Test fun parseParagraph() { - "# head\ncontent".let { markdownParser.parse(it) }.expect("head\ncontent", "

head

content

") + "# head\ncontent".let { markdownParser.parse(it).expect(it, "

head

content

") } } private fun testIdentity(text: String) { @@ -215,59 +209,73 @@ class MarkdownParserTest : InstrumentedTest { private fun testType(name: String, markdownPattern: String, - htmlExpectedTag: String, - plainTextPrefix: String = "", - plainTextSuffix: String = "") { + htmlExpectedTag: String) { // Test simple case "$markdownPattern$name$markdownPattern" - .let { markdownParser.parse(it) } - .expect(expectedText = "$plainTextPrefix$name$plainTextSuffix", - expectedFormattedText = "<$htmlExpectedTag>$name") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "<$htmlExpectedTag>$name") + } // Test twice the same tag "$markdownPattern$name$markdownPattern and $markdownPattern$name bis$markdownPattern" - .let { markdownParser.parse(it) } - .expect(expectedText = "$plainTextPrefix$name$plainTextSuffix and $plainTextPrefix$name bis$plainTextSuffix", - expectedFormattedText = "<$htmlExpectedTag>$name and <$htmlExpectedTag>$name bis") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "<$htmlExpectedTag>$name and <$htmlExpectedTag>$name bis") + } val textBefore = "a" val textAfter = "b" // With sticked text before "$textBefore$markdownPattern$name$markdownPattern" - .let { markdownParser.parse(it) } - .expect(expectedText = "$textBefore$plainTextPrefix$name$plainTextSuffix", - expectedFormattedText = "$textBefore<$htmlExpectedTag>$name") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "$textBefore<$htmlExpectedTag>$name") + } // With text before and space "$textBefore $markdownPattern$name$markdownPattern" - .let { markdownParser.parse(it) } - .expect(expectedText = "$textBefore $plainTextPrefix$name$plainTextSuffix", - expectedFormattedText = "$textBefore <$htmlExpectedTag>$name") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "$textBefore <$htmlExpectedTag>$name") + } // With sticked text after "$markdownPattern$name$markdownPattern$textAfter" - .let { markdownParser.parse(it) } - .expect(expectedText = "$plainTextPrefix$name$plainTextSuffix$textAfter", - expectedFormattedText = "<$htmlExpectedTag>$name$textAfter") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "<$htmlExpectedTag>$name$textAfter") + } // With space and text after "$markdownPattern$name$markdownPattern $textAfter" - .let { markdownParser.parse(it) } - .expect(expectedText = "$plainTextPrefix$name$plainTextSuffix $textAfter", - expectedFormattedText = "<$htmlExpectedTag>$name $textAfter") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "<$htmlExpectedTag>$name $textAfter") + } // With sticked text before and text after "$textBefore$markdownPattern$name$markdownPattern$textAfter" - .let { markdownParser.parse(it) } - .expect(expectedText = "$textBefore$plainTextPrefix$name$plainTextSuffix$textAfter", - expectedFormattedText = "a<$htmlExpectedTag>$name$textAfter") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "a<$htmlExpectedTag>$name$textAfter") + } // With text before and after, with spaces "$textBefore $markdownPattern$name$markdownPattern $textAfter" - .let { markdownParser.parse(it) } - .expect(expectedText = "$textBefore $plainTextPrefix$name$plainTextSuffix $textAfter", - expectedFormattedText = "$textBefore <$htmlExpectedTag>$name $textAfter") + .let { + markdownParser.parse(it) + .expect(expectedText = it, + expectedFormattedText = "$textBefore <$htmlExpectedTag>$name $textAfter") + } } private fun TextContent.expect(expectedText: String, expectedFormattedText: String?) {