Migrating tests to new format
This commit is contained in:
parent
7c473b3d37
commit
1245712ef6
@ -15,17 +15,13 @@ import ru.noties.markwon.test.TestUtil;
|
||||
|
||||
abstract class BaseSuiteTest {
|
||||
|
||||
void matches(@NonNull String input, @NonNull TestSpan.Document document) {
|
||||
final Spanned spanned = (Spanned) markwon().toMarkdown(input);
|
||||
void matchInput(@NonNull String name, @NonNull TestSpan.Document document) {
|
||||
final Spanned spanned = markwon().toMarkdown(read(name));
|
||||
TestSpanMatcher.matches(spanned, document);
|
||||
}
|
||||
|
||||
void matchInput(@NonNull String name, @NonNull TestSpan.Document document) {
|
||||
matches(read(name), document);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
String read(@NonNull String name) {
|
||||
private String read(@NonNull String name) {
|
||||
return TestUtil.read(this, "tests/" + name);
|
||||
}
|
||||
|
||||
@ -36,9 +32,13 @@ abstract class BaseSuiteTest {
|
||||
.use(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||
builder.factory(new TestFactory());
|
||||
builder.factory(new TestFactory(useParagraphs()));
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
boolean useParagraphs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
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.BLOCK_QUOTE;
|
||||
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 BlockquoteTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
> First
|
||||
> > Second
|
||||
> > > Third
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void nested() {
|
||||
|
||||
final Document document = document(
|
||||
span(BLOCK_QUOTE,
|
||||
text("First\n\n"),
|
||||
span(BLOCK_QUOTE,
|
||||
text("Second\n\n"),
|
||||
span(BLOCK_QUOTE,
|
||||
text("Third"))))
|
||||
);
|
||||
|
||||
matchInput("nested-blockquotes.md", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(BLOCK_QUOTE, text("blockquote")));
|
||||
|
||||
matchInput("single-blockquote.md", document);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class BoldItalic extends BaseSuiteTest {
|
||||
public class BoldItalicTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
**_bold italic_**
|
@ -5,7 +5,7 @@ import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import ru.noties.markwon.test.TestSpan;
|
||||
import ru.noties.markwon.test.TestSpan.Document;
|
||||
|
||||
import static ru.noties.markwon.core.suite.TestFactory.CODE;
|
||||
import static ru.noties.markwon.test.TestSpan.args;
|
||||
@ -15,7 +15,7 @@ import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class CodeBlocks extends BaseSuiteTest {
|
||||
public class CodeTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
```java
|
||||
@ -30,9 +30,9 @@ public class CodeBlocks extends BaseSuiteTest {
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void multiple_blocks() {
|
||||
|
||||
final TestSpan.Document document = document(
|
||||
final Document document = document(
|
||||
span(CODE,
|
||||
args("multiline", true),
|
||||
text("\u00a0\nfinal String s = null;\n\u00a0")),
|
||||
@ -48,4 +48,24 @@ public class CodeBlocks extends BaseSuiteTest {
|
||||
|
||||
matchInput("code-blocks.md", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(CODE, args("multiline", false), text("\u00a0code\u00a0"))
|
||||
);
|
||||
|
||||
matchInput("single-code.md", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void single_block() {
|
||||
|
||||
final Document document = document(
|
||||
span(CODE, args("multiline", true), text("\u00a0\ncode block\n\u00a0"))
|
||||
);
|
||||
|
||||
matchInput("single-code-block.md", document);
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class DeeplyNested extends BaseSuiteTest {
|
||||
public class DeeplyNestedTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
**bold *bold italic `bold italic code` bold italic* bold** normal
|
@ -17,7 +17,7 @@ import static ru.noties.markwon.test.TestSpan.text;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE)
|
||||
public class First extends BaseSuiteTest {
|
||||
public class FirstTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
Here is some [link](https://my.href)
|
@ -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 NoParagraphsTest extends BaseSuiteTest {
|
||||
/*
|
||||
This could be a paragraph
|
||||
|
||||
But it is not and this one is not also
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final Document document = document(
|
||||
text("This could be a paragraph"),
|
||||
text("\n\n"),
|
||||
text("But it is not and this one is not also")
|
||||
);
|
||||
|
||||
matchInput("no-paragraphs.md", document);
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
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.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 OrderedListTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
1. First
|
||||
1. Second
|
||||
1. Third
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void nested() {
|
||||
|
||||
// wanted to use 1,2,3 as start numbers, but anything but `1` won't be treated as sub-list
|
||||
|
||||
final Document document = document(
|
||||
span(ORDERED_LIST,
|
||||
args("start", 1),
|
||||
text("First\n"),
|
||||
span(ORDERED_LIST,
|
||||
args("start", 1),
|
||||
text("Second\n"),
|
||||
span(ORDERED_LIST,
|
||||
args("start", 1),
|
||||
text("Third"))))
|
||||
);
|
||||
|
||||
matchInput("ol.md", document);
|
||||
}
|
||||
|
||||
/*
|
||||
1. First
|
||||
2. Second
|
||||
3. Third
|
||||
*/
|
||||
@Test
|
||||
public void two_spaces() {
|
||||
// just a regular flat-list (no sub-lists)
|
||||
|
||||
final Document document = document(
|
||||
span(ORDERED_LIST,
|
||||
args("start", 1),
|
||||
text("First")),
|
||||
text("\n"),
|
||||
span(ORDERED_LIST,
|
||||
args("start", 2),
|
||||
text("Second")),
|
||||
text("\n"),
|
||||
span(ORDERED_LIST,
|
||||
args("start", 3),
|
||||
text("Third"))
|
||||
);
|
||||
|
||||
matchInput("ol-2-spaces.md", document);
|
||||
}
|
||||
|
||||
/*
|
||||
5. Five
|
||||
6. Six
|
||||
7. Seven
|
||||
*/
|
||||
@Test
|
||||
public void starts_with_5() {
|
||||
|
||||
final Document document = document(
|
||||
span(ORDERED_LIST,
|
||||
args("start", 5),
|
||||
text("Five")),
|
||||
text("\n"),
|
||||
span(ORDERED_LIST,
|
||||
args("start", 6),
|
||||
text("Six")),
|
||||
text("\n"),
|
||||
span(ORDERED_LIST,
|
||||
args("start", 7),
|
||||
text("Seven"))
|
||||
);
|
||||
|
||||
matchInput("ol-starts-with-5.md", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
|
||||
final Document document = document(
|
||||
span(ORDERED_LIST,
|
||||
args("start", 1),
|
||||
text("ol"))
|
||||
);
|
||||
|
||||
matchInput("single-ol.md", document);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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.PARAGRAPH;
|
||||
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 ParagraphTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
So, this is a paragraph
|
||||
|
||||
And this one is another
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final Document document = document(
|
||||
span(PARAGRAPH,
|
||||
text("So, this is a paragraph")),
|
||||
text("\n\n"),
|
||||
span(PARAGRAPH,
|
||||
text("And this one is another"))
|
||||
);
|
||||
|
||||
matchInput("paragraph.md", document);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean useParagraphs() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
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.BLOCK_QUOTE;
|
||||
import static ru.noties.markwon.core.suite.TestFactory.BOLD;
|
||||
import static ru.noties.markwon.core.suite.TestFactory.CODE;
|
||||
import static ru.noties.markwon.core.suite.TestFactory.HEADING;
|
||||
import static ru.noties.markwon.core.suite.TestFactory.ITALIC;
|
||||
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 SecondTest extends BaseSuiteTest {
|
||||
|
||||
/*
|
||||
First **line** is *always*
|
||||
|
||||
> Some quote here!
|
||||
|
||||
# Header 1
|
||||
## Header 2
|
||||
|
||||
and `some code` and more:
|
||||
|
||||
```java
|
||||
the code in multiline
|
||||
```
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final Document document = document(
|
||||
text("First "),
|
||||
span(BOLD, text("line")),
|
||||
text(" is "),
|
||||
span(ITALIC, text("always")),
|
||||
text("\n\n"),
|
||||
span(BLOCK_QUOTE, text("Some quote here!")),
|
||||
text("\n\n"),
|
||||
span(HEADING, args("level", 1), text("Header 1")),
|
||||
text("\n\n"),
|
||||
span(HEADING, args("level", 2), text("Header 2")),
|
||||
text("\n\n"),
|
||||
text("and "),
|
||||
span(CODE, args("multiline", false), text("\u00a0some code\u00a0")),
|
||||
text(" and more:"),
|
||||
text("\n\n"),
|
||||
span(CODE, args("multiline", true), text("\u00a0\nthe code in multiline\n\u00a0"))
|
||||
);
|
||||
|
||||
matchInput("second.md", document);
|
||||
}
|
||||
}
|
@ -19,6 +19,16 @@ class TestFactory implements SpannableFactory {
|
||||
static final String ITALIC = "italic";
|
||||
static final String CODE = "code";
|
||||
static final String LINK = "link";
|
||||
static final String BLOCK_QUOTE = "blockquote";
|
||||
static final String PARAGRAPH = "paragraph";
|
||||
static final String ORDERED_LIST = "ordered-list";
|
||||
static final String HEADING = "heading";
|
||||
|
||||
private final boolean useParagraphs;
|
||||
|
||||
TestFactory(boolean useParagraphs) {
|
||||
this.useParagraphs = useParagraphs;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -35,7 +45,7 @@ class TestFactory implements SpannableFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object blockQuote(@NonNull MarkwonTheme theme) {
|
||||
return null;
|
||||
return span(BLOCK_QUOTE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -47,7 +57,7 @@ class TestFactory implements SpannableFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object orderedListItem(@NonNull MarkwonTheme theme, int startNumber) {
|
||||
return null;
|
||||
return span(ORDERED_LIST, args("start", startNumber));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -65,13 +75,15 @@ class TestFactory implements SpannableFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object heading(@NonNull MarkwonTheme theme, int level) {
|
||||
return null;
|
||||
return span(HEADING, args("level", level));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object paragraph(boolean inTightList) {
|
||||
return null;
|
||||
return useParagraphs
|
||||
? span(PARAGRAPH)
|
||||
: null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
3
markwon/src/test/resources/tests/nested-blockquotes.md
Normal file
3
markwon/src/test/resources/tests/nested-blockquotes.md
Normal file
@ -0,0 +1,3 @@
|
||||
> First
|
||||
> > Second
|
||||
> > > Third
|
@ -1,12 +0,0 @@
|
||||
input: |-
|
||||
> First
|
||||
> > Second
|
||||
> > > Third
|
||||
|
||||
output:
|
||||
- blockquote:
|
||||
- "First\n\n"
|
||||
- blockquote:
|
||||
- "Second\n\n"
|
||||
- blockquote:
|
||||
- "Third"
|
3
markwon/src/test/resources/tests/no-paragraphs.md
Normal file
3
markwon/src/test/resources/tests/no-paragraphs.md
Normal file
@ -0,0 +1,3 @@
|
||||
This could be a paragraph
|
||||
|
||||
But it is not and this one is not also
|
@ -1,12 +0,0 @@
|
||||
input: |-
|
||||
This could be a paragraph
|
||||
|
||||
But it is not and this one is not also
|
||||
|
||||
config:
|
||||
use-paragraphs: false
|
||||
|
||||
output:
|
||||
- text: "This could be a paragraph"
|
||||
- text: "\n\n"
|
||||
- text: "But it is not and this one is not also"
|
3
markwon/src/test/resources/tests/ol-2-spaces.md
Normal file
3
markwon/src/test/resources/tests/ol-2-spaces.md
Normal file
@ -0,0 +1,3 @@
|
||||
1. First
|
||||
2. Second
|
||||
3. Third
|
@ -1,16 +0,0 @@
|
||||
description: "Will be rendered as simple flat list"
|
||||
|
||||
input: |-
|
||||
1. First
|
||||
2. Second
|
||||
3. Third
|
||||
|
||||
output:
|
||||
- ol: "First"
|
||||
start: 1
|
||||
- text: "\n"
|
||||
- ol: "Second"
|
||||
start: 2
|
||||
- text: "\n"
|
||||
- ol: "Third"
|
||||
start: 3
|
3
markwon/src/test/resources/tests/ol-starts-with-5.md
Normal file
3
markwon/src/test/resources/tests/ol-starts-with-5.md
Normal file
@ -0,0 +1,3 @@
|
||||
5. Five
|
||||
6. Six
|
||||
7. Seven
|
@ -1,14 +0,0 @@
|
||||
input: |-
|
||||
5. Five
|
||||
6. Six
|
||||
7. Seven
|
||||
|
||||
output:
|
||||
- ol: "Five"
|
||||
start: 5
|
||||
- text: "\n"
|
||||
- ol: "Six"
|
||||
start: 6
|
||||
- text: "\n"
|
||||
- ol: "Seven"
|
||||
start: 7
|
3
markwon/src/test/resources/tests/ol.md
Normal file
3
markwon/src/test/resources/tests/ol.md
Normal file
@ -0,0 +1,3 @@
|
||||
1. First
|
||||
1. Second
|
||||
1. Third
|
@ -1,14 +0,0 @@
|
||||
input: |-
|
||||
1. First
|
||||
1. Second
|
||||
1. Third
|
||||
|
||||
output:
|
||||
- ol:
|
||||
- text: "First\n"
|
||||
- ol:
|
||||
- text: "Second\n"
|
||||
- ol: "Third"
|
||||
start: 1
|
||||
start: 1
|
||||
start: 1
|
3
markwon/src/test/resources/tests/paragraph.md
Normal file
3
markwon/src/test/resources/tests/paragraph.md
Normal file
@ -0,0 +1,3 @@
|
||||
So, this is a paragraph
|
||||
|
||||
And this one is another
|
@ -1,12 +0,0 @@
|
||||
input: |-
|
||||
So, this is a paragraph
|
||||
|
||||
And this one is another
|
||||
|
||||
config:
|
||||
use-paragraphs: true
|
||||
|
||||
output:
|
||||
- p: "So, this is a paragraph"
|
||||
- text: "\n\n"
|
||||
- p: "And this one is another"
|
12
markwon/src/test/resources/tests/second.md
Normal file
12
markwon/src/test/resources/tests/second.md
Normal file
@ -0,0 +1,12 @@
|
||||
First **line** is *always*
|
||||
|
||||
> Some quote here!
|
||||
|
||||
# Header 1
|
||||
## Header 2
|
||||
|
||||
and `some code` and more:
|
||||
|
||||
```java
|
||||
the code in multiline
|
||||
```
|
@ -1,29 +0,0 @@
|
||||
input: |-
|
||||
First **line** is *always*
|
||||
|
||||
> Some quote here!
|
||||
|
||||
# Header 1
|
||||
## Header 2
|
||||
|
||||
and `some code` and more:
|
||||
|
||||
```java
|
||||
the code in multiline
|
||||
```
|
||||
|
||||
output:
|
||||
- text: "First "
|
||||
- b: "line"
|
||||
- text: " is "
|
||||
- i: "always"
|
||||
- text: "\n\n"
|
||||
- blockquote: "Some quote here!"
|
||||
- text: "\n\n"
|
||||
- h1: "Header 1"
|
||||
- text: "\n\n"
|
||||
- h2: "Header 2"
|
||||
- text: "\n\nand "
|
||||
- code: "some code"
|
||||
- text: " and more:\n\n"
|
||||
- code-block: "the code in multiline"
|
1
markwon/src/test/resources/tests/single-blockquote.md
Normal file
1
markwon/src/test/resources/tests/single-blockquote.md
Normal file
@ -0,0 +1 @@
|
||||
> blockquote
|
@ -1,4 +0,0 @@
|
||||
input: "> blockquote"
|
||||
|
||||
output:
|
||||
- blockquote: "blockquote"
|
3
markwon/src/test/resources/tests/single-code-block.md
Normal file
3
markwon/src/test/resources/tests/single-code-block.md
Normal file
@ -0,0 +1,3 @@
|
||||
```
|
||||
code block
|
||||
```
|
@ -1,7 +0,0 @@
|
||||
input: |-
|
||||
```
|
||||
code block
|
||||
```
|
||||
|
||||
output:
|
||||
- code-block: "code block"
|
1
markwon/src/test/resources/tests/single-code.md
Normal file
1
markwon/src/test/resources/tests/single-code.md
Normal file
@ -0,0 +1 @@
|
||||
`code`
|
@ -1,4 +0,0 @@
|
||||
input: "`code`"
|
||||
|
||||
output:
|
||||
- code: "code"
|
1
markwon/src/test/resources/tests/single-ol.md
Normal file
1
markwon/src/test/resources/tests/single-ol.md
Normal file
@ -0,0 +1 @@
|
||||
1. ol
|
@ -1,5 +0,0 @@
|
||||
input: "1. ol"
|
||||
|
||||
output:
|
||||
- ol: "ol"
|
||||
start: 1
|
Loading…
x
Reference in New Issue
Block a user