1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.velocity.filter

File HTMLVelocityMacroFilterTest.java

 

Code metrics

0
49
12
1
153
109
12
0.24
4.08
12
1

Classes

Class Line # Actions
HTMLVelocityMacroFilterTest 34 49 0% 12 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.internal.macro.velocity.filter;
21   
22    import org.junit.Assert;
23   
24    import org.apache.velocity.VelocityContext;
25    import org.junit.Test;
26    import org.xwiki.rendering.macro.velocity.filter.VelocityMacroFilter;
27    import org.xwiki.test.jmock.AbstractComponentTestCase;
28   
29    /**
30    * Validate the behavior of {@link HTMLVelocityMacroFilter}.
31    *
32    * @version $Id: 24a1cb90a795146f4c9967f03a04d94578deeff2 $
33    */
 
34    public class HTMLVelocityMacroFilterTest extends AbstractComponentTestCase
35    {
36    private VelocityMacroFilter filter;
37   
38    private VelocityContext context;
39   
 
40  10 toggle @Override
41    protected void registerComponents() throws Exception
42    {
43  10 this.filter = getComponentManager().getInstance(VelocityMacroFilter.class, "html");
44  10 this.context = new VelocityContext();
45    }
46   
 
47  46 toggle public void assertFilter(String expected, String input)
48    {
49  46 Assert.assertEquals(expected, this.filter.before(input, this.context));
50    }
51   
 
52  1 toggle @Test
53    public void testFilter()
54    {
55  1 assertFilter("T T", "T T");
56  1 assertFilter("T T", "T T");
57  1 assertFilter("T T", "T\nT");
58  1 assertFilter("T T", "T\n\nT");
59  1 assertFilter("T T", "T\tT");
60  1 assertFilter("T T", "T\t\tT");
61  1 assertFilter("T T", "T \n\tT");
62   
63  1 assertFilter("T", "T ");
64  1 assertFilter("T", " T");
65    }
66   
 
67  1 toggle @Test
68    public void testFilterSP()
69    {
70  1 assertFilter("T$spT", "T$spT");
71  1 assertFilter("T $spT", "T $spT");
72  1 assertFilter("T$sp T", "T$sp T");
73  1 assertFilter("T $sp T", "T $sp T");
74    }
75   
 
76  1 toggle @Test
77    public void testFilterNL()
78    {
79  1 assertFilter("${nl}", "$nl");
80  1 assertFilter("T${nl}", "T $nl");
81  1 assertFilter("${nl}T", "$nl T");
82  1 assertFilter("T${nl}T", "T $nl T");
83  1 assertFilter("T${nl}", "T\n$nl");
84  1 assertFilter("${nl}T", "$nl\n\nT");
85  1 assertFilter("T${nl}T", "T\n\n$nl\n\nT");
86  1 assertFilter("T${nl}T", "T\n \n $nl \n \nT");
87   
88  1 assertFilter("T \\$nl", "T\n\\$nl");
89  1 assertFilter("\\$nl T", "\\$nl\n\nT");
90  1 assertFilter("T \\$nl T", "T\n\n\\$nl\n\nT");
91  1 assertFilter("T \\$nl T", "T\n \n \\$nl \n \nT");
92    }
93   
 
94  1 toggle @Test
95    public void testFilterIndent()
96    {
97  1 assertFilter("#if (true)\ntext#end", "#if (true)\n text#end");
98  1 assertFilter("#if (true)\ntext#end", "#if (true)\n text#end");
99  1 assertFilter("#if (true)\ntext#end", "#if (true)\n \n text#end");
100  1 assertFilter("#if (true)\ntext#end", "#if (true)\n \n \ttext#end");
101  1 assertFilter("#if (true)\n#if (true)\ntext#end#end", "#if (true)\n #if (true)\n text#end#end");
102    }
103   
 
104  1 toggle @Test
105    public void testFilterComment()
106    {
107  1 assertFilter("", "##comment\n#*comment*#");
108    }
109   
 
110  1 toggle @Test
111    public void testFilterDirective()
112    {
113  1 assertFilter("#set()\n#if()\n#foreach()\n#end\n#elseif()\n#else\n#macro()\n#somemacro() T",
114    "##comment\n#set()\n#if()\n#foreach()\n#end\n#elseif()\n#else\n#macro()\n#somemacro()\nT");
115    }
116   
 
117  1 toggle @Test
118    public void testFilterDirectiveSet()
119    {
120  1 assertFilter("#set()\n", "#set()\n");
121  1 assertFilter("#set() ", "#set() ");
122  1 assertFilter("#set()\n", "#set()\n \n ");
123  1 assertFilter("#set(\n)\n", "#set(\n)\n");
124   
125  1 assertFilter("#set()\nT", "#set()\n\n \tT");
126  1 assertFilter("T #set()\nT", "T #set()\n\n \tT");
127   
128  1 assertFilter("#if()\ntext#end", "#if()\ntext\n#end");
129    }
130   
 
131  1 toggle @Test
132    public void testFilterDirectiveMacro()
133    {
134  1 assertFilter("#somemacro() T", "#somemacro()\nT");
135  1 assertFilter("#somemacro() #set()\nT", "#somemacro()\n#set()\nT");
136  1 assertFilter("#somemacro()#set()\n", "#somemacro()\n#set()\n");
137    }
138   
 
139  1 toggle @Test
140    public void testFilterWithMSNL()
141    {
142  1 assertFilter("#set()\n", "#set()\r\n");
143  1 assertFilter("#set()\n", "#set()\r");
144    }
145   
 
146  1 toggle @Test
147    public void testInvalidOrPartial()
148    {
149  1 assertFilter("#${escapetool.H}${declaredRight}#${escapetool.H}",
150    "#${escapetool.H}${declaredRight}#${escapetool.H}");
151  1 assertFilter("$ notvar", "$ notvar");
152    }
153    }