1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3.text.translate;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import org.apache.commons.lang3.AbstractLangTest;
23 import org.junit.jupiter.api.Test;
24
25
26
27
28 @Deprecated
29 class UnicodeEscaperTest extends AbstractLangTest {
30
31 @Test
32 void testAbove() {
33 final UnicodeEscaper ue = UnicodeEscaper.above('F');
34 final String input = "ADFGZ";
35 final String result = ue.translate(input);
36 assertEquals("ADF\\u0047\\u005A", result, "Failed to escape Unicode characters via the above method");
37 }
38
39 @Test
40 void testBelow() {
41 final UnicodeEscaper ue = UnicodeEscaper.below('F');
42 final String input = "ADFGZ";
43 final String result = ue.translate(input);
44 assertEquals("\\u0041\\u0044FGZ", result, "Failed to escape Unicode characters via the below method");
45 }
46
47 @Test
48 void testBetween() {
49 final UnicodeEscaper ue = UnicodeEscaper.between('F', 'L');
50 final String input = "ADFGZ";
51 final String result = ue.translate(input);
52 assertEquals("AD\\u0046\\u0047Z", result, "Failed to escape Unicode characters via the between method");
53 }
54
55 @Test
56 void testSupplementary() {
57 final UnicodeEscaper ue = UnicodeEscaper.above(0x7f);
58
59 final String input = new String(Character.toChars(0x10437));
60 final String result = ue.translate(input);
61 assertEquals("\\uD801\\uDC37", result, "Supplementary code point must escape to a surrogate pair");
62 assertEquals(input, new UnicodeUnescaper().translate(result), "Escaped supplementary code point must round-trip");
63 }
64 }