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

File WikiScannerUtilTest.java

 

Code metrics

2
45
8
1
146
106
9
0.2
5.62
8
1.12

Classes

Class Line # Actions
WikiScannerUtilTest 32 45 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 2 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.WikiParameter;
23    import org.xwiki.rendering.wikimodel.WikiParameters;
24    import org.xwiki.rendering.wikimodel.impl.WikiScannerUtil;
25   
26    import junit.framework.TestCase;
27   
28    /**
29    * @version $Id: 7520a33d825a2638f19432fa821128b7feafc397 $
30    * @since 4.0M1
31    */
 
32    public class WikiScannerUtilTest extends TestCase
33    {
34    /**
35    * @param name
36    */
 
37  2 toggle public WikiScannerUtilTest(String name)
38    {
39  2 super(name);
40    }
41   
 
42  1 toggle public void testParams()
43    {
44  1 testParams("a b c d", " ", "a", null, "b", null, "c", null, "d", null);
45  1 testParams("a=b c=d", " ", "a", "b", "c", "d");
46  1 testParams("a=b", "|", "a", "b");
47  1 testParams(" a = b ", "|", "a", "b");
48  1 testParams(" a = b c ", "|", "a", "b c");
49  1 testParams("a=b|c=d", "|", "a", "b", "c", "d");
50  1 testParams("a b c d", "|", "a b c d", null);
51  1 testParams("x=b d e | y= f g h ", "|", "x", "b d e", "y", "f g h");
52  1 testParams(" x = b d e | y = f g h ", "|", "x", "b d e", "y", "f g h");
53  1 testParams(
54    " x = ' b d e ' | y = ' f g h ' ",
55    "|",
56    "x",
57    " b d e ",
58    "y",
59    " f g h ");
60  1 testParams(
61    " x = ' b d e ' y = ' f g h ' ",
62    " ",
63    "x",
64    " b d e ",
65    "y",
66    " f g h ");
67    }
68   
 
69  11 toggle private void testParams(String str, String delim, String... pairs)
70    {
71  11 WikiParameters params = new WikiParameters(str, delim);
72  11 int size = params.getSize();
73  11 assertEquals(pairs.length / 2, size);
74  31 for (int i = 0; i < size; i++) {
75  20 String key = pairs[i * 2];
76  20 String value = pairs[i * 2 + 1];
77  20 WikiParameter pair = params.getParameter(i);
78  20 assertNotNull(pair);
79  20 assertEquals(key, pair.getKey());
80  20 assertEquals(value, pair.getValue());
81    }
82    }
83   
84    /**
85    *
86    */
 
87  1 toggle public void testSubstringExtract()
88    {
89  1 testSubstringExtract1("123", "");
90  1 testSubstringExtract1("123()", "");
91  1 testSubstringExtract1("()", "");
92  1 testSubstringExtract1("(abc)", "abc");
93  1 testSubstringExtract1("123(abc)456", "abc");
94  1 testSubstringExtract1("123(a\\(b\\)c)456", "a(b)c");
95  1 testSubstringExtract1("123(a\\(b\\)c)456", "a\\(b\\)c", false);
96   
97  1 testSubstringExtract2("123{{}}", "");
98  1 testSubstringExtract2("{{}}", "");
99  1 testSubstringExtract2("{{abc}}", "abc");
100  1 testSubstringExtract2("123{{abc}}456", "abc");
101  1 testSubstringExtract2("123{{a\\(b\\)c}}456", "a(b)c");
102  1 testSubstringExtract2("123{{a\\(b\\)c}}456", "a\\(b\\)c", false);
103  1 testSubstringExtract2("123{{a\\{{b\\}}c}}456", "a{{b}}c");
104  1 testSubstringExtract2("123{{a\\{{b\\}}c}}456", "a\\{{b\\}}c", false);
105    }
106   
 
107  6 toggle private void testSubstringExtract1(String str, String result)
108    {
109  6 String test = WikiScannerUtil.extractSubstring(str, "(", ")", '\\');
110  6 assertEquals(result, test);
111    }
112   
 
113  1 toggle private void testSubstringExtract1(
114    String str,
115    String result,
116    boolean cleanEscape)
117    {
118  1 String test = WikiScannerUtil.extractSubstring(
119    str,
120    "(",
121    ")",
122    '\\',
123    cleanEscape);
124  1 assertEquals(result, test);
125    }
126   
 
127  6 toggle private void testSubstringExtract2(String str, String result)
128    {
129  6 String test = WikiScannerUtil.extractSubstring(str, "{{", "}}", '\\');
130  6 assertEquals(result, test);
131    }
132   
 
133  2 toggle private void testSubstringExtract2(
134    String str,
135    String result,
136    boolean cleanEscape)
137    {
138  2 String test = WikiScannerUtil.extractSubstring(
139    str,
140    "{{",
141    "}}",
142    '\\',
143    cleanEscape);
144  2 assertEquals(result, test);
145    }
146    }