1   /*
2    * Copyright (c) 2009 QOS.ch All rights reserved.
3    * 
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   * 
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   * 
14   * THE SOFTWARE IS PROVIDED "AS  IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  package ch.qos.cal10n.util;
23  
24  import static org.junit.Assert.*;
25  
26  import java.io.FileNotFoundException;
27  import java.io.FileReader;
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  import org.junit.Test;
32  
33  import ch.qos.cal10n.Cal10nTestConstants;
34  import ch.qos.cal10n.util.Token.TokenType;
35  
36  /**
37   * 
38   * @author Ceki Gülcü
39   *
40   */
41  public class TokenStreamTest {
42  
43    
44    @Test
45    public void smoke() throws FileNotFoundException {
46      FileReader fr = new FileReader(Cal10nTestConstants.TEST_CLASSES+"/parser/smoke.properties");
47      TokenStream ts = new TokenStream(fr);
48      List<Token> tokenList = ts.tokenize();
49      
50      List<Token> witness = new ArrayList<Token>();
51      witness.add(new Token(TokenType.KEY, "K0"));
52      witness.add(new Token(TokenType.SEPARATOR, "="));
53      witness.add(new Token(TokenType.VALUE, "V0"));
54      witness.add(Token.EOL);
55  
56      witness.add(new Token(TokenType.KEY, "K1"));
57      witness.add(new Token(TokenType.SEPARATOR, "="));
58      witness.add(new Token(TokenType.VALUE, "V1"));
59      witness.add(Token.EOL);
60      assertEquals(witness, tokenList);
61    }
62    
63    @Test
64    public void medium() throws FileNotFoundException {
65      FileReader fr = new FileReader(Cal10nTestConstants.TEST_CLASSES+"/parser/medium.properties");
66      TokenStream ts = new TokenStream(fr);
67      List<Token> tokenList = ts.tokenize();
68      
69     // K0=V0 \
70     //  X
71     // # comment
72     // K1=V1
73      
74      
75      List<Token> witness = new ArrayList<Token>();
76      witness.add(new Token(TokenType.KEY, "K0"));
77      witness.add(new Token(TokenType.SEPARATOR, "="));
78      witness.add(new Token(TokenType.VALUE, "V0 "));
79      witness.add(Token.TRAILING_BACKSLASH);
80      witness.add(Token.EOL);
81      witness.add(new Token(TokenType.VALUE, "X"));
82      witness.add(Token.EOL);
83      witness.add(Token.EOL);
84      
85      witness.add(new Token(TokenType.KEY, "K1"));
86      witness.add(new Token(TokenType.SEPARATOR, "="));
87      witness.add(new Token(TokenType.VALUE, "V1"));
88      witness.add(Token.EOL);
89      assertEquals(witness, tokenList);
90    }
91  
92  }