inlines = action.tags;
+ assertEquals(inlines.toString(), 1, inlines.size());
+
+ final HtmlTag.Inline inline = inlines.get(0);
+ assertEquals("i", inline.name());
+ assertEquals(0, inline.start());
+ assertEquals(output.length(), inline.end());
+ assertEquals("italic ", output.toString());
}
@Test
public void paragraphCannotContainAnythingButInlines() {
- throw new RuntimeException();
- }
- // move to htmlInlineTagreplacement test class
- @Test
- public void imageReplacementNoAlt() {
- throw new RuntimeException();
- }
+ final MarkwonHtmlParserImpl impl = MarkwonHtmlParserImpl.create();
- @Test
- public void brAddsNewLine() {
- throw new RuntimeException();
- }
+ final StringBuilder output = new StringBuilder();
- @Test
- public void imageReplacementAlt() {
- throw new RuntimeException();
+ impl.processFragment(output, "italic bold italic
in-div
");
+
+ final CaptureInlineTagsAction inlineTagsAction = new CaptureInlineTagsAction();
+ final CaptureBlockTagsAction blockTagsAction = new CaptureBlockTagsAction();
+
+ impl.flushInlineTags(output.length(), inlineTagsAction);
+ impl.flushBlockTags(output.length(), blockTagsAction);
+
+ assertTrue(inlineTagsAction.called);
+ assertTrue(blockTagsAction.called);
+
+ final List inlines = inlineTagsAction.tags;
+ final List blocks = blockTagsAction.tags;
+
+ assertEquals(2, inlines.size());
+ assertEquals(2, blocks.size());
+
+ // inlines will be closed at the end of the document
+ // P will be closed right before
+
+ with(inlines.get(0), new Action
() {
+ @Override
+ public void apply(@NonNull HtmlTag.Inline inline) {
+ assertEquals("i", inline.name());
+ assertEquals(0, inline.start());
+ assertEquals(output.length(), inline.end());
+ }
+ });
+
+ with(inlines.get(1), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Inline inline) {
+ assertEquals("b", inline.name());
+ assertEquals("italic ".length(), inline.start());
+ assertEquals(output.length(), inline.end());
+ }
+ });
+
+ with(blocks.get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("p", block.name());
+ assertEquals(0, block.start());
+ assertEquals(output.indexOf("in-div") - 1, block.end());
+ }
+ });
+
+ with(blocks.get(1), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("div", block.name());
+ assertEquals(output.indexOf("in-div"), block.start());
+ assertEquals(output.length(), block.end());
+ }
+ });
}
@Test
public void blockCloseClosesChildren() {
- throw new RuntimeException();
- }
- @Test
- public void allReturnedTagsAreClosed() {
- throw new RuntimeException();
+ final MarkwonHtmlParserImpl impl = MarkwonHtmlParserImpl.create();
+ final StringBuilder output = new StringBuilder();
+
+ final String html = "12hello!";
+ impl.processFragment(output, html);
+
+ assertEquals("12hello!", output.toString());
+
+ final CaptureBlockTagsAction action = new CaptureBlockTagsAction();
+ impl.flushBlockTags(output.length(), action);
+
+ assertTrue(action.called);
+ assertEquals(1, action.tags.size());
+
+ with(action.tags.get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+
+ final int end = output.length();
+
+ assertEquals("div-1", block.name());
+ assertEquals(0, block.start());
+ assertEquals(end, block.end());
+ assertEquals(1, block.children().size());
+
+ with(block.children().get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("div-2", block.name());
+ assertEquals(1, block.start());
+ assertEquals(end, block.end());
+ assertEquals(1, block.children().size());
+
+ with(block.children().get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("div-3", block.name());
+ assertEquals(2, block.start());
+ assertEquals(end, block.end());
+ assertEquals(0, block.children().size());
+ }
+ });
+ }
+ });
+ }
+ });
}
@Test
public void allTagsAreLowerCase() {
- throw new RuntimeException();
+
+ final MarkwonHtmlParserImpl impl = MarkwonHtmlParserImpl.create();
+ final StringBuilder output = new StringBuilder();
+ impl.processFragment(output, "italic emphasis italic
");
+
+ final CaptureInlineTagsAction inlineTagsAction = new CaptureInlineTagsAction();
+ final CaptureBlockTagsAction blockTagsAction = new CaptureBlockTagsAction();
+
+ impl.flushInlineTags(output.length(), inlineTagsAction);
+ impl.flushBlockTags(output.length(), blockTagsAction);
+
+ assertTrue(inlineTagsAction.called);
+ assertTrue(blockTagsAction.called);
+
+ with(inlineTagsAction.tags, new Action>() {
+ @Override
+ public void apply(@NonNull List inlines) {
+
+ assertEquals(2, inlines.size());
+
+ with(inlines.get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Inline inline) {
+ assertEquals("i", inline.name());
+ assertEquals(0, inline.start());
+ assertEquals(output.length(), inline.end());
+ }
+ });
+
+ with(inlines.get(1), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Inline inline) {
+
+ assertEquals("em", inline.name());
+
+ final int start = "italic ".length();
+ assertEquals(start, inline.start());
+ assertEquals(start + ("emphasis".length()), inline.end());
+ }
+ });
+ }
+ });
+
+ assertEquals(1, blockTagsAction.tags.size());
+
+ with(blockTagsAction.tags.get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("div", block.name());
+ assertEquals(0, block.start());
+ assertEquals(output.length(), block.end());
+ }
+ });
}
@Test
public void previousListItemClosed() {
- throw new RuntimeException();
- }
- @Test
- public void nestedBlocks() {
- throw new RuntimeException();
+ final MarkwonHtmlParserImpl impl = MarkwonHtmlParserImpl.create();
+ final StringBuilder output = new StringBuilder();
+
+ final String html = "- UL-First
- UL-Second
- OL-First
- OL-Second
- UL-Third";
+
+ impl.processFragment(output, html);
+
+ final CaptureBlockTagsAction action = new CaptureBlockTagsAction();
+ impl.flushBlockTags(output.length(), action);
+
+ assertTrue(action.called);
+ assertEquals(1, action.tags.size());
+
+ with(action.tags.get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+
+ assertEquals("ul", block.name());
+ assertEquals(3, block.children().size());
+
+ with(block.children().get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("li", block.name());
+ assertEquals("UL-First", output.substring(block.start(), block.end()));
+ assertEquals(0, block.children().size());
+ }
+ });
+
+ with(block.children().get(1), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("li", block.name());
+
+ // this block will contain nested block text also
+ assertEquals("UL-Second\nOL-First\nOL-Second", output.substring(block.start(), block.end()));
+ assertEquals(1, block.children().size());
+
+ with(block.children().get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("ol", block.name());
+ assertEquals(2, block.children().size());
+
+ with(block.children().get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("li", block.name());
+ assertEquals("OL-First", output.substring(block.start(), block.end()));
+ assertEquals(0, block.children().size());
+ }
+ });
+
+ with(block.children().get(1), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("li", block.name());
+ assertEquals("OL-Second", output.substring(block.start(), block.end()));
+ assertEquals(0, block.children().size());
+ }
+ });
+ }
+ });
+ }
+ });
+
+ with(block.children().get(2), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+ assertEquals("li", block.name());
+ assertEquals("UL-Third", output.substring(block.start(), block.end()));
+ assertEquals(0, block.children().size());
+ }
+ });
+ }
+ });
}
@Test
public void attributes() {
- throw new RuntimeException();
+
+ final MarkwonHtmlParserImpl impl = MarkwonHtmlParserImpl.create();
+ final StringBuilder output = new StringBuilder();
+
+ impl.processFragment(output, "my-content");
+
+ final CaptureBlockTagsAction action = new CaptureBlockTagsAction();
+ impl.flushBlockTags(output.length(), action);
+
+ assertTrue(action.called);
+ assertEquals(1, action.tags.size());
+
+ with(action.tags.get(0), new Action() {
+ @Override
+ public void apply(@NonNull HtmlTag.Block block) {
+
+ assertEquals("my-tag", block.name());
+
+ with(block.attributes(), new Action