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

File VelocityParserTest.java

 

Code metrics

0
26
5
1
90
55
5
0.19
5.2
5
1

Classes

Class Line # Actions
VelocityParserTest 27 26 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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  4 toggle @Before
32    public void setUp()
33    {
34  4 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    }