1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.encoder;
16
17 import org.junit.jupiter.api.Test;
18
19 import static org.junit.jupiter.api.Assertions.*;
20
21 class JsonEscapeUtilTest {
22
23 @Test
24 public void smokeTestEscapeCodes() {
25 assertEquals("\\u0001", JsonEscapeUtil.ESCAPE_CODES[1]);
26 assertEquals("\\u0005", JsonEscapeUtil.ESCAPE_CODES[5]);
27 assertEquals("\\b", JsonEscapeUtil.ESCAPE_CODES[8]);
28 assertEquals("\\t", JsonEscapeUtil.ESCAPE_CODES[9]);
29 assertEquals("\\n", JsonEscapeUtil.ESCAPE_CODES[0x0A]);
30 assertEquals("\\u000B", JsonEscapeUtil.ESCAPE_CODES[0x0B]);
31 assertEquals("\\f", JsonEscapeUtil.ESCAPE_CODES[0x0C]);
32 assertEquals("\\r", JsonEscapeUtil.ESCAPE_CODES[0x0D]);
33 assertEquals("\\u000E", JsonEscapeUtil.ESCAPE_CODES[0x0E]);
34
35 assertEquals("\\u001A", JsonEscapeUtil.ESCAPE_CODES[0x1A]);
36 }
37
38 @Test
39 public void smokeTestEscapeString() {
40 assertEquals("abc", JsonEscapeUtil.jsonEscapeString("abc"));
41 assertEquals("{world: \\\"world\\\"}", JsonEscapeUtil.jsonEscapeString("{world: \"world\"}"));
42 assertEquals("{world: "+'\\'+'"'+"world\\\"}", JsonEscapeUtil.jsonEscapeString("{world: \"world\"}"));
43 }
44
45 @Test
46 public void testEscapingLF() {
47 String input = "{\nhello: \"wo\nrld\"}";
48 System.out.println(input);
49 assertEquals("{\\nhello: "+'\\'+'"'+"wo\\nrld\\\"}", JsonEscapeUtil.jsonEscapeString(input));
50 }
51
52 @Test
53 public void testEscapingTab() {
54 String input = "{hello: \"\tworld\"}";
55 System.out.println(input);
56 assertEquals("{hello: "+'\\'+'"'+"\\tworld\\\"}", JsonEscapeUtil.jsonEscapeString(input));
57 }
58 }