1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.wikimodel.test

File CreoleWikiParserTest.java

 

Code metrics

0
63
12
1
346
180
12
0.19
5.25
12
1

Classes

Class Line # Actions
CreoleWikiParserTest 30 63 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.wikimodel.test;
21   
22    import org.xwiki.rendering.wikimodel.IWikiParser;
23    import org.xwiki.rendering.wikimodel.WikiParserException;
24    import org.xwiki.rendering.wikimodel.creole.CreoleWikiParser;
25   
26    /**
27    * @version $Id: 03155c2487b62b12ed8052bf527712fc6f13337d $
28    * @since 4.0M1
29    */
 
30    public class CreoleWikiParserTest extends AbstractWikiParserTest
31    {
32    /**
33    * @param name
34    */
 
35  10 toggle public CreoleWikiParserTest(String name)
36    {
37  10 super(name);
38    }
39   
 
40  61 toggle @Override
41    protected IWikiParser newWikiParser()
42    {
43  61 return new CreoleWikiParser();
44    }
45   
46    /**
47    * @throws WikiParserException
48    */
 
49  1 toggle public void testFormats() throws WikiParserException
50    {
51  1 test("**bold**", "<p><strong>bold</strong></p>");
52  1 test("//italic//", "<p><em>italic</em></p>");
53  1 test("before{{{inside}}}after", "<p>before<tt class=\"wikimodel-verbatim\">inside</tt>after</p>");
54   
55    // Mixed styles
56  1 test(
57    "normal**bold//bold-italic**italic//normal",
58    "<p>normal<strong>bold</strong><strong><em>bold-italic</em></strong><em>italic</em>normal</p>");
59   
60    // Not formatting
61  1 test("_nothing special_", "<p>_nothing special_</p>");
62  1 test(
63    "http://www.foo.bar",
64    "<p><a href='http://www.foo.bar' class='wikimodel-freestanding'>http://www.foo.bar</a></p>");
65    }
66   
67    /**
68    * @throws WikiParserException
69    */
 
70  1 toggle public void testHeaders() throws WikiParserException
71    {
72  1 test("=Header1=", "<h1>Header1</h1>");
73  1 test("==Header2==", "<h2>Header2</h2>");
74  1 test("===Header3===", "<h3>Header3</h3>");
75  1 test("====Header4====", "<h4>Header4</h4>");
76  1 test("=====Header5====", "<h5>Header5</h5>");
77  1 test("======Header6======", "<h6>Header6</h6>");
78  1 test("=======Header6=======", "<h6>Header6</h6>");
79   
80  1 test("\n===Header===\n * list item");
81  1 test("before\n=== Header ===\nafter");
82  1 test("before\n=== Header \nafter");
83  1 test("This is not a header: ===");
84  1 test("== Header**bold** //italic// ==");
85    }
86   
87    /**
88    * @throws WikiParserException
89    */
 
90  1 toggle public void testLineBreaks() throws WikiParserException
91    {
92  1 test("line\\\\break");
93  1 test("not\\a\\break");
94    }
95   
96    /**
97    * @throws WikiParserException
98    */
 
99  1 toggle public void testLists() throws WikiParserException
100    {
101  1 test("\n**item one**", "<p><strong>item one</strong></p>");
102  1 test("**item one**\n\n**item two**", ""
103    + "<p><strong>item one</strong></p>\n"
104    + "<p><strong>item two</strong></p>");
105   
106  1 test(" * item one", "<ul>\n <li>item one</li>\n</ul>");
107  1 test("* item one\n** item two", ""
108    + "<ul>\n"
109    + " <li>item one<ul>\n"
110    + " <li>item two</li>\n"
111    + "</ul>\n"
112    + "</li>\n"
113    + "</ul>");
114   
115    // test(" * item one\n ** item two", ""
116    // + "<ul>\n"
117    // + " <li>item one<ul>\n"
118    // + " <li>item two</li>\n"
119    // + "</ul>\n"
120    // + "</li>\n"
121    // + "</ul>");
122    // test(" * item one\n ** item two\n ** item three", ""
123    // + "<ul>\n"
124    // + " <li>item one<ul>\n"
125    // + " <li>item two</li>\n"
126    // + " <li>item three</li>\n"
127    // + "</ul>\n"
128    // + "</li>\n"
129    // + "</ul>");
130   
131    // Ordered list in an unordered list
132    // test(" * item one\n *# item two\n *# item three", ""
133    // + "<ul>\n"
134    // + " <li>item one<ol>\n"
135    // + " <li>item two</li>\n"
136    // + " <li>item three</li>\n"
137    // + "</ol>\n"
138    // + "</li>\n"
139    // + "</ul>");
140   
141    // test("##item one", ""
142    // + "<ol>\n"
143    // + " <li><ol>\n"
144    // + " <li>item one</li>\n"
145    // + "</ol>\n"
146    // + "</li>\n"
147    // + "</ol>");
148    // test(" ##item one", ""
149    // + "<ol>\n"
150    // + " <li><ol>\n"
151    // + " <li>item one</li>\n"
152    // + "</ol>\n"
153    // + "</li>\n"
154    // + "</ol>");
155    // test(" ## item one", ""
156    // + "<ol>\n"
157    // + " <li><ol>\n"
158    // + " <li>item one</li>\n"
159    // + "</ol>\n"
160    // + "</li>\n"
161    // + "</ol>");
162  1 test("** item one", ""
163    + "<ul>\n"
164    + " <li><ul>\n"
165    + " <li>item one</li>\n"
166    + "</ul>\n"
167    + "</li>\n"
168    + "</ul>");
169  1 test("*** item one", ""
170    + "<ul>\n"
171    + " <li><ul>\n"
172    + " <li><ul>\n"
173    + " <li>item one</li>\n"
174    + "</ul>\n"
175    + "</li>\n"
176    + "</ul>\n"
177    + "</li>\n"
178    + "</ul>");
179  1 test("*## item one", ""
180    + "<ul>\n"
181    + " <li><ol>\n"
182    + " <li><ol>\n"
183    + " <li>item one</li>\n"
184    + "</ol>\n"
185    + "</li>\n"
186    + "</ol>\n"
187    + "</li>\n"
188    + "</ul>");
189  1 test("*##item one", ""
190    + "<ul>\n"
191    + " <li><ol>\n"
192    + " <li><ol>\n"
193    + " <li>item one</li>\n"
194    + "</ol>\n"
195    + "</li>\n"
196    + "</ol>\n"
197    + "</li>\n"
198    + "</ul>");
199   
200    // Two "**" symbols at the beginning of the line are interpreted as a
201    // bold!!!
202  1 test("**item one", "<p><strong>item one</strong></p>");
203  1 test(
204    " **item one",
205    "<blockquote>\n<strong>item one</strong>\n</blockquote>");
206    // test("***item one", "<p><strong>*item one</strong></p>");
207   
208    // test("*#item one", ""
209    // + "<ul>\n"
210    // + " <li><ol>\n"
211    // + " <li>item one</li>\n"
212    // + "</ol>\n"
213    // + "</li>\n"
214    // + "</ul>");
215    // test("*#;item one", ""
216    // + "<ul>\n"
217    // + " <li><ol>\n"
218    // + " <li><dl>\n"
219    // + " <dt>item one</dt>\n"
220    // + "</dl>\n"
221    // + "</li>\n"
222    // + "</ol>\n"
223    // + "</li>\n"
224    // + "</ul>");
225    //
226    // //
227    // test(" * item one\n"
228    // + " * item two\n"
229    // + " # item three\n"
230    // + " # item four\n"
231    // + " * item five - first line\n"
232    // + " item five - second line\n"
233    // + " * item six\n"
234    // + " is on multiple\n"
235    // + " lines");
236    }
237   
238    /**
239    * @throws WikiParserException
240    */
 
241  1 toggle public void testParagraphs() throws WikiParserException
242    {
243  1 test("First paragraph.\n"
244    + "Second line of the same paragraph.\n"
245    + "\n"
246    + "The second paragraph");
247    }
248   
249    /**
250    * @throws WikiParserException
251    */
 
252  1 toggle public void testProperties() throws WikiParserException
253    {
254  1 test("#toto hello world\n123");
255  1 test("#prop1 value1\n#prop2 value2");
256    }
257   
258    /**
259    */
 
260  1 toggle public void testQuot() throws WikiParserException
261    {
262  1 test("This is a paragraph\n\n and this is a quotations\n the second line");
263    }
264   
265    /**
266    * @throws WikiParserException
267    */
 
268  1 toggle public void testReferences() throws WikiParserException
269    {
270  1 test(
271    "before http://www.foo.bar/com after",
272    "<p>before <a href='http://www.foo.bar/com' class='wikimodel-freestanding'>http://www.foo.bar/com</a> after</p>");
273  1 test(
274    "before this+is+a+reference:to_here after",
275    "<p>before <a href='this+is+a+reference:to_here' class='wikimodel-freestanding'>this+is+a+reference:to_here</a> after</p>");
276  1 test(
277    "before [[toto]] after",
278    "<p>before <a href='toto' class='wikimodel-freestanding'>toto</a> after</p>");
279   
280    // Tests from
281    // http://wikicreole.org/wiki/Creole1.0#section-Creole1.0-
282    // LinksInternalExternalAndInterwiki
283  1 test("[[link]]", "<p><a href='link' class='wikimodel-freestanding'>link</a></p>");
284  1 test(
285    "[[MyBigPage|Go to my page]]",
286    "<p><a href='MyBigPage'>Go to my page</a></p>");
287  1 test(
288    "[[http://www.wikicreole.org/]]",
289    "<p><a href='http://www.wikicreole.org/' class='wikimodel-freestanding'>http://www.wikicreole.org/</a></p>");
290  1 test(
291    "http://www.rawlink.org/, http://www.another.rawlink.org",
292    "<p><a href='http://www.rawlink.org/' class='wikimodel-freestanding'>http://www.rawlink.org/</a>, <a href='http://www.another.rawlink.org' class='wikimodel-freestanding'>http://www.another.rawlink.org</a></p>");
293  1 test(
294    "[[http://www.wikicreole.org/|Visit the WikiCreole website]]",
295    "<p><a href='http://www.wikicreole.org/'>Visit the WikiCreole website</a></p>");
296    // test(
297    // "[[Weird Stuff|**Weird** // Stuff//]]",
298    // "<p><a href='Weird Stuff'>**Weird** // Stuff//</a></p>");
299  1 test("[[Weird Stuff|**Weird** // Stuff//]]");
300  1 test(
301    "[[Ohana:WikiFamily]]",
302    "<p><a href='Ohana:WikiFamily' class='wikimodel-freestanding'>Ohana:WikiFamily</a></p>");
303   
304    // Not a reference
305  1 test("before [toto] after", "<p>before [toto] after</p>");
306   
307  1 test("before this+is+a+reference:to_here after");
308  1 test("before this+is+not+a+reference: to_here after");
309  1 test("before|foo:bar|after");
310  1 test("before main:wiki after");
311  1 test("before main:**wiki** after");
312  1 test("before http://www.google.com:8080 after");
313  1 test("before http://www.google.com?q=Hello+World!#fragmenté~~ after");
314   
315  1 test("Bad reference: http://923.43.23.11:8080/toto ");
316  1 test("Bad reference: http:|sdf after");
317    }
318   
319    /**
320    * @throws WikiParserException
321    */
 
322  1 toggle public void testTables() throws WikiParserException
323    {
324  1 test("|= Header 1.1 |= Header 1.2\n"
325    + "| Cell 2.1 | Cell 2.2\n"
326    + "| Cell 3.1 |= Head 3.2", ""
327    + "<table><tbody>\n"
328    + " <tr><th> Header 1.1 </th><th> Header 1.2</th></tr>\n"
329    + " <tr><td> Cell 2.1 </td><td> Cell 2.2</td></tr>\n"
330    + " <tr><td> Cell 3.1 </td><th> Head 3.2</th></tr>\n"
331    + "</tbody></table>");
332  1 test("abc || cde");
333    }
334   
335    /**
336    * @throws WikiParserException
337    */
 
338  1 toggle public void testVerbatimeBlocks() throws WikiParserException
339    {
340  1 test("abc \n{{{ 123\n CDE\n 345 }}} efg");
341  1 test("abc {{{ 123\n CDE\n 345 }}} efg");
342  1 test("abc\n{{{\n{{{\n 123 \n }}}\n}}} efg");
343  1 test("`verbatime`");
344  1 test("`just like this...");
345    }
346    }