Add test cases for all avaialble elements (single)

This commit is contained in:
Dimitry Ivanov 2018-08-24 17:42:29 +03:00
parent caf7f99335
commit ba30654728
26 changed files with 145 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import ru.noties.markwon.Markwon;
import ru.noties.markwon.SpannableBuilder; import ru.noties.markwon.SpannableBuilder;
import ru.noties.markwon.SpannableConfiguration; import ru.noties.markwon.SpannableConfiguration;
import ru.noties.markwon.SpannableFactory; import ru.noties.markwon.SpannableFactory;
import ru.noties.markwon.html.api.MarkwonHtmlParser;
import ru.noties.markwon.renderer.SpannableMarkdownVisitor; import ru.noties.markwon.renderer.SpannableMarkdownVisitor;
import ru.noties.markwon.spans.SpannableTheme; import ru.noties.markwon.spans.SpannableTheme;
@ -134,11 +135,15 @@ public class SpannableMarkdownVisitorTest {
private SpannableConfiguration configuration(@NonNull TestConfig config) { private SpannableConfiguration configuration(@NonNull TestConfig config) {
final SpannableFactory factory = new TestFactory(config.hasOption(TestConfig.USE_PARAGRAPHS)); final SpannableFactory factory = new TestFactory(config.hasOption(TestConfig.USE_PARAGRAPHS));
final MarkwonHtmlParser htmlParser = config.hasOption(TestConfig.USE_HTML)
? null
: MarkwonHtmlParser.noOp();
// todo: rest omitted for now // todo: rest omitted for now
return SpannableConfiguration.builder(null) return SpannableConfiguration.builder(null)
.theme(mock(SpannableTheme.class)) .theme(mock(SpannableTheme.class))
.linkResolver(mock(LinkResolverDef.class)) .linkResolver(mock(LinkResolverDef.class))
.htmlParser(htmlParser)
.factory(factory) .factory(factory)
.build(); .build();
} }

View File

@ -276,7 +276,14 @@ abstract class TestDataReader {
if (object != null) { if (object != null) {
attributes = new HashMap<>(object.size()); attributes = new HashMap<>(object.size());
for (String key : object.keySet()) { for (String key : object.keySet()) {
attributes.put(key, object.get(key).getAsString()); final String value;
final JsonElement valueElement = object.get(key);
if (valueElement.isJsonNull()) {
value = null;
} else {
value = valueElement.getAsString();
}
attributes.put(key, value);
} }
} else { } else {
attributes = Collections.emptyMap(); attributes = Collections.emptyMap();

View File

@ -0,0 +1,15 @@
input: |-
**bold *bold italic ~~bold italic strike `bold italic strike code` bold italic strike~~ bold italic* bold** normal
output:
- b:
- text: "bold "
- i:
- text: "bold italic "
- s:
- text: "bold italic strike "
- code: "bold italic strike code"
- text: " bold italic strike"
- text: " bold italic"
- text: " bold"
- text: " normal"

View File

@ -12,8 +12,7 @@ config:
output: output:
- text: "Here is some " - text: "Here is some "
- a: - a: "link"
- text: "link"
attrs: attrs:
href: "https://my.href" href: "https://my.href"
- text: " " - text: " "

View File

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

View File

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

View File

@ -0,0 +1,4 @@
input: "> blockquote"
output:
- blockquote: "blockquote"

View File

@ -0,0 +1,7 @@
input: |-
```
code block
```
output:
- code-block: "code block"

View File

@ -0,0 +1,4 @@
input: "`code`"
output:
- code: "code"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,7 @@
# 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: " "

View File

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

View File

@ -0,0 +1,8 @@
input: "![image](#href)"
output:
- img: "image"
attrs:
scr: "#href"
imageSize: null
replacementTextIsLink: false

View File

@ -0,0 +1,6 @@
input: "1. ol"
output:
- ol: "ol"
attrs:
start: 1

View File

@ -0,0 +1,4 @@
input: "~~strike~~"
output:
- s: "strike"

View File

@ -0,0 +1,7 @@
input: "<sub>sub</sub>"
config:
use-html: true
output:
- sub: "sub"

View File

@ -0,0 +1,7 @@
input: "<sup>sup</sup>"
config:
use-html: true
output:
- sup: "sup"

View File

@ -0,0 +1,7 @@
input: "- [ ] task-list"
output:
- task-list: "task-list"
attrs:
blockIdent: 1
done: false

View File

@ -0,0 +1,4 @@
input: "table-table-table"
output:
- text: "should fail as we are to decide how to pass info here"

View File

@ -0,0 +1,7 @@
input: "<u>underline</u>"
config:
use-html: true
output:
- u: "underline"

View File

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