mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-26 06:47:03 +03:00
Update MarkdownUtilTest.java
This commit is contained in:
parent
c0356909a1
commit
4ccbed52bb
1 changed files with 23 additions and 23 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue