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  
11  package ch.qos.logback.core.pattern.parser;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  import org.junit.Test;
19  
20  public class OptionTokenizerTest  {
21  
22    @Test
23    public void testEmpty() throws ScanException {
24      {
25        List ol = new OptionTokenizer("").tokenize();
26        List witness = new ArrayList();
27        assertEquals(witness, ol);
28      }
29  
30      {
31        List ol = new OptionTokenizer(" ").tokenize();
32        List witness = new ArrayList();
33        assertEquals(witness, ol);
34      }
35    }
36  
37    @Test
38    public void testSimple() throws ScanException {
39      {
40        List ol = new OptionTokenizer("abc").tokenize();
41        List<String> witness = new ArrayList<String>();
42        witness.add("abc");
43        assertEquals(witness, ol);
44      }
45    }
46  
47    @Test
48    public void testSingleQuote() throws ScanException {
49      {
50        List ol = new OptionTokenizer("' '").tokenize();
51        List<String> witness = new ArrayList<String>();
52        witness.add(" ");
53        assertEquals(witness, ol);
54      }
55  
56      {
57        List ol = new OptionTokenizer("' x\t'").tokenize();
58        List<String> witness = new ArrayList<String>();
59        witness.add(" x\t");
60        assertEquals(witness, ol);
61      }
62  
63      {
64        List ol = new OptionTokenizer("' x\\t'").tokenize();
65        List<String> witness = new ArrayList<String>();
66        witness.add(" x\t");
67        assertEquals(witness, ol);
68      }
69  
70      {
71        List ol = new OptionTokenizer("' x\\''").tokenize();
72        List<String> witness = new ArrayList<String>();
73        witness.add(" x\'");
74        assertEquals(witness, ol);
75      }
76    }
77  
78    @Test
79    public void testDoubleQuote() throws ScanException {
80      {
81        List ol = new OptionTokenizer("\" \"").tokenize();
82        List<String> witness = new ArrayList<String>();
83        witness.add(" ");
84        assertEquals(witness, ol);
85      }
86  
87      {
88        List ol = new OptionTokenizer("\" x\t\"").tokenize();
89        List<String> witness = new ArrayList<String>();
90        witness.add(" x\t");
91        assertEquals(witness, ol);
92      }
93  
94      {
95        List ol = new OptionTokenizer("\" x\\t\"").tokenize();
96        List<String> witness = new ArrayList<String>();
97        witness.add(" x\t");
98        assertEquals(witness, ol);
99      }
100 
101     {
102       List ol = new OptionTokenizer("\" x\\\"\"").tokenize();
103       List<String> witness = new ArrayList<String>();
104       witness.add(" x\"");
105       assertEquals(witness, ol);
106     }
107   }
108 
109   @Test
110   public void testMultiple() throws ScanException {
111     {
112       List ol = new OptionTokenizer("a, b").tokenize();
113       List<String> witness = new ArrayList<String>();
114       witness.add("a");
115       witness.add("b");
116       assertEquals(witness, ol);
117     }
118   }
119 
120 }