@Test(expected = IllegalArgumentException.class) public void testRegisterClassWithoutExplicitName() { asciidoctor.javaExtensionRegistry().blockMacro(AbstractTestProcessor.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterClassWithNameAsClass() { asciidoctor.javaExtensionRegistry().blockMacro(TestProcessorWithName.class); }
@Test public void a_block_macro_extension_instance_should_be_executed_when_macro_is_detected() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.blockMacro(new GistMacro("gist", new HashMap<>())); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_block_macro_as_instance_extension_should_be_executed_when_macro_is_detected() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); Map<String, Object> options = new HashMap<>(); options.put(ContentModel.KEY, ContentModel.RAW); javaExtensionRegistry.blockMacro(new GistMacro("gist", options)); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_block_macro_extension_should_be_executed_when_macro_is_detected() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.blockMacro("gist", GistMacro.class); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_block_macro_as_string_extension_should_be_executed_when_macro_is_detected() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.blockMacro("gist", "org.asciidoctor.extension.GistMacro"); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_treeprocessor_and_blockmacroprocessor_should_be_executed_in_document() { this.asciidoctor.javaExtensionRegistry() .treeprocessor(TerminalCommandTreeprocessor.class) .blockMacro("gist", GistMacro.class); String content = asciidoctor.convertFile( classpath.getResource("sample-with-terminal-command-and-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "command").first(); assertThat(contentElement.text(), is("echo \"Hello, World!\"")); contentElement = doc.getElementsByAttributeValue("class", "command").last(); assertThat(contentElement.text(), is("gem install asciidoctor")); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/42.js")); }
@Test public void should_create_script_element_for_block_macro() { //tag::include[] File gistmacro_adoc = //... //end::include[] classpathResources.getResource("gist-macro.adoc"); //tag::include[] asciidoctor.javaExtensionRegistry().blockMacro(GistBlockMacroProcessor.class); // <1> String result = asciidoctor.convertFile(gistmacro_adoc, OptionsBuilder.options().toFile(false)); assertThat( result, containsString( "<script src=\"https://gist.github.com/myaccount/1234abcd.js\">")); // <2> //end::include[] }
@Test public void testRegisterClassAsClassWithExplicitName() { final String explicitblockname = "anotherexplicitname"; asciidoctor.javaExtensionRegistry().blockMacro(explicitblockname, AbstractTestProcessor.class); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit Class"), OptionsBuilder.options()); check("HELLO EXPLICIT CLASS", result); }
@Test public void testRegisterNamedClassAsClassWithExplicitName() { final String explicitblockname = "explicitblockname"; asciidoctor.javaExtensionRegistry().blockMacro(explicitblockname, AnnotatedTestProcessor.class); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit"), OptionsBuilder.options()); check("HELLO EXPLICIT", result); } @Test
@Test public void testRegisterClassWithNameAsClassWithExplicitName() { final String explicitblockname = "explicitblockname"; asciidoctor.javaExtensionRegistry().blockMacro(explicitblockname, TestProcessorWithName.class); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit"), OptionsBuilder.options()); check("HELLO EXPLICIT", result); }
@Test public void testRegisterNamedClassAsClass() { asciidoctor.javaExtensionRegistry().blockMacro(AnnotatedTestProcessor.class); final String result = asciidoctor.convert(document(AnnotatedTestProcessor.NAME, "Hello World"), OptionsBuilder.options()); check("HELLO WORLD", result); }
@Test(expected = AsciidoctorCoreException.class) public void testRegisterClassAsInstance() { asciidoctor.javaExtensionRegistry().blockMacro(new AbstractTestProcessor()); asciidoctor.convert(document("foo", "Hello Explicit Instance"), OptionsBuilder.options()); }
@Test public void testRegisterClassWithNameAsInstance() { asciidoctor.javaExtensionRegistry().blockMacro(new TestProcessorWithName()); final String result = asciidoctor.convert(document(TestProcessorWithName.NAME, "Another Test"), OptionsBuilder.options()); check("ANOTHER TEST", result); }
@Test public void testRegisterNamedClassAsInstance() { asciidoctor.javaExtensionRegistry().blockMacro(new AnnotatedTestProcessor()); final String result = asciidoctor.convert(document(AnnotatedTestProcessor.NAME, "Another Test"), OptionsBuilder.options()); check("ANOTHER TEST", result); }
@Test public void testRegisterNamedClassAsInstanceWithExplicitName() { final String blockName = "somename"; asciidoctor.javaExtensionRegistry().blockMacro(blockName, new AnnotatedTestProcessor()); final String result = asciidoctor.convert(document(blockName, "Yet Another Test"), OptionsBuilder.options()); check("YET ANOTHER TEST", result); }
@Test public void testRegisterClassWithNameAsInstanceWithExplicitName() { final String blockName = "somename"; asciidoctor.javaExtensionRegistry().blockMacro(blockName, new TestProcessorWithName()); final String result = asciidoctor.convert(document(blockName, "Yet Another Test"), OptionsBuilder.options()); check("YET ANOTHER TEST", result); }
@Test public void testRegisterClassAsInstanceWithExplicitName() { final String explicitblockname = "aname"; asciidoctor.javaExtensionRegistry().blockMacro(explicitblockname, new AbstractTestProcessor()); final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit Instance"), OptionsBuilder.options()); check("HELLO EXPLICIT INSTANCE", result); }