1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 44 public final class QuestionStartingNewStmtTest extends IndentRulesTestCase { 45 46 52 public void testStartOfStmtCheckForEndCharacters() throws BadLocationException { 53 IndentRuleQuestion rule = new QuestionStartingNewStmt(null, null); 54 55 _setDocText("import java.util.Vector;\n"); 57 _doc.setCurrentLocation(4); 58 assertTrue("starting new stmt, prev char docstart", 59 rule.applyRule(_doc, Indenter.OTHER)); 60 61 _setDocText("foo();\nbar();\n"); 63 _doc.setCurrentLocation(7); 64 assertTrue("starting new stmt, prev char ';'", 65 rule.applyRule(_doc, Indenter.OTHER)); 66 67 _setDocText("public void foo() {\nfoo()\n"); 69 _doc.setCurrentLocation(20); 70 assertTrue("starting new stmt, prev char '{'", 71 rule.applyRule(_doc, Indenter.OTHER)); 72 73 _setDocText("x();\n}\nfoo()\n"); 75 _doc.setCurrentLocation(7); 76 assertTrue("starting new stmt, prev char '}'", 77 rule.applyRule(_doc, Indenter.OTHER)); 78 } 79 80 85 public void testStartOfStmtIgnoreWhiteSpaceAndCommentsInBetween() throws BadLocationException { 86 IndentRuleQuestion rule = new QuestionStartingNewStmt(null, null); 87 88 _setDocText("bar();\n\t \n foo();"); 90 _doc.setCurrentLocation(12); 91 assertTrue("starting new stmt, ignore whitespace in between", 92 rule.applyRule(_doc, Indenter.OTHER)); 93 94 _setDocText("} // note:\n//please ignore me\nfoo();\n"); 96 _doc.setCurrentLocation(30); 97 assertTrue("starting new stmt, ignore single line comments", 98 rule.applyRule(_doc, Indenter.OTHER)); 99 100 _setDocText("{ /* in a comment\nstill in a comment\ndone */\nfoo();"); 102 _doc.setCurrentLocation(45); 103 assertTrue("starting new stmt, ignore multi-line comments", 104 rule.applyRule(_doc, Indenter.OTHER)); 105 106 _setDocText("bar();\n/* blah */ foo();\n"); 107 _doc.setCurrentLocation(18); 108 assertTrue("starting new stmt, ignore multi-line comment on same " + 109 "line as new stmt", 110 rule.applyRule(_doc, Indenter.OTHER)); 111 112 _setDocText("method foo() {\n" + 113 "}\n" + 114 " "); 115 _doc.setCurrentLocation(17); 116 assertTrue("Blank line with no non-WS after", 117 rule.applyRule(_doc, Indenter.OTHER)); 118 119 _setDocText("method foo() {\n" + 120 "}\n" + 121 " \n" + 122 "// comment"); 123 _doc.setCurrentLocation(17); 124 assertTrue("Blank line with comments after, but no non-WS", 125 rule.applyRule(_doc, Indenter.OTHER)); 126 } 127 128 133 public void testNotStartOfStmtDueToEndCharactersInCommentsOrQuotes() throws BadLocationException { 134 IndentRuleQuestion rule = new QuestionStartingNewStmt(null, null); 135 136 _setDocText("x = bar + \";\" + \"}\" + \"{\"\n+ foo;\n"); 138 _doc.setCurrentLocation(26); 139 assertTrue("not starting new stmt, ignore end chars in quotes", 140 !rule.applyRule(_doc, Indenter.OTHER)); 141 142 _setDocText("x = bar.//;{}\nfoo();\n"); 144 _doc.setCurrentLocation(14); 145 assertTrue("not starting new stmt, ignore end chars in single-line comments", 146 !rule.applyRule(_doc, Indenter.OTHER)); 147 148 _setDocText("x = bar./*;\n{\n}\n*/\nfoo();\n"); 150 _doc.setCurrentLocation(19); 151 assertTrue("not starting new stmt, ignore end chars in multi-line comments", 152 !rule.applyRule(_doc, Indenter.OTHER)); 153 } 154 } 155 | Popular Tags |