-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a647f50
commit 95c52fa
Showing
2 changed files
with
102 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
83 changes: 83 additions & 0 deletions
83
...est/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserTest.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,83 @@ | ||
package com.mohamedrejeb.richeditor.parser.markdown | ||
|
||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class RichTextStateMarkdownParserTest { | ||
|
||
@Test | ||
fun testBold() { | ||
val markdown = "**Hello World!**" | ||
val expectedText = "Hello World!" | ||
val state = RichTextStateMarkdownParser.encode(markdown) | ||
val actualText = state.annotatedString.text | ||
|
||
assertEquals( | ||
expected = expectedText, | ||
actual = actualText, | ||
) | ||
|
||
assertEquals( | ||
expected = SpanStyle(fontWeight = FontWeight.Bold), | ||
actual = state.richParagraphList.first().children.first().spanStyle | ||
) | ||
} | ||
|
||
@Test | ||
fun testBoldWithNestedItalic() { | ||
val markdown = "**Hello *World!***" | ||
val expectedText = "Hello World!" | ||
val state = RichTextStateMarkdownParser.encode(markdown) | ||
val actualText = state.annotatedString.text | ||
|
||
assertEquals( | ||
expected = expectedText, | ||
actual = actualText, | ||
) | ||
|
||
val firstChild = state.richParagraphList.first().children.first() | ||
val secondChild = firstChild.children.first() | ||
|
||
assertEquals( | ||
expected = SpanStyle(fontWeight = FontWeight.Bold), | ||
actual = firstChild.spanStyle | ||
) | ||
|
||
assertEquals( | ||
expected = SpanStyle(fontStyle = FontStyle.Italic), | ||
actual = secondChild.spanStyle | ||
) | ||
} | ||
|
||
|
||
|
||
@Test | ||
fun testBoldWithNestedItalicAndUnderline() { | ||
val markdown = "**Hello *World!***" | ||
val expectedText = "Hello World!" | ||
val state = RichTextStateMarkdownParser.encode(markdown) | ||
val actualText = state.annotatedString.text | ||
|
||
assertEquals( | ||
expected = expectedText, | ||
actual = actualText, | ||
) | ||
|
||
val firstChild = state.richParagraphList.first().children.first() | ||
val secondChild = firstChild.children.first() | ||
|
||
assertEquals( | ||
expected = SpanStyle(fontWeight = FontWeight.Bold), | ||
actual = firstChild.spanStyle | ||
) | ||
|
||
assertEquals( | ||
expected = SpanStyle(fontStyle = FontStyle.Italic), | ||
actual = secondChild.spanStyle | ||
) | ||
} | ||
|
||
} |