From e4935a3d2a5c807ab85914ca6540319ad6c619db Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Fri, 25 Jun 2021 19:03:17 +0200 Subject: [PATCH] Add multiple unit tests for togglePunctuation Signed-off-by: Stefan Niedermann --- .../android/markdown/MarkdownUtilTest.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/markdown/src/test/java/it/niedermann/android/markdown/MarkdownUtilTest.java b/markdown/src/test/java/it/niedermann/android/markdown/MarkdownUtilTest.java index ac4db998..19d9b189 100644 --- a/markdown/src/test/java/it/niedermann/android/markdown/MarkdownUtilTest.java +++ b/markdown/src/test/java/it/niedermann/android/markdown/MarkdownUtilTest.java @@ -293,13 +293,11 @@ public class MarkdownUtilTest extends TestCase { assertEquals(13, MarkdownUtil.togglePunctuation(builder, 0, 14, "*")); assertEquals("Lorem **ipsum** dolor sit amet.", builder.toString()); - // ######### The following one is my desired behaviour instead of this fuckup above // toggle italic around multiple existing bolds builder = new SpannableStringBuilder("Lorem **ipsum** dolor **sit** amet."); assertEquals(35, MarkdownUtil.togglePunctuation(builder, 0, 34, "*")); assertEquals("*Lorem **ipsum** dolor **sit** amet*.", builder.toString()); - // Toggle italic and bold to italic builder = new SpannableStringBuilder("Lorem ***ipsum*** dolor sit amet."); assertEquals(12, MarkdownUtil.togglePunctuation(builder, 9, 14, "**")); @@ -355,13 +353,45 @@ public class MarkdownUtilTest extends TestCase { assertEquals(24, MarkdownUtil.togglePunctuation(builder, 18, 23, "*")); assertEquals("Lorem **Ipsum** ***Dolor***", builder.toString()); + builder = new SpannableStringBuilder("Lorem **Ipsum** **Dolor**"); + assertEquals(14, MarkdownUtil.togglePunctuation(builder, 8, 13, "*")); + assertEquals("Lorem ***Ipsum*** **Dolor**", builder.toString()); + + builder = new SpannableStringBuilder("Lorem **Ipsum** **Dolor**"); + assertEquals(16, MarkdownUtil.togglePunctuation(builder, 6, 15, "*")); + assertEquals("Lorem ***Ipsum*** **Dolor**", builder.toString()); + // Toggle italic for last bold + italic in a row of multiple marked elements builder = new SpannableStringBuilder("Lorem **Ipsum** ***Dolor***"); assertEquals(23, MarkdownUtil.togglePunctuation(builder, 19, 24, "*")); assertEquals("Lorem **Ipsum** **Dolor**", builder.toString()); + builder = new SpannableStringBuilder("Lorem ***Ipsum*** **Dolor**"); + assertEquals(13, MarkdownUtil.togglePunctuation(builder, 9, 14, "*")); + assertEquals("Lorem **Ipsum** **Dolor**", builder.toString()); + + builder = new SpannableStringBuilder("Lorem ***Ipsum*** **Dolor**"); + assertEquals(15, MarkdownUtil.togglePunctuation(builder, 6, 17, "*")); + assertEquals("Lorem **Ipsum** **Dolor**", builder.toString()); + + builder = new SpannableStringBuilder("Lorem ***Ipsum*** **Dolor**"); + assertEquals(15, MarkdownUtil.togglePunctuation(builder, 7, 16, "*")); + assertEquals("Lorem **Ipsum** **Dolor**", builder.toString()); + + builder = new SpannableStringBuilder("Lorem ***Ipsum*** **Dolor**"); + assertEquals(15, MarkdownUtil.togglePunctuation(builder, 7, 17, "*")); + assertEquals("Lorem **Ipsum** **Dolor**", builder.toString()); + + builder = new SpannableStringBuilder("Lorem ***Ipsum*** **Dolor**"); + assertEquals(15, MarkdownUtil.togglePunctuation(builder, 8, 16, "*")); + assertEquals("Lorem **Ipsum** **Dolor**", builder.toString()); + // Multiline + builder = new SpannableStringBuilder("Lorem ***Ipsum***\n **Dolor**"); + assertEquals(29, MarkdownUtil.togglePunctuation(builder, 0, 28, "*")); + assertEquals("*Lorem ***Ipsum***\n **Dolor***", builder.toString()); + builder = new SpannableStringBuilder("**Bold**\nItalic"); assertEquals(16, MarkdownUtil.togglePunctuation(builder, 9, 15, "*")); assertEquals("**Bold**\n*Italic*", builder.toString());