1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.core.pattern.parser;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.fail;
14  
15  import org.junit.Test;
16  
17  import ch.qos.logback.core.pattern.FormatInfo;
18  
19  
20  public class FormatInfoTest  {
21  
22    @Test
23    public void testEndingInDot() {
24      try {
25        FormatInfo.valueOf("45.");
26        fail("45. is not a valid format info string");
27      } catch (IllegalArgumentException iae) {
28        // OK
29      }
30    }
31  
32    @Test
33    public void testBasic() {
34      {
35        FormatInfo fi = FormatInfo.valueOf("45");
36        FormatInfo witness = new FormatInfo();
37        witness.setMin(45);
38        assertEquals(witness, fi);
39      }
40  
41      {
42        FormatInfo fi = FormatInfo.valueOf("4.5");
43        FormatInfo witness = new FormatInfo();
44        witness.setMin(4);
45        witness.setMax(5);
46        assertEquals(witness, fi);
47      }
48    }
49  
50    @Test
51    public void testRightPad() {
52      {
53        FormatInfo fi = FormatInfo.valueOf("-40");
54        FormatInfo witness = new FormatInfo();
55        witness.setMin(40);
56        witness.setLeftPad(false);
57        assertEquals(witness, fi);
58      }
59  
60      {
61        FormatInfo fi = FormatInfo.valueOf("-12.5");
62        FormatInfo witness = new FormatInfo();
63        witness.setMin(12);
64        witness.setMax(5);
65        witness.setLeftPad(false);
66        assertEquals(witness, fi);
67      }
68  
69      {
70        FormatInfo fi = FormatInfo.valueOf("-14.-5");
71        FormatInfo witness = new FormatInfo();
72        witness.setMin(14);
73        witness.setMax(5);
74        witness.setLeftPad(false);
75        witness.setLeftTruncate(false);
76        assertEquals(witness, fi);
77      }
78    }
79  
80    @Test
81    public void testMinOnly() {
82      {
83        FormatInfo fi = FormatInfo.valueOf("49");
84        FormatInfo witness = new FormatInfo();
85        witness.setMin(49);
86        assertEquals(witness, fi);
87      }
88  
89      {
90        FormatInfo fi = FormatInfo.valueOf("-587");
91        FormatInfo witness = new FormatInfo();
92        witness.setMin(587);
93        witness.setLeftPad(false);
94        assertEquals(witness, fi);
95      }
96  
97    }
98  
99    @Test
100   public void testMaxOnly() {
101     {
102       FormatInfo fi = FormatInfo.valueOf(".49");
103       FormatInfo witness = new FormatInfo();
104       witness.setMax(49);
105       assertEquals(witness, fi);
106     }
107 
108     {
109       FormatInfo fi = FormatInfo.valueOf(".-5");
110       FormatInfo witness = new FormatInfo();
111       witness.setMax(5);
112       witness.setLeftTruncate(false);
113       assertEquals(witness, fi);
114     }
115   }
116 }