1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.pattern.parser;
15
16 import org.junit.jupiter.api.Test;
17
18 import ch.qos.logback.core.pattern.FormatInfo;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.fail;
22
23 public class FormatInfoTest {
24
25 @Test
26 public void testEndingInDot() {
27 try {
28 FormatInfo.valueOf("45.");
29 fail("45. is not a valid format info string");
30 } catch (IllegalArgumentException iae) {
31
32 }
33 }
34
35 @Test
36 public void testBasic() {
37 {
38 FormatInfo fi = FormatInfo.valueOf("45");
39 FormatInfo witness = new FormatInfo();
40 witness.setMin(45);
41 assertEquals(witness, fi);
42 }
43
44 {
45 FormatInfo fi = FormatInfo.valueOf("4.5");
46 FormatInfo witness = new FormatInfo();
47 witness.setMin(4);
48 witness.setMax(5);
49 assertEquals(witness, fi);
50 }
51 }
52
53 @Test
54 public void testRightPad() {
55 {
56 FormatInfo fi = FormatInfo.valueOf("-40");
57 FormatInfo witness = new FormatInfo();
58 witness.setMin(40);
59 witness.setLeftPad(false);
60 assertEquals(witness, fi);
61 }
62
63 {
64 FormatInfo fi = FormatInfo.valueOf("-12.5");
65 FormatInfo witness = new FormatInfo();
66 witness.setMin(12);
67 witness.setMax(5);
68 witness.setLeftPad(false);
69 assertEquals(witness, fi);
70 }
71
72 {
73 FormatInfo fi = FormatInfo.valueOf("-14.-5");
74 FormatInfo witness = new FormatInfo();
75 witness.setMin(14);
76 witness.setMax(5);
77 witness.setLeftPad(false);
78 witness.setLeftTruncate(false);
79 assertEquals(witness, fi);
80 }
81 }
82
83 @Test
84 public void testMinOnly() {
85 {
86 FormatInfo fi = FormatInfo.valueOf("49");
87 FormatInfo witness = new FormatInfo();
88 witness.setMin(49);
89 assertEquals(witness, fi);
90 }
91
92 {
93 FormatInfo fi = FormatInfo.valueOf("-587");
94 FormatInfo witness = new FormatInfo();
95 witness.setMin(587);
96 witness.setLeftPad(false);
97 assertEquals(witness, fi);
98 }
99
100 }
101
102 @Test
103 public void testMaxOnly() {
104 {
105 FormatInfo fi = FormatInfo.valueOf(".49");
106 FormatInfo witness = new FormatInfo();
107 witness.setMax(49);
108 assertEquals(witness, fi);
109 }
110
111 {
112 FormatInfo fi = FormatInfo.valueOf(".-5");
113 FormatInfo witness = new FormatInfo();
114 witness.setMax(5);
115 witness.setLeftTruncate(false);
116 assertEquals(witness, fi);
117 }
118 }
119 }