From 323ac35bb2e6b60839270e6c11acefdc1c81fa76 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Fri, 31 Aug 2018 11:55:33 +0300 Subject: [PATCH] Add ability to provide text directly in test file --- .../renderer/visitor/TestDataReader.java | 11 +++- .../test/resources/tests/deeply-nested.yaml | 14 ++--- markwon/src/test/resources/tests/first.yaml | 10 ++-- .../tests/html-allow-non-closed-tags.yaml | 9 ++- .../tests/html-non-closed-ignore.yaml | 4 +- markwon/src/test/resources/tests/html.yaml | 56 +++++++++---------- .../resources/tests/nested-blockquotes.yaml | 6 +- 7 files changed, 59 insertions(+), 51 deletions(-) diff --git a/markwon/src/test/java/ru/noties/markwon/renderer/visitor/TestDataReader.java b/markwon/src/test/java/ru/noties/markwon/renderer/visitor/TestDataReader.java index 5d84e7c7..bfba93b1 100644 --- a/markwon/src/test/java/ru/noties/markwon/renderer/visitor/TestDataReader.java +++ b/markwon/src/test/java/ru/noties/markwon/renderer/visitor/TestDataReader.java @@ -223,7 +223,16 @@ abstract class TestDataReader { for (int i = 0; i < size; i++) { - final JsonObject object = array.get(i).getAsJsonObject(); + // if element is a string (or a json primitive) let's just add a text node + // right away, this way we will not have to provide text with `text: "my-text"` + // (we still can though) + final JsonElement jsonElement = array.get(i); + if (jsonElement.isJsonPrimitive()) { + testNodes.add(new TestNode.Text(parent, jsonElement.getAsString())); + continue; + } + + final JsonObject object = jsonElement.getAsJsonObject(); String name = null; Map attributes = new HashMap<>(0); diff --git a/markwon/src/test/resources/tests/deeply-nested.yaml b/markwon/src/test/resources/tests/deeply-nested.yaml index f81eca55..2f40ddf3 100644 --- a/markwon/src/test/resources/tests/deeply-nested.yaml +++ b/markwon/src/test/resources/tests/deeply-nested.yaml @@ -3,13 +3,13 @@ input: |- output: - b: - - text: "bold " + - "bold " - i: - - text: "bold italic " + - "bold italic " - s: - - text: "bold italic strike " + - "bold italic strike " - code: "bold italic strike code" - - text: " bold italic strike" - - text: " bold italic" - - text: " bold" - - text: " normal" \ No newline at end of file + - " bold italic strike" + - " bold italic" + - " bold" + - " normal" \ No newline at end of file diff --git a/markwon/src/test/resources/tests/first.yaml b/markwon/src/test/resources/tests/first.yaml index a278acea..d52d670d 100644 --- a/markwon/src/test/resources/tests/first.yaml +++ b/markwon/src/test/resources/tests/first.yaml @@ -11,13 +11,13 @@ config: html-allow-non-closed-tags: false output: - - text: "Here is some " + - "Here is some " - a: "link" href: "https://my.href" - - text: " " + - " " - b: - - text: "bold " + - "bold " - i: "bold italic" #equals to: `- i: - text: "bold italic"` - - text: " bold" - - text: " normal" + - " bold" + - " normal" diff --git a/markwon/src/test/resources/tests/html-allow-non-closed-tags.yaml b/markwon/src/test/resources/tests/html-allow-non-closed-tags.yaml index 42578b6b..f0f219b0 100644 --- a/markwon/src/test/resources/tests/html-allow-non-closed-tags.yaml +++ b/markwon/src/test/resources/tests/html-allow-non-closed-tags.yaml @@ -10,10 +10,9 @@ config: output: - i: - - text: "italic " + - "italic " - b: - - text: "bold italic " + - "bold italic " - u: - - text: "underline bold italic " - - s: - - text: "strike underline bold italic" \ No newline at end of file + - "underline bold italic " + - s: "strike underline bold italic" \ No newline at end of file diff --git a/markwon/src/test/resources/tests/html-non-closed-ignore.yaml b/markwon/src/test/resources/tests/html-non-closed-ignore.yaml index 73c41ae4..0c97e34e 100644 --- a/markwon/src/test/resources/tests/html-non-closed-ignore.yaml +++ b/markwon/src/test/resources/tests/html-non-closed-ignore.yaml @@ -7,6 +7,6 @@ config: use-html: true output: - - text: "no italic here " + - "no italic here " - b: "bold yeah" - - text: " no underline" \ No newline at end of file + - " no underline" \ No newline at end of file diff --git a/markwon/src/test/resources/tests/html.yaml b/markwon/src/test/resources/tests/html.yaml index 7db7243f..d952ce96 100644 --- a/markwon/src/test/resources/tests/html.yaml +++ b/markwon/src/test/resources/tests/html.yaml @@ -32,74 +32,74 @@ config: output: - h1: "html" - - text: "\n" + - "\n" - h2: "emphasis" - - text: "\n" + - "\n" - i: "i" - i: "em" - i: "cite" - i: "dfn" - - text: "\n" + - "\n" - h2: "strong-emphasis" - - text: "\n" + - "\n" - b: "b" - b: "strong" - - text: "\n" + - "\n" - h2: "super-script" - - text: "\n" + - "\n" - sup: "sup" - - text: "\n" + - "\n" - h2: "sub-script" - - text: "\n" + - "\n" - sub: "sub" - - text: "\n" + - "\n" - h2: "underline" - - text: "\n" + - "\n" - u: "u" - u: "ins" - - text: "\n" + - "\n" - h2: "strike" - - text: "\n" + - "\n" - s: "s" - s: "del" - - text: "\n" + - "\n" - h2: "link" - - text: "\n" + - "\n" - a: "a" href: "a://href" - - text: "\n" + - "\n" - h2: "unordered-list" - - text: "\n" + - "\n" - ul: "ul1" level: 0 - - text: "\n" + - "\n" - ul: "ul2" level: 0 - - text: "\n" + - "\n" - h2: "ordered-list" - - text: "\n" + - "\n" - ol: "ol1" start: 1 - - text: "\n" + - "\n" - ol: "ol2" start: 2 - - text: "\n" + - "\n" - h2: "image" - - text: "\n" + - "\n" - img: "img" src: "img://src" imageSize: null replacementTextIsLink: false - - text: "\n" + - "\n" - h2: "blockquote" - - text: "\n" + - "\n" - blockquote: "blockquote" - - text: "\n" + - "\n" - h3: "3" - - text: "\n" + - "\n" - h4: "4" - - text: "\n" + - "\n" - h5: "5" - - text: "\n" + - "\n" - h6: "6" diff --git a/markwon/src/test/resources/tests/nested-blockquotes.yaml b/markwon/src/test/resources/tests/nested-blockquotes.yaml index 93356d03..fbdb04b9 100644 --- a/markwon/src/test/resources/tests/nested-blockquotes.yaml +++ b/markwon/src/test/resources/tests/nested-blockquotes.yaml @@ -5,8 +5,8 @@ input: |- output: - blockquote: - - text: "First\n\n" + - "First\n\n" - blockquote: - - text: "Second\n\n" + - "Second\n\n" - blockquote: - - text: "Third" \ No newline at end of file + - "Third" \ No newline at end of file