-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #629 from ancho/feature/asciidoc-attributes-test
add asciidoctor parser tests
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
jbake-core/src/test/java/org/jbake/app/AsciidocParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.jbake.app; | ||
|
||
import org.jbake.TestUtils; | ||
import org.jbake.app.configuration.ConfigUtil; | ||
import org.jbake.app.configuration.DefaultJBakeConfiguration; | ||
import org.jbake.app.configuration.JBakeProperty; | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.PrintWriter; | ||
import java.util.AbstractMap.SimpleEntry; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AsciidocParserTest { | ||
|
||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
private DefaultJBakeConfiguration config; | ||
private Parser parser; | ||
private File rootPath; | ||
|
||
private File validAsciiDocFile; | ||
|
||
private String validHeader = "title=This is a Title = This is a valid Title\nstatus=draft\ntype=post\ndate=2013-09-02\n~~~~~~"; | ||
|
||
@Before | ||
public void createSampleFile() throws Exception { | ||
rootPath = TestUtils.getTestResourcesAsSourceFolder(); | ||
config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(rootPath); | ||
parser = new Parser(config); | ||
|
||
validAsciiDocFile = folder.newFile("asciidoc-with-source.ad"); | ||
PrintWriter out = new PrintWriter(validAsciiDocFile); | ||
out.println(validHeader); | ||
out.println("= Hello, AsciiDoc!"); | ||
out.println("Test User <[email protected]>"); | ||
out.println(""); | ||
out.println("JBake now supports AsciiDoc."); | ||
out.println(""); | ||
out.println("```"); | ||
out.println("#!/bin/bash"); | ||
out.println(""); | ||
out.println("echo 'hello world!'"); | ||
out.println("```"); | ||
out.println(""); | ||
out.println("{testattribute}"); | ||
|
||
out.close(); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void parseAsciidocFileWithPrettifyAttribute() { | ||
|
||
config.setProperty(JBakeProperty.ASCIIDOCTOR_ATTRIBUTES,"source-highlighter=prettify"); | ||
Map<String, Object> map = parser.processFile(validAsciiDocFile); | ||
Assert.assertNotNull(map); | ||
Assert.assertEquals("draft", map.get("status")); | ||
Assert.assertEquals("post", map.get("type")); | ||
assertThat(map.get("body").toString()) | ||
.contains("class=\"paragraph\"") | ||
.contains("<p>JBake now supports AsciiDoc.</p>") | ||
.contains("class=\"prettyprint highlight\""); | ||
|
||
System.out.println(map.get("body").toString()); | ||
} | ||
|
||
@Test | ||
public void parseAsciidocFileWithCustomAttribute() { | ||
|
||
config.setProperty(JBakeProperty.ASCIIDOCTOR_ATTRIBUTES,"source-highlighter=prettify,testattribute=I Love Jbake"); | ||
Map<String, Object> map = parser.processFile(validAsciiDocFile); | ||
Assert.assertNotNull(map); | ||
Assert.assertEquals("draft", map.get("status")); | ||
Assert.assertEquals("post", map.get("type")); | ||
assertThat(map.get("body").toString()) | ||
.contains("I Love Jbake") | ||
.contains("class=\"prettyprint highlight\""); | ||
|
||
System.out.println(map.get("body").toString()); | ||
} | ||
|
||
|
||
} |