| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
| 30 |
|
@since |
| 31 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (55) |
Complexity: 9 |
Complexity Density: 0.2 |
|
| 32 |
|
public class WikiScannerUtilTest extends TestCase |
| 33 |
|
{ |
| 34 |
|
|
| 35 |
|
@param |
| 36 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 37 |
2 |
public WikiScannerUtilTest(String name)... |
| 38 |
|
{ |
| 39 |
2 |
super(name); |
| 40 |
|
} |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 42 |
1 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 69 |
11 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 87 |
1 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 107 |
6 |
private void testSubstringExtract1(String str, String result)... |
| 108 |
|
{ |
| 109 |
6 |
String test = WikiScannerUtil.extractSubstring(str, "(", ")", '\\'); |
| 110 |
6 |
assertEquals(result, test); |
| 111 |
|
} |
| 112 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 113 |
1 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 127 |
6 |
private void testSubstringExtract2(String str, String result)... |
| 128 |
|
{ |
| 129 |
6 |
String test = WikiScannerUtil.extractSubstring(str, "{{", "}}", '\\'); |
| 130 |
6 |
assertEquals(result, test); |
| 131 |
|
} |
| 132 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 133 |
2 |
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 |
|
} |