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

File PrintCharactersTest.java

 

Code metrics

16
64
3
1
205
89
20
0.31
21.33
3
6.67

Classes

Class Line # Actions
PrintCharactersTest 28 64 0% 20 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 junit.framework.TestCase;
23   
24    /**
25    * @version $Id: 0be2c8dd98b80817f71dd34ea2893f46afca37f6 $
26    * @since 4.0M1
27    */
 
28    public class PrintCharactersTest extends TestCase
29    {
30    /**
31    * @param name
32    */
 
33  2 toggle public PrintCharactersTest(String name)
34    {
35  2 super(name);
36    }
37   
 
38  1 toggle public void test()
39    {
40  257 for (int i = 0; i < 256; i++) {
41  256 if ((i % 16) == 0) {
42  16 System.out.println();
43    }
44  256 System.out.print("\"");
45  256 char ch = (char) i;
46  256 String str = "";
47  256 switch (ch) {
48  1 case '\t':
49  1 str = "\\t";
50  1 break;
51  1 case '\n':
52  1 str = "\\n";
53  1 break;
54  1 case '\r':
55  1 str = "\\r";
56  1 break;
57  1 case '\"':
58  1 str = "\\\"";
59  1 break;
60  252 default:
61  252 str += ch;
62  252 break;
63    }
64  256 System.out.print(str);
65  256 System.out.print("\", ");
66    }
67    }
68   
69    /**
70    * <pre>
71    | <#NEW_LINE : "\r\n" | "\r" | "\n" >
72    | <#SPACE : [" ", "\t"] >
73    | <#SPECIAL_SYMBOL : [
74    "!", "\"", "#", "$", "%", "&", "'", "(",
75    ")", "*", "+", ",", "-", ".", "/", ":",
76    ";", "<", "=", ">", "?", "@", "[", "\\",
77    "]", "^", "_", "`", "{", "|", "}", "~"
78    ] >
79    | <#CHAR : ~[
80    "\t", "\n", "\r", " ",
81    "!", "\"", "#", "$", "%", "&", "'", "(",
82    ")", "*", "+", ",", "-", ".", "/", ":",
83    ";", "<", "=", ">", "?", "@", "[", "\\",
84    "]", "^", "_", "`", "{", "|", "}", "~"
85    ] >
86    </pre>
87    */
88    /**
89    * http://en.wikipedia.org/wiki/Uniform_Resource_Identifier
90    * http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
91    * http://www.iana.org/assignments/uri-schemes.html
92    *
93    * <pre>
94    *
95    *
96    *
97    * // URI syntax - see http://tools.ietf.org/html/rfc3986#page-49
98    * <#URI: <URI_SCHEME> ":" <URI_HIER_PART> ("?" <URI_QUERY>)? ("#" <URI_FRAGMENT>)? >
99    *
100    * | <#ALPHA: ["A"-"z"]>
101    * | <#DIGIT: ["0"-"9"]>
102    * | <#HEXDIG: ( <DIGIT> | ["A"-"F"] | ["a"-"f"] ) >
103    * | <#DEC_OCTET: (
104    * <DIGIT> // 0-9
105    * | ["1"-"9"] <DIGIT> // 10-99
106    * | "1" <DIGIT> <DIGIT> // 100-199
107    * | "2" ["0"-"4"] <DIGIT> // 200-249
108    * | "25" ["0"-"5"] // 250-255
109    * )>
110    * | <#URI_GEN_DELIMS: [ ":", "/", "?", "#", "[", "]", "@" ]>
111    * | <#URI_SUB_DELIMS: [ "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "=" ]>
112    * | <#URI_UNRESERVED: ( <ALPHA> | <DIGIT> | "-" | "." | "_" | "~" )>
113    * | <#URI_RESERVED: ( <URI_GEN_DELIMS> | <URI_SUB_DELIMS> ) >
114    * | <#URI_SCHEME: <ALPHA> ( <ALPHA> | <DIGIT> | "+" | "-" | "." )* >
115    * | <#URI_PCT_ENCODED: "%" <HEXDIG> <HEXDIG> >
116    * | <#URI_PCHAR: ( <URI_UNRESERVED> | <URI_PCT_ENCODED> | <URI_SUB_DELIMS> | ":" | "@" ) >
117    * | <#URI_QUERY: ( <URI_PCHAR> | "/" | "?" )* >
118    * | <#URI_FRAGMENT: ( <URI_PCHAR> | "/" | "?" )* >
119    *
120    * | <#URI_AUTHORITY: ( <URI_USERINFO> "@" )? <URI_HOST> ( ":" <URI_PORT> )? >
121    * | <#URI_USERINFO: ( <URI_UNRESERVED> | <URI_PCT_ENCODED> | <URI_SUB_DELIMS> | ":" )* >
122    * | <#URI_HOST: ( <URI_IP_LITERAL> | <URI_IP_V4_ADDRESS> | <URI_REG_NAME> ) >
123    * | <#URI_REG_NAME: ( <URI_UNRESERVED> | <URI_PCT_ENCODED> | <URI_SUB_DELIMS> )* >
124    * | <#URI_PORT: (<DIGIT>)* >
125    *
126    * | <#URI_IP_LITERAL: "[" ( <URI_IP_V6_ADDRESS> | <URI_IP_V_FUTURE> ) "]" >
127    * | <#URI_IP_V_FUTURE : "v" ( <HEXDIG> )+ "." ( <URI_UNRESERVED> | <URI_SUB_DELIMS> | ":" )+ >
128    * | <#URI_IP_V4_ADDRESS: <DEC_OCTET> "." <DEC_OCTET> "." <DEC_OCTET> "." <DEC_OCTET> >
129    *
130    * | <#URI_IP_V6_ADDRESS: (
131    * ( <URI_H16> ":" ){6} <URI_LS32>
132    * | "::" ( <URI_H16> ":" ){5} <URI_LS32>
133    * | ( <URI_H16> )? "::" ( <URI_H16> ":" ){4} <URI_LS32>
134    * | ( ( <URI_H16> ":" ){0,1} <URI_H16> )? "::" ( <URI_H16> ":" ){3} <URI_LS32>
135    * | ( ( <URI_H16> ":" ){0,2} <URI_H16> )? "::" ( <URI_H16> ":" ){2} <URI_LS32>
136    * | ( ( <URI_H16> ":" ){0,3} <URI_H16> )? "::" <URI_H16> ":" <URI_LS32>
137    * | ( ( <URI_H16> ":" ){0,4} <URI_H16> )? "::" <URI_LS32>
138    * | ( ( <URI_H16> ":" ){0,5} <URI_H16> )? "::" <URI_H16>
139    * | ( ( <URI_H16> ":" ){0,6} <URI_H16> )? "::"
140    * ) >
141    * | <#URI_H16: (<HEXDIG>){1,4} >
142    * | <#URI_LS32: ( <URI_H16> ":" <URI_H16> ) | <URI_IP_V4_ADDRESS> >
143    *
144    * | <#URI_PATH_ABEMPTY: ( "/" <URI_SEGMENT> )* >
145    * | <#URI_PATH_ABSOLUTE: "/" ( <URI_SEGMENT_NZ> ( "/" <URI_SEGMENT> )* )? >
146    * | <#URI_PATH_ROOTLESS: <URI_SEGMENT_NZ> ( "/" <URI_SEGMENT> )* >
147    * | <#URI_SEGMENT: (<URI_PCHAR>)* >
148    * | <#URI_SEGMENT_NZ: (<URI_PCHAR>)+ >
149    *
150    * // A simplified URI definition: it does not contain an empty path.
151    * | <#URI_HIER_PART: ( "//" <URI_AUTHORITY> <URI_PATH_ABEMPTY> | <URI_PATH_ABSOLUTE> | <URI_PATH_ROOTLESS> )>
152    *
153    * </pre>
154    */
 
155  1 toggle public void test1()
156    {
157  1 System.out.println();
158  1 System.out
159    .println("===================================================");
160  128 for (int i = 0; i < 127; i++) {
161  127 char ch = (char) i;
162  127 String str = "";
163  127 switch (ch) {
164  1 case '\t':
165  1 str = "\\t";
166  1 break;
167  1 case '\n':
168  1 str = "\\n";
169  1 break;
170  1 case '\r':
171  1 str = "\\r";
172  1 break;
173  1 case '\\':
174  1 str = "\\\\";
175  1 break;
176  1 case '\"':
177  1 str = "\\\"";
178  1 break;
179  122 default:
180  122 str += ch;
181  122 break;
182    }
183  127 System.out.print("[" + Integer.toHexString(i) + "] - ");
184  127 System.out.print("\"");
185  127 System.out.print(str);
186  127 System.out.print("\", ");
187  127 if (Character.isSpaceChar(ch)) {
188  1 System.out.print(" space");
189    }
190  127 if (Character.isLetter(ch)) {
191  52 System.out.print(" letter");
192    }
193  127 if (Character.isLetterOrDigit(ch)) {
194  62 System.out.print(" letterOrDigit");
195    }
196  127 if (Character.isDigit(ch)) {
197  10 System.out.print(" digit");
198    }
199  127 if (Character.isWhitespace(ch)) {
200  10 System.out.print(" whitespace");
201    }
202  127 System.out.println();
203    }
204    }
205    }