Migrated existing tests to new format
This commit is contained in:
parent
1245712ef6
commit
066b634bee
@ -84,7 +84,8 @@ public abstract class TestSpanMatcher {
|
||||
public boolean test(TestSpan.Span span) {
|
||||
return expected.name().equals(span.name())
|
||||
&& start == spanned.getSpanStart(span)
|
||||
&& end == spanned.getSpanEnd(span);
|
||||
&& end == spanned.getSpanEnd(span)
|
||||
&& expected.arguments().equals(span.arguments());
|
||||
}
|
||||
})
|
||||
.first(null);
|
||||
|
@ -15,6 +15,11 @@ import ru.noties.markwon.test.TestUtil;
|
||||
|
||||
abstract class BaseSuiteTest {
|
||||
|
||||
void match(@NonNull String markdown, @NonNull TestSpan.Document document) {
|
||||
final Spanned spanned = markwon().toMarkdown(markdown);
|
||||
TestSpanMatcher.matches(spanned, document);
|
||||
}
|
||||
|
||||
void matchInput(@NonNull String name, @NonNull TestSpan.Document document) {
|
||||
final Spanned spanned = markwon().toMarkdown(read(name));
|
||||
TestSpanMatcher.matches(spanned, document);
|
||||
@ -28,7 +33,7 @@ abstract class BaseSuiteTest {
|
||||
@NonNull
|
||||
Markwon markwon() {
|
||||
return Markwon.builder(RuntimeEnvironment.application)
|
||||
.use(CorePlugin.create())
|
||||
.use(CorePlugin.create(softBreakAddsNewLine()))
|
||||
.use(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||
@ -41,4 +46,8 @@ abstract class BaseSuiteTest {
|
||||
boolean useParagraphs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean softBreakAddsNewLine() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,6 @@ public class BlockquoteTest extends BaseSuiteTest {
|
||||
final Document document = document(
|
||||
span(BLOCK_QUOTE, text("blockquote")));
|
||||
|
||||
matchInput("single-blockquote.md", document);
|
||||
match("> blockquote", document);
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,6 @@ import static ru.noties.markwon.test.TestSpan.text;
|
||||
@Config(manifest = Config.NONE)
|
||||
public class BoldItalicTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
**_bold italic_**
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
@ -28,6 +24,6 @@ public class BoldItalicTest extends BaseSuiteTest {
|
||||
span(BOLD,
|
||||
span(ITALIC, text("bold italic"))));
|
||||
|
||||
matchInput("bold-italic.md", document);
|
||||
match("**_bold italic_**", document);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class CodeTest extends BaseSuiteTest {
|
||||
span(CODE, args("multiline", false), text("\u00a0code\u00a0"))
|
||||
);
|
||||
|
||||
matchInput("single-code.md", document);
|
||||
match("`code`", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1,27 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.ITALIC;
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.span;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class EmphasisTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(span(ITALIC, text("italic")));
|
||||
|
||||
match("*italic*", document);
|
||||
match("_italic_", document);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.HEADING;
|
||||
import static ru.noties.markwon.test.TestSpan.args;
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.span;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class HeadingTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void single_headings() {
|
||||
|
||||
final int[] levels = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
for (int level : levels) {
|
||||
|
||||
final Document document = document(
|
||||
span(HEADING, args("level", level), text("head" + level))
|
||||
);
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < level; i++) {
|
||||
builder.append('#');
|
||||
}
|
||||
builder.append(" head").append(level);
|
||||
|
||||
match(builder.toString(), document);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.LINK;
|
||||
import static ru.noties.markwon.test.TestSpan.args;
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.span;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class LinkTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(LINK, args("href", "#href"), text("link"))
|
||||
);
|
||||
|
||||
match("[link](#href)", document);
|
||||
}
|
||||
}
|
@ -103,6 +103,6 @@ public class OrderedListTest extends BaseSuiteTest {
|
||||
text("ol"))
|
||||
);
|
||||
|
||||
matchInput("single-ol.md", document);
|
||||
match("1. ol", document);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class SoftBreakAddsNewLineTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
hello there!
|
||||
this one is on the next line
|
||||
hard break to the full extend
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final Document document = document(
|
||||
text("hello there!\n"),
|
||||
text("this one is on the next line\n"),
|
||||
text("hard break to the full extend")
|
||||
);
|
||||
|
||||
matchInput("soft-break-adds-new-line.md", document);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean softBreakAddsNewLine() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class SoftBreakTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final Document document = document(
|
||||
text("First line "),
|
||||
text("same line but with space between "),
|
||||
text("this is also the first line")
|
||||
);
|
||||
|
||||
matchInput("soft-break.md", document);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean softBreakAddsNewLine() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.BOLD;
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.span;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class StrongEmphasisTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(BOLD, text("bold"))
|
||||
);
|
||||
|
||||
match("**bold**", document);
|
||||
match("__bold__", document);
|
||||
}
|
||||
}
|
@ -22,7 +22,9 @@ class TestFactory implements SpannableFactory {
|
||||
static final String BLOCK_QUOTE = "blockquote";
|
||||
static final String PARAGRAPH = "paragraph";
|
||||
static final String ORDERED_LIST = "ordered-list";
|
||||
static final String UN_ORDERED_LIST = "un-ordered-list";
|
||||
static final String HEADING = "heading";
|
||||
static final String THEMATIC_BREAK = "thematic-break";
|
||||
|
||||
private final boolean useParagraphs;
|
||||
|
||||
@ -63,13 +65,13 @@ class TestFactory implements SpannableFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object bulletListItem(@NonNull MarkwonTheme theme, int level) {
|
||||
return null;
|
||||
return span(UN_ORDERED_LIST, args("level", level));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object thematicBreak(@NonNull MarkwonTheme theme) {
|
||||
return null;
|
||||
return span(THEMATIC_BREAK);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -0,0 +1,30 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.THEMATIC_BREAK;
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.span;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class ThematicBreakTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(THEMATIC_BREAK, text("\u00a0"))
|
||||
);
|
||||
|
||||
match("---", document);
|
||||
match("----", document);
|
||||
match("***", document);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package ru.noties.markwon.core.suite;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.UN_ORDERED_LIST;
|
||||
import static ru.noties.markwon.test.TestSpan.args;
|
||||
import static ru.noties.markwon.test.TestSpan.document;
|
||||
import static ru.noties.markwon.test.TestSpan.span;
|
||||
import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class UnOrderedListTest extends BaseSuiteTest {
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(UN_ORDERED_LIST, args("level", 0), text("ul"))
|
||||
);
|
||||
|
||||
match("* ul", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
/*
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
*/
|
||||
|
||||
final Document document = document(
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 0),
|
||||
text("First\n"),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 1),
|
||||
text("Second\n"),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 2),
|
||||
text("Third"))))
|
||||
);
|
||||
|
||||
matchInput("ul.md", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void levels() {
|
||||
|
||||
/*
|
||||
* First
|
||||
* * Second
|
||||
* * * Third
|
||||
*/
|
||||
|
||||
final Document document = document(
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 0),
|
||||
text("First")),
|
||||
text("\n"),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 0),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 1),
|
||||
text("Second"))),
|
||||
text("\n"),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 0),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 1),
|
||||
span(UN_ORDERED_LIST,
|
||||
args("level", 2),
|
||||
text("Third"))))
|
||||
);
|
||||
|
||||
matchInput("ul-levels.md", document);
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
**_bold italic_**
|
@ -1,5 +0,0 @@
|
||||
input: "[link](#href)"
|
||||
|
||||
output:
|
||||
- a: "link"
|
||||
href: "#href"
|
@ -1,4 +0,0 @@
|
||||
input: "**bold**"
|
||||
|
||||
output:
|
||||
- b: "bold"
|
@ -1 +0,0 @@
|
||||
> blockquote
|
@ -1 +0,0 @@
|
||||
`code`
|
@ -1,4 +0,0 @@
|
||||
input: "# head1"
|
||||
|
||||
output:
|
||||
- h1: "head1"
|
@ -1,4 +0,0 @@
|
||||
input: "## head2"
|
||||
|
||||
output:
|
||||
- h2: "head2"
|
@ -1,4 +0,0 @@
|
||||
input: "### head3"
|
||||
|
||||
output:
|
||||
- h3: "head3"
|
@ -1,4 +0,0 @@
|
||||
input: "#### head4"
|
||||
|
||||
output:
|
||||
- h4: "head4"
|
@ -1,4 +0,0 @@
|
||||
input: "##### head5"
|
||||
|
||||
output:
|
||||
- h5: "head5"
|
@ -1,4 +0,0 @@
|
||||
input: "###### head6"
|
||||
|
||||
output:
|
||||
- h6: "head6"
|
@ -1,7 +0,0 @@
|
||||
# it is failing as we are still removing white spaces manually
|
||||
# this will be fixed when different logic for new lines will be introduced
|
||||
|
||||
input: "---"
|
||||
|
||||
output:
|
||||
- hr: "\u00a0"
|
@ -1,4 +0,0 @@
|
||||
input: "*italic*"
|
||||
|
||||
output:
|
||||
- i: "italic"
|
@ -1 +0,0 @@
|
||||
1. ol
|
@ -1,5 +0,0 @@
|
||||
input: "* ul"
|
||||
|
||||
output:
|
||||
- ul: "ul"
|
||||
level: 0
|
@ -0,0 +1,3 @@
|
||||
hello there!
|
||||
this one is on the next line
|
||||
hard break to the full extend
|
@ -1,10 +0,0 @@
|
||||
input: |-
|
||||
hello there!
|
||||
this one is on the next line
|
||||
hard break to the full extend
|
||||
|
||||
config:
|
||||
soft-break-adds-new-line: true
|
||||
|
||||
output:
|
||||
- text: "hello there!\nthis one is on the next line\nhard break to the full extend"
|
3
markwon/src/test/resources/tests/soft-break.md
Normal file
3
markwon/src/test/resources/tests/soft-break.md
Normal file
@ -0,0 +1,3 @@
|
||||
First line
|
||||
same line but with space between
|
||||
this is also the first line
|
@ -1,7 +0,0 @@
|
||||
input: |-
|
||||
First line
|
||||
same line but with space between
|
||||
this is also the first line
|
||||
|
||||
output:
|
||||
- text: "First line same line but with space between this is also the first line"
|
3
markwon/src/test/resources/tests/ul-levels.md
Normal file
3
markwon/src/test/resources/tests/ul-levels.md
Normal file
@ -0,0 +1,3 @@
|
||||
* First
|
||||
* * Second
|
||||
* * * Third
|
@ -1,20 +0,0 @@
|
||||
input: |-
|
||||
* First
|
||||
* * Second
|
||||
* * * Third
|
||||
|
||||
output:
|
||||
- ul: "First"
|
||||
level: 0
|
||||
- text: "\n"
|
||||
- ul:
|
||||
- ul: "Second"
|
||||
level: 1
|
||||
level: 0
|
||||
- text: "\n"
|
||||
- ul:
|
||||
- ul:
|
||||
- ul: "Third"
|
||||
level: 2
|
||||
level: 1
|
||||
level: 0
|
3
markwon/src/test/resources/tests/ul.md
Normal file
3
markwon/src/test/resources/tests/ul.md
Normal file
@ -0,0 +1,3 @@
|
||||
* First
|
||||
* Second
|
||||
* Third
|
@ -1,14 +0,0 @@
|
||||
input: |-
|
||||
* First
|
||||
* Second
|
||||
* Third
|
||||
|
||||
output:
|
||||
- ul:
|
||||
- text: "First\n"
|
||||
- ul:
|
||||
- text: "Second\n"
|
||||
- ul: "Third"
|
||||
level: 2
|
||||
level: 1
|
||||
level: 0
|
Loading…
x
Reference in New Issue
Block a user