From 4ccbed52bbf98ec782a96dada6c7068304f3bae3 Mon Sep 17 00:00:00 2001 From: Jimmy-7664 <47916283+Jimmy-7664@users.noreply.github.com> Date: Mon, 10 May 2021 21:26:56 +0800 Subject: [PATCH] Update MarkdownUtilTest.java --- .../android/markdown/MarkdownUtilTest.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java b/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java index 575815d7..72e0c373 100644 --- a/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java +++ b/markdown/src/androidTest/java/it/niedermann/android/markdown/MarkdownUtilTest.java @@ -161,13 +161,14 @@ public class MarkdownUtilTest extends TestCase { lines.forEach((key, value) -> assertEquals(value, (Boolean) MarkdownUtil.lineStartsWithCheckbox(key))); } + @Test @Test public void testTogglePunctuation() { Editable builder; // Add italic builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); - assertEquals(13, MarkdownUtil.togglePunctuation(builder, 6, 11, "*")); + assertEquals(12, MarkdownUtil.togglePunctuation(builder, 6, 11, "*")); assertEquals("Lorem *ipsum* dolor sit amet.", builder.toString()); // Remove italic @@ -177,7 +178,7 @@ public class MarkdownUtilTest extends TestCase { // Add bold builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); - assertEquals(15, MarkdownUtil.togglePunctuation(builder, 6, 11, "**")); + assertEquals(13, MarkdownUtil.togglePunctuation(builder, 6, 11, "**")); assertEquals("Lorem **ipsum** dolor sit amet.", builder.toString()); // Remove bold @@ -187,7 +188,7 @@ public class MarkdownUtilTest extends TestCase { // Add strike builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); - assertEquals(15, MarkdownUtil.togglePunctuation(builder, 6, 11, "~~")); + assertEquals(13, MarkdownUtil.togglePunctuation(builder, 6, 11, "~~")); assertEquals("Lorem ~~ipsum~~ dolor sit amet.", builder.toString()); // Remove strike @@ -197,7 +198,7 @@ public class MarkdownUtilTest extends TestCase { // Add italic at first position builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); - assertEquals(7, MarkdownUtil.togglePunctuation(builder, 0, 5, "*")); + assertEquals(6, MarkdownUtil.togglePunctuation(builder, 0, 5, "*")); assertEquals("*Lorem* ipsum dolor sit amet.", builder.toString()); // Remove italic from first position @@ -207,7 +208,7 @@ public class MarkdownUtilTest extends TestCase { // Add italic at last position builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); - assertEquals(29, MarkdownUtil.togglePunctuation(builder, 22, 27, "*")); + assertEquals(28, MarkdownUtil.togglePunctuation(builder, 22, 27, "*")); assertEquals("Lorem ipsum dolor sit *amet.*", builder.toString()); // Remove italic from last position @@ -242,11 +243,9 @@ public class MarkdownUtilTest extends TestCase { assertEquals(21, MarkdownUtil.togglePunctuation(builder, 0, 31, "*")); assertEquals("Lorem ipsum dolor sit amet.", builder.toString()); - // Special use-case: toggle from italic to bold and back - // Toggle italic on bold text builder = new SpannableStringBuilder("Lorem **ipsum** dolor sit amet."); - assertEquals(17, MarkdownUtil.togglePunctuation(builder, 8, 13, "*")); + assertEquals(16, MarkdownUtil.togglePunctuation(builder, 8, 13, "*")); assertEquals("Lorem ***ipsum*** dolor sit amet.", builder.toString()); // Toggle bold on italic text @@ -256,12 +255,12 @@ public class MarkdownUtilTest extends TestCase { // Toggle bold to italic builder = new SpannableStringBuilder("Lorem **ipsum** dolor sit amet."); - assertEquals(17, MarkdownUtil.togglePunctuation(builder, 0, 31, "*")); + assertEquals(16, MarkdownUtil.togglePunctuation(builder, 0, 31, "*")); assertEquals("Lorem ***ipsum*** dolor sit amet.", builder.toString()); // Toggle multiple bold parts to italic builder = new SpannableStringBuilder("Lorem **ipsum** dolor **sit** amet."); - assertEquals(33, MarkdownUtil.togglePunctuation(builder, 0, 34, "*")); + assertEquals(32, MarkdownUtil.togglePunctuation(builder, 0, 34, "*")); assertEquals("Lorem ***ipsum*** dolor ***sit*** amet.", builder.toString()); // Toggle italic and bold to bold @@ -283,38 +282,39 @@ public class MarkdownUtilTest extends TestCase { builder = new SpannableStringBuilder("Lorem ***ipsum*** dolor ***sit*** amet."); assertEquals(24, MarkdownUtil.togglePunctuation(builder, 0, 38, "**")); assertEquals("Lorem *ipsum* dolor *sit* amet.", builder.toString()); - + // Toggle italic on an empty text builder = new SpannableStringBuilder(""); - assertEquals(0, MarkdownUtil.togglePunctuation(builder, 0, 0, "*")); - assertEquals("", builder.toString()); + assertEquals(1, MarkdownUtil.togglePunctuation(builder, 0, 0, "*")); + assertEquals("**", builder.toString()); // Toggle italic on a blank selection builder = new SpannableStringBuilder(" "); - assertEquals(1, MarkdownUtil.togglePunctuation(builder, 0, 1, "*")); - assertEquals(" ", builder.toString()); + assertEquals(2, MarkdownUtil.togglePunctuation(builder, 0, 1, "*")); + assertEquals("* *", builder.toString()); // Toggle italic on a partial blank selection builder = new SpannableStringBuilder(" "); - assertEquals(2, MarkdownUtil.togglePunctuation(builder, 1, 2, "*")); - assertEquals(" ", builder.toString()); + assertEquals(3, MarkdownUtil.togglePunctuation(builder, 1, 2, "*")); + assertEquals(" * * ", builder.toString()); // Toggle bold on an empty text builder = new SpannableStringBuilder(""); - assertEquals(0, MarkdownUtil.togglePunctuation(builder, 0, 0, "**")); - assertEquals("", builder.toString()); + assertEquals(2, MarkdownUtil.togglePunctuation(builder, 0, 0, "**")); + assertEquals("****", builder.toString()); // Toggle bold on a blank selection builder = new SpannableStringBuilder(" "); - assertEquals(1, MarkdownUtil.togglePunctuation(builder, 0, 1, "**")); - assertEquals(" ", builder.toString()); + assertEquals(3, MarkdownUtil.togglePunctuation(builder, 0, 1, "**")); + assertEquals("** **", builder.toString()); // Toggle bold on a partial blank selection builder = new SpannableStringBuilder(" "); - assertEquals(2, MarkdownUtil.togglePunctuation(builder, 1, 2, "**")); - assertEquals(" ", builder.toString()); + assertEquals(4, MarkdownUtil.togglePunctuation(builder, 1, 2, "**")); + assertEquals(" ** ** ", builder.toString()); } + @Test public void testInsertLink() { Editable builder;