View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.text.translate;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  
22  import org.junit.jupiter.api.Test;
23  
24  /**
25   * Tests {@link OctalUnescaper}.
26   */
27  class OctalUnescaperTest {
28  
29      @Test
30      void testBetween() {
31          final OctalUnescaper oue = new OctalUnescaper(); // .between("1", "377");
32  
33          String input = "\\45";
34          String result = oue.translate(input);
35          assertEquals("\45", result, "Failed to unescape octal characters via the between method");
36  
37          input = "\\377";
38          result = oue.translate(input);
39          assertEquals("\377", result, "Failed to unescape octal characters via the between method");
40  
41          input = "\\377 and";
42          result = oue.translate(input);
43          assertEquals("\377 and", result, "Failed to unescape octal characters via the between method");
44  
45          input = "\\378 and";
46          result = oue.translate(input);
47          assertEquals("\37" + "8 and", result, "Failed to unescape octal characters via the between method");
48  
49          input = "\\378";
50          result = oue.translate(input);
51          assertEquals("\37" + "8", result, "Failed to unescape octal characters via the between method");
52  
53          input = "\\1";
54          result = oue.translate(input);
55          assertEquals("\1", result, "Failed to unescape octal characters via the between method");
56  
57          input = "\\036";
58          result = oue.translate(input);
59          assertEquals("\036", result, "Failed to unescape octal characters via the between method");
60  
61          input = "\\0365";
62          result = oue.translate(input);
63          assertEquals("\036" + "5", result, "Failed to unescape octal characters via the between method");
64  
65          input = "\\003";
66          result = oue.translate(input);
67          assertEquals("\003", result, "Failed to unescape octal characters via the between method");
68  
69          input = "\\0003";
70          result = oue.translate(input);
71          assertEquals("\000" + "3", result, "Failed to unescape octal characters via the between method");
72  
73          input = "\\279";
74          result = oue.translate(input);
75          assertEquals("\279", result, "Failed to unescape octal characters via the between method");
76  
77          input = "\\999";
78          result = oue.translate(input);
79          assertEquals("\\999", result, "Failed to ignore an out of range octal character via the between method");
80      }
81  
82  }