001: package com.ecyrd.jspwiki.render;
002:
003: import java.io.IOException;
004: import java.io.StringReader;
005: import java.util.Properties;
006:
007: import junit.framework.Test;
008: import junit.framework.TestCase;
009: import junit.framework.TestSuite;
010:
011: import com.ecyrd.jspwiki.TestEngine;
012: import com.ecyrd.jspwiki.WikiContext;
013: import com.ecyrd.jspwiki.WikiPage;
014: import com.ecyrd.jspwiki.parser.JSPWikiMarkupParser;
015: import com.ecyrd.jspwiki.parser.WikiDocument;
016:
017: public class CreoleRendererTest extends TestCase {
018: protected TestEngine m_testEngine;
019:
020: protected void setUp() throws Exception {
021: Properties props = new Properties();
022: props.load(TestEngine.findTestProperties());
023: m_testEngine = new TestEngine(props);
024: super .setUp();
025: }
026:
027: private String render(String s) throws IOException {
028: WikiPage dummyPage = new WikiPage(m_testEngine, "TestPage");
029: WikiContext ctx = new WikiContext(m_testEngine, dummyPage);
030:
031: StringReader in = new StringReader(s);
032:
033: JSPWikiMarkupParser p = new JSPWikiMarkupParser(ctx, in);
034: WikiDocument d = p.parse();
035:
036: CreoleRenderer cr = new CreoleRenderer(ctx, d);
037:
038: return cr.getString();
039: }
040:
041: public void testItalic() throws Exception {
042: String src = "123 ''test'' 456";
043:
044: assertEquals("123 //test// 456", render(src));
045: }
046:
047: public void testBold() throws Exception {
048: String src = "123 __test__ 456";
049:
050: assertEquals("123 **test** 456", render(src));
051: }
052:
053: public void testBoldItalic() throws Exception {
054: String src = "123 __''test''__ 456";
055:
056: assertEquals("123 **//test//** 456", render(src));
057: }
058:
059: public void testList() throws Exception {
060: String src = "*one\r\n**two\r\n**three\r\n*four";
061:
062: assertEquals("* one\n** two\n** three\n* four", render(src));
063: }
064:
065: public void testList2() throws Exception {
066: String src = "* one\r\n** two\r\n** three\r\n* four";
067:
068: assertEquals("* one\n** two\n** three\n* four", render(src));
069: }
070:
071: public void testList3() throws Exception {
072: String src = "*one\r\n**two\r\n**three\r\n*four";
073:
074: assertEquals("* one\n** two\n** three\n* four", render(src));
075: }
076:
077: public void testList4() throws Exception {
078: String src = "# one\r\n## two\r\n## three\r\n#four";
079:
080: assertEquals("# one\n## two\n## three\n# four", render(src));
081: }
082:
083: /*
084: // FIXME: This class does not work.
085: public void testPara() throws Exception
086: {
087: String src = "aaa\n\nbbb\n\nccc";
088:
089: assertEquals( src, render(src) );
090: }
091: */
092: public void testInlineImages() throws Exception {
093: String src = "Testing [{Image src='http://test/image.png'}] plugin.";
094:
095: assertEquals("Testing {{http://test/image.png}} plugin.",
096: render(src));
097: }
098:
099: public void testPlugins() throws Exception {
100: String src = "[{Counter}] [{Counter}]";
101:
102: assertEquals("<<Counter 1>> <<Counter 2>>", render(src));
103: }
104:
105: public void testHeading1() throws Exception {
106: String src = "!!!Hello";
107:
108: assertEquals("== Hello ==", render(src));
109: }
110:
111: public void testHeading2() throws Exception {
112: String src = "!!Hello";
113:
114: assertEquals("=== Hello ===", render(src));
115: }
116:
117: public void testHeading3() throws Exception {
118: String src = "!Hello";
119:
120: assertEquals("==== Hello ====", render(src));
121: }
122:
123: public void testExternalAnchor() throws Exception {
124: String src = "[http://www.jspwiki.org]";
125:
126: assertEquals("[[http://www.jspwiki.org]]", render(src));
127: }
128:
129: public void testExternalAnchor2() throws Exception {
130: String src = "[JSPWiki|http://www.jspwiki.org]";
131:
132: assertEquals("[[http://www.jspwiki.org|JSPWiki]]", render(src));
133: }
134:
135: public void testLineBreak() throws Exception {
136: String src = "a\nb\nc";
137:
138: assertEquals("a\nb\nc", render(src));
139: }
140:
141: public void testPre() throws Exception {
142: String src = "{{{\n test __foo__ \n}}}";
143:
144: assertEquals("{{{\n test __foo__ \n}}}", render(src));
145: }
146:
147: public void testRule() throws Exception {
148: String src = "a\n----\nb";
149:
150: assertEquals("a\n----\nb", render(src));
151: }
152:
153: public static Test suite() {
154: TestSuite suite = new TestSuite(CreoleRendererTest.class);
155:
156: return suite;
157: }
158: }
|