1 33 34 package edu.rice.cs.drjava.model.definitions.reducedmodel; 35 36 import junit.framework.*; 37 import edu.rice.cs.drjava.DrJavaTestCase; 38 39 43 public final class BraceTest extends DrJavaTestCase implements ReducedModelStates { 44 protected Brace rparen; 45 protected Brace lparen; 46 47 50 public void setUp() throws Exception { 51 super.setUp(); 52 lparen = Brace.MakeBrace("(", FREE); 53 rparen = Brace.MakeBrace(")", FREE); 54 } 55 56 60 public static Test suite() { 61 return new TestSuite(BraceTest.class); 62 } 63 64 67 public void testMakeBraceSuccess() { 68 Brace brace = Brace.MakeBrace("{", FREE); 69 assertEquals("{", brace.getType()); 70 assertEquals(1, brace.getSize()); 71 } 72 73 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 87 public void testGetType() { 88 assertEquals("(", lparen.getType()); 89 assertEquals(")", rparen.getType()); 90 } 91 92 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 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 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 131 public void testToString() { 132 assertEquals(" (", lparen.toString()); 133 assertEquals(" )", rparen.toString()); 134 } 135 136 139 public void testFlip() { 140 lparen.flip(); 141 rparen.flip(); 142 assertEquals("(", rparen.getType()); 143 assertEquals(")", lparen.getType()); 144 } 145 146 149 public void testOpenClosed() { 150 assertTrue(lparen.isOpen()); 151 assertTrue(rparen.isClosed()); 152 } 153 154 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 |