Update MarkdownUtilTest.java

This commit is contained in:
Jimmy-7664 2021-05-10 21:26:56 +08:00 committed by Niedermann IT-Dienstleistungen
parent c0356909a1
commit 4ccbed52bb

View file

@ -161,13 +161,14 @@ public class MarkdownUtilTest extends TestCase {
lines.forEach((key, value) -> assertEquals(value, (Boolean) MarkdownUtil.lineStartsWithCheckbox(key))); lines.forEach((key, value) -> assertEquals(value, (Boolean) MarkdownUtil.lineStartsWithCheckbox(key)));
} }
@Test
@Test @Test
public void testTogglePunctuation() { public void testTogglePunctuation() {
Editable builder; Editable builder;
// Add italic // Add italic
builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); 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()); assertEquals("Lorem *ipsum* dolor sit amet.", builder.toString());
// Remove italic // Remove italic
@ -177,7 +178,7 @@ public class MarkdownUtilTest extends TestCase {
// Add bold // Add bold
builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); 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()); assertEquals("Lorem **ipsum** dolor sit amet.", builder.toString());
// Remove bold // Remove bold
@ -187,7 +188,7 @@ public class MarkdownUtilTest extends TestCase {
// Add strike // Add strike
builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); 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()); assertEquals("Lorem ~~ipsum~~ dolor sit amet.", builder.toString());
// Remove strike // Remove strike
@ -197,7 +198,7 @@ public class MarkdownUtilTest extends TestCase {
// Add italic at first position // Add italic at first position
builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); 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()); assertEquals("*Lorem* ipsum dolor sit amet.", builder.toString());
// Remove italic from first position // Remove italic from first position
@ -207,7 +208,7 @@ public class MarkdownUtilTest extends TestCase {
// Add italic at last position // Add italic at last position
builder = new SpannableStringBuilder("Lorem ipsum dolor sit amet."); 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()); assertEquals("Lorem ipsum dolor sit *amet.*", builder.toString());
// Remove italic from last position // Remove italic from last position
@ -242,11 +243,9 @@ public class MarkdownUtilTest extends TestCase {
assertEquals(21, MarkdownUtil.togglePunctuation(builder, 0, 31, "*")); assertEquals(21, MarkdownUtil.togglePunctuation(builder, 0, 31, "*"));
assertEquals("Lorem ipsum dolor sit amet.", builder.toString()); assertEquals("Lorem ipsum dolor sit amet.", builder.toString());
// Special use-case: toggle from italic to bold and back
// Toggle italic on bold text // Toggle italic on bold text
builder = new SpannableStringBuilder("Lorem **ipsum** dolor sit amet."); 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()); assertEquals("Lorem ***ipsum*** dolor sit amet.", builder.toString());
// Toggle bold on italic text // Toggle bold on italic text
@ -256,12 +255,12 @@ public class MarkdownUtilTest extends TestCase {
// Toggle bold to italic // Toggle bold to italic
builder = new SpannableStringBuilder("Lorem **ipsum** dolor sit amet."); 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()); assertEquals("Lorem ***ipsum*** dolor sit amet.", builder.toString());
// Toggle multiple bold parts to italic // Toggle multiple bold parts to italic
builder = new SpannableStringBuilder("Lorem **ipsum** dolor **sit** amet."); 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()); assertEquals("Lorem ***ipsum*** dolor ***sit*** amet.", builder.toString());
// Toggle italic and bold to bold // Toggle italic and bold to bold
@ -286,35 +285,36 @@ public class MarkdownUtilTest extends TestCase {
// Toggle italic on an empty text // Toggle italic on an empty text
builder = new SpannableStringBuilder(""); builder = new SpannableStringBuilder("");
assertEquals(0, MarkdownUtil.togglePunctuation(builder, 0, 0, "*")); assertEquals(1, MarkdownUtil.togglePunctuation(builder, 0, 0, "*"));
assertEquals("", builder.toString()); assertEquals("**", builder.toString());
// Toggle italic on a blank selection // Toggle italic on a blank selection
builder = new SpannableStringBuilder(" "); builder = new SpannableStringBuilder(" ");
assertEquals(1, MarkdownUtil.togglePunctuation(builder, 0, 1, "*")); assertEquals(2, MarkdownUtil.togglePunctuation(builder, 0, 1, "*"));
assertEquals(" ", builder.toString()); assertEquals("* *", builder.toString());
// Toggle italic on a partial blank selection // Toggle italic on a partial blank selection
builder = new SpannableStringBuilder(" "); builder = new SpannableStringBuilder(" ");
assertEquals(2, MarkdownUtil.togglePunctuation(builder, 1, 2, "*")); assertEquals(3, MarkdownUtil.togglePunctuation(builder, 1, 2, "*"));
assertEquals(" ", builder.toString()); assertEquals(" * * ", builder.toString());
// Toggle bold on an empty text // Toggle bold on an empty text
builder = new SpannableStringBuilder(""); builder = new SpannableStringBuilder("");
assertEquals(0, MarkdownUtil.togglePunctuation(builder, 0, 0, "**")); assertEquals(2, MarkdownUtil.togglePunctuation(builder, 0, 0, "**"));
assertEquals("", builder.toString()); assertEquals("****", builder.toString());
// Toggle bold on a blank selection // Toggle bold on a blank selection
builder = new SpannableStringBuilder(" "); builder = new SpannableStringBuilder(" ");
assertEquals(1, MarkdownUtil.togglePunctuation(builder, 0, 1, "**")); assertEquals(3, MarkdownUtil.togglePunctuation(builder, 0, 1, "**"));
assertEquals(" ", builder.toString()); assertEquals("** **", builder.toString());
// Toggle bold on a partial blank selection // Toggle bold on a partial blank selection
builder = new SpannableStringBuilder(" "); builder = new SpannableStringBuilder(" ");
assertEquals(2, MarkdownUtil.togglePunctuation(builder, 1, 2, "**")); assertEquals(4, MarkdownUtil.togglePunctuation(builder, 1, 2, "**"));
assertEquals(" ", builder.toString()); assertEquals(" ** ** ", builder.toString());
} }
@Test @Test
public void testInsertLink() { public void testInsertLink() {
Editable builder; Editable builder;