1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.velocity.internal.util

File VelocityParserTest.java

 

Code metrics

0
32
6
1
103
65
6
0.19
5.33
6
1

Classes

Class Line # Actions
VelocityParserTest 27 32 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 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.velocity.internal.util;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Test;
25    import org.xwiki.velocity.internal.util.VelocityBlock.VelocityType;
26   
 
27    public class VelocityParserTest
28    {
29    private VelocityParser parser;
30   
 
31  5 toggle @Before
32    public void setUp()
33    {
34  5 this.parser = new VelocityParser();
35    }
36   
37    // Tests
38   
 
39  1 toggle @Test
40    public void isValidVelocityIdentifierChar()
41    {
42  1 Assert.assertTrue(this.parser.isValidVelocityIdentifierChar('a'));
43  1 Assert.assertTrue(this.parser.isValidVelocityIdentifierChar('_'));
44  1 Assert.assertTrue(this.parser.isValidVelocityIdentifierChar('-'));
45   
46  1 Assert.assertFalse(this.parser.isValidVelocityIdentifierChar('.'));
47    }
48   
 
49  1 toggle @Test
50    public void getKeyWordComment() throws InvalidVelocityException
51    {
52  1 VelocityParserContext context = new VelocityParserContext();
53  1 StringBuffer buffer = new StringBuffer();
54   
55  1 int index = this.parser.getKeyWord("## some comment\n ".toCharArray(), 0, buffer, context);
56   
57  1 Assert.assertEquals("## some comment\n".length(), index);
58  1 Assert.assertEquals("## some comment\n", buffer.toString());
59  1 Assert.assertFalse(context.isInVelocityBlock());
60  1 Assert.assertEquals(VelocityType.COMMENT, context.getType());
61    }
62   
 
63  1 toggle @Test
64    public void getKeyWordMultiLinesComment() throws InvalidVelocityException
65    {
66  1 VelocityParserContext context = new VelocityParserContext();
67  1 StringBuffer buffer = new StringBuffer();
68   
69  1 int index = this.parser.getKeyWord("#*\n some comment\n*# ".toCharArray(), 0, buffer, context);
70   
71  1 Assert.assertEquals("#*\n some comment\n*#".length(), index);
72  1 Assert.assertEquals("#*\n some comment\n*#", buffer.toString());
73  1 Assert.assertFalse(context.isInVelocityBlock());
74  1 Assert.assertEquals(VelocityType.COMMENT, context.getType());
75    }
76   
 
77  1 toggle @Test
78    public void getKeyWordDirective() throws InvalidVelocityException
79    {
80  1 VelocityParserContext context = new VelocityParserContext();
81  1 StringBuffer buffer = new StringBuffer();
82   
83  1 int index = this.parser.getKeyWord("#directive(param1 param2, param2) ".toCharArray(), 0, buffer, context);
84   
85  1 Assert.assertEquals("#directive(param1 param2, param2)".length(), index);
86  1 Assert.assertEquals("#directive(param1 param2, param2)", buffer.toString());
87  1 Assert.assertFalse(context.isInVelocityBlock());
88  1 Assert.assertEquals(VelocityType.MACRO, context.getType());
89    }
90   
 
91  1 toggle @Test
92    public void getDirective() throws InvalidVelocityException
93    {
94  1 VelocityParserContext context = new VelocityParserContext();
95  1 StringBuffer buffer = new StringBuffer();
96   
97  1 int index = this.parser.getDirective("#if($a==1)true enough#elseno way!#end".toCharArray(), 0, buffer, context);
98   
99  1 Assert.assertEquals("#if($a==1)".length(), index);
100  1 Assert.assertEquals("#if($a==1)", buffer.toString());
101  1 Assert.assertTrue(context.isInVelocityBlock());
102    }
103    }