KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > reducedmodel > BraceTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.definitions.reducedmodel;
35
36 import junit.framework.*;
37 import edu.rice.cs.drjava.DrJavaTestCase;
38
39 /**
40  * Tests the Brace class.
41  * @version $Id: BraceTest.java 3553 2006-02-20 21:22:09Z rcartwright $
42  */

43 public final class BraceTest extends DrJavaTestCase implements ReducedModelStates {
44   protected Brace rparen;
45   protected Brace lparen;
46
47   /**
48    * Set up Braces for testing.
49    */

50   public void setUp() throws Exception JavaDoc {
51     super.setUp();
52     lparen = Brace.MakeBrace("(", FREE);
53     rparen = Brace.MakeBrace(")", FREE);
54   }
55
56   /**
57    * Create the test suite.
58    * @return BraceTest test suite
59    */

60   public static Test suite() {
61     return new TestSuite(BraceTest.class);
62   }
63
64   /**
65    * Tests the successful construction of a Brace using the MakeBrace method.
66    */

67   public void testMakeBraceSuccess() {
68     Brace brace = Brace.MakeBrace("{", FREE);
69     assertEquals("{", brace.getType());
70     assertEquals(1, brace.getSize());
71   }
72
73   /**
74    * Tests the failure to make a Brace with a non-special character.
75    */

76   public void testMakeBraceFailure() {
77     try {
78       Brace.MakeBrace("k", FREE);
79     } catch (BraceException e) {
80       assertEquals("Invalid brace type \"k\"", e.getMessage());
81     }
82   }
83
84   /**
85    * Test the getType function for Braces.
86    */

87   public void testGetType() {
88     assertEquals("(", lparen.getType());
89     assertEquals(")", rparen.getType());
90   }
91
92   /**
93    * Test the isShadowed() function.
94    */

95   public void testIsShadowed() {
96     assertTrue("#0.0", !lparen.isShadowed());
97     lparen.setState(INSIDE_DOUBLE_QUOTE);
98     assertEquals("#0.0.1", INSIDE_DOUBLE_QUOTE, lparen.getState());
99     assertTrue("#0.1", lparen.isShadowed());
100     rparen.setState(INSIDE_BLOCK_COMMENT);
101     assertTrue("#0.2", rparen.isShadowed());
102     rparen.setState(FREE);
103     assertTrue("#0.3", !rparen.isShadowed());
104   }
105
106   /**
107    * Test the isQuoted() function.
108    */

109   public void testIsQuoted() {
110     assertTrue("#0.0", !lparen.isQuoted());
111     lparen.setState(INSIDE_DOUBLE_QUOTE);
112     assertTrue("#0.1", lparen.isQuoted());
113     lparen.setState(INSIDE_BLOCK_COMMENT);
114     assertTrue("#0.2", !lparen.isQuoted());
115   }
116
117   /**
118    * Test the isCommented() function.
119    */

120   public void testIsCommented() {
121     assertTrue("#0.0", !lparen.isCommented());
122     lparen.setState(INSIDE_BLOCK_COMMENT);
123     assertTrue("#0.1", lparen.isCommented());
124     lparen.setState(INSIDE_DOUBLE_QUOTE);
125     assertTrue("#0.2", !lparen.isCommented());
126   }
127
128   /**
129    * Test the toString method.
130    */

131   public void testToString() {
132     assertEquals(" (", lparen.toString());
133     assertEquals(" )", rparen.toString());
134   }
135
136   /**
137    * Test the flip() method.
138    */

139   public void testFlip() {
140     lparen.flip();
141     rparen.flip();
142     assertEquals("(", rparen.getType());
143     assertEquals(")", lparen.getType());
144   }
145
146   /**
147    * Test isOpen() and isClosed().
148    */

149   public void testOpenClosed() {
150     assertTrue(lparen.isOpen());
151     assertTrue(rparen.isClosed());
152   }
153
154   /**
155    * Test isMatch(Brace) method.
156    */

157   public void testIsMatch() {
158     Brace bracket = Brace.MakeBrace("]", FREE);
159     Brace dummy = Brace.MakeBrace("", FREE);
160     assertTrue(lparen.isMatch(rparen));
161     assertTrue(!lparen.isMatch(bracket));
162     assertTrue(!lparen.isMatch(dummy));
163     assertTrue(!dummy.isMatch(lparen));
164   }
165 }
166
167
168
169
Popular Tags