Migrated existing tests to new format

This commit is contained in:
Dimitry Ivanov 2018-12-17 18:25:48 +03:00
parent 1245712ef6
commit 066b634bee
38 changed files with 343 additions and 116 deletions

View File

@ -84,7 +84,8 @@ public abstract class TestSpanMatcher {
public boolean test(TestSpan.Span span) { public boolean test(TestSpan.Span span) {
return expected.name().equals(span.name()) return expected.name().equals(span.name())
&& start == spanned.getSpanStart(span) && start == spanned.getSpanStart(span)
&& end == spanned.getSpanEnd(span); && end == spanned.getSpanEnd(span)
&& expected.arguments().equals(span.arguments());
} }
}) })
.first(null); .first(null);

View File

@ -15,6 +15,11 @@ import ru.noties.markwon.test.TestUtil;
abstract class BaseSuiteTest { 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) { void matchInput(@NonNull String name, @NonNull TestSpan.Document document) {
final Spanned spanned = markwon().toMarkdown(read(name)); final Spanned spanned = markwon().toMarkdown(read(name));
TestSpanMatcher.matches(spanned, document); TestSpanMatcher.matches(spanned, document);
@ -28,7 +33,7 @@ abstract class BaseSuiteTest {
@NonNull @NonNull
Markwon markwon() { Markwon markwon() {
return Markwon.builder(RuntimeEnvironment.application) return Markwon.builder(RuntimeEnvironment.application)
.use(CorePlugin.create()) .use(CorePlugin.create(softBreakAddsNewLine()))
.use(new AbstractMarkwonPlugin() { .use(new AbstractMarkwonPlugin() {
@Override @Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
@ -41,4 +46,8 @@ abstract class BaseSuiteTest {
boolean useParagraphs() { boolean useParagraphs() {
return false; return false;
} }
boolean softBreakAddsNewLine() {
return false;
}
} }

View File

@ -43,6 +43,6 @@ public class BlockquoteTest extends BaseSuiteTest {
final Document document = document( final Document document = document(
span(BLOCK_QUOTE, text("blockquote"))); span(BLOCK_QUOTE, text("blockquote")));
matchInput("single-blockquote.md", document); match("> blockquote", document);
} }
} }

View File

@ -17,10 +17,6 @@ import static ru.noties.markwon.test.TestSpan.text;
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class BoldItalicTest extends BaseSuiteTest { public class BoldItalicTest extends BaseSuiteTest {
/*
**_bold italic_**
*/
@Test @Test
public void test() { public void test() {
@ -28,6 +24,6 @@ public class BoldItalicTest extends BaseSuiteTest {
span(BOLD, span(BOLD,
span(ITALIC, text("bold italic")))); span(ITALIC, text("bold italic"))));
matchInput("bold-italic.md", document); match("**_bold italic_**", document);
} }
} }

View File

@ -56,7 +56,7 @@ public class CodeTest extends BaseSuiteTest {
span(CODE, args("multiline", false), text("\u00a0code\u00a0")) span(CODE, args("multiline", false), text("\u00a0code\u00a0"))
); );
matchInput("single-code.md", document); match("`code`", document);
} }
@Test @Test

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -103,6 +103,6 @@ public class OrderedListTest extends BaseSuiteTest {
text("ol")) text("ol"))
); );
matchInput("single-ol.md", document); match("1. ol", document);
} }
} }

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -22,7 +22,9 @@ class TestFactory implements SpannableFactory {
static final String BLOCK_QUOTE = "blockquote"; static final String BLOCK_QUOTE = "blockquote";
static final String PARAGRAPH = "paragraph"; static final String PARAGRAPH = "paragraph";
static final String ORDERED_LIST = "ordered-list"; static final String ORDERED_LIST = "ordered-list";
static final String UN_ORDERED_LIST = "un-ordered-list";
static final String HEADING = "heading"; static final String HEADING = "heading";
static final String THEMATIC_BREAK = "thematic-break";
private final boolean useParagraphs; private final boolean useParagraphs;
@ -63,13 +65,13 @@ class TestFactory implements SpannableFactory {
@Nullable @Nullable
@Override @Override
public Object bulletListItem(@NonNull MarkwonTheme theme, int level) { public Object bulletListItem(@NonNull MarkwonTheme theme, int level) {
return null; return span(UN_ORDERED_LIST, args("level", level));
} }
@Nullable @Nullable
@Override @Override
public Object thematicBreak(@NonNull MarkwonTheme theme) { public Object thematicBreak(@NonNull MarkwonTheme theme) {
return null; return span(THEMATIC_BREAK);
} }
@Nullable @Nullable

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -1 +0,0 @@
**_bold italic_**

View File

@ -1,5 +0,0 @@
input: "[link](#href)"
output:
- a: "link"
href: "#href"

View File

@ -1,4 +0,0 @@
input: "**bold**"
output:
- b: "bold"

View File

@ -1 +0,0 @@
> blockquote

View File

@ -1 +0,0 @@
`code`

View File

@ -1,4 +0,0 @@
input: "# head1"
output:
- h1: "head1"

View File

@ -1,4 +0,0 @@
input: "## head2"
output:
- h2: "head2"

View File

@ -1,4 +0,0 @@
input: "### head3"
output:
- h3: "head3"

View File

@ -1,4 +0,0 @@
input: "#### head4"
output:
- h4: "head4"

View File

@ -1,4 +0,0 @@
input: "##### head5"
output:
- h5: "head5"

View File

@ -1,4 +0,0 @@
input: "###### head6"
output:
- h6: "head6"

View File

@ -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"

View File

@ -1,4 +0,0 @@
input: "*italic*"
output:
- i: "italic"

View File

@ -1 +0,0 @@
1. ol

View File

@ -1,5 +0,0 @@
input: "* ul"
output:
- ul: "ul"
level: 0

View File

@ -0,0 +1,3 @@
hello there!
this one is on the next line
hard break to the full extend

View File

@ -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"

View File

@ -0,0 +1,3 @@
First line
same line but with space between
this is also the first line

View File

@ -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"

View File

@ -0,0 +1,3 @@
* First
* * Second
* * * Third

View File

@ -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

View File

@ -0,0 +1,3 @@
* First
* Second
* Third

View File

@ -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