This project has retired. For details please refer to its Attic page.
StringUtilTest xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.server.support.query;
20  
21  import static org.junit.Assert.*;
22  
23  import org.junit.Test;
24  
25  public class StringUtilTest {
26      
27      @Test
28      public void testUnescape() {
29          String s = "abc";
30          String res = StringUtil.unescape(s, null);
31          assertEquals("abc", res);
32          
33          s="ab\\\\c";
34          res = StringUtil.unescape(s, null);
35          assertEquals("ab\\c", res);
36  
37          s="ab\\'c";
38          res = StringUtil.unescape(s, null);
39          assertEquals("ab'c", res);
40          
41          s="ab\\'";
42          res = StringUtil.unescape(s, null);
43          assertEquals("ab'", res);
44  
45          s="\\\\abc";
46          res = StringUtil.unescape(s, null);
47          assertEquals("\\abc", res);
48          
49          s="abc\\\\";
50          res = StringUtil.unescape(s, null);
51          assertEquals("abc\\", res);
52          
53          s="abc\\";
54          res = StringUtil.unescape(s, null);
55          assertNull(res);
56  
57          s="ab\\xc";
58          res = StringUtil.unescape(s, null);
59          assertNull(res);
60      
61          s="ab\\xc";
62          res = StringUtil.unescape(s, "\\'x");
63          assertEquals("abxc", res);
64          
65          s="abc\\x";
66          res = StringUtil.unescape(s, "\\'x");
67          assertEquals("abcx", res);
68  
69          s="ab\\yc";
70          res = StringUtil.unescape(s, "\\'x");
71          assertNull(res);
72  
73          // double escaping
74          s="ab\\\\\\\\c";
75          res = StringUtil.unescape(s, null);
76          assertEquals("ab\\\\c", res);
77  
78          s="ab\\\\'c";
79          res = StringUtil.unescape(s, null);
80          assertEquals("ab\\'c", res);
81          
82          s="ab\\'Johnny\\'c";
83          res = StringUtil.unescape(s, null);
84          assertEquals("ab'Johnny'c", res);
85  
86          s="ab\\\\'Johnny\\\\'c";
87          res = StringUtil.unescape(s, null);
88          assertEquals("ab\\'Johnny\\'c", res);
89  
90          s="\\\\";
91          res = StringUtil.unescape(s, null);
92          assertEquals("\\", res);
93  
94          s="\\";
95          res = StringUtil.unescape(s, null);
96          assertNull(res);
97  
98          s="a";
99          res = StringUtil.unescape(s, null);
100         assertEquals("a", res);
101         
102         s="";
103         res = StringUtil.unescape(s, null);
104         assertEquals("", res);
105 
106         res = StringUtil.unescape(null, null);
107         assertNull(res);
108     }
109 
110 }