1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 45 public final class ActionStartPrevStmtPlusTest extends IndentRulesTestCase { 46 47 public void testNoPrevStmt() throws BadLocationException { 48 IndentRuleAction rule1 = new ActionStartPrevStmtPlus("", true); 49 IndentRuleAction rule2 = new ActionStartPrevStmtPlus(" ", true); 50 51 _setDocText("foo();\n"); 52 rule1.indentLine(_doc, 2, Indenter.OTHER); 53 assertEquals("no prev stmt, no suffix", 54 "foo();\n", 55 _doc.getText()); 56 57 _setDocText("foo();\n"); 58 rule2.indentLine(_doc, 2, Indenter.OTHER); 59 assertEquals("no prev stmt, suffix two spaces", 60 " foo();\n", 61 _doc.getText()); 62 } 63 64 public void testPrevStmtPrevLine() throws BadLocationException { 65 IndentRuleAction rule1 = new ActionStartPrevStmtPlus("", true); 66 IndentRuleAction rule2 = new ActionStartPrevStmtPlus(" ", true); 67 68 _setDocText(" foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\nbiz();\n"); 69 rule1.indentLine(_doc, 44, Indenter.OTHER); 70 assertEquals("prev stmt on prev line, no suffix", 71 " foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\n biz();\n", 72 _doc.getText()); 73 74 _setDocText(" foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\nbiz();\n"); 75 rule2.indentLine(_doc, 44, Indenter.OTHER); 76 assertEquals("prev stmt on prev line, suffix two spaces", 77 " foo().\n//boo();\n/*y=x+1;\nfoo(){}*/\nbar();\n biz();\n", 78 _doc.getText()); 79 } 80 81 public void testPrevStmtSeveralLinesBeforeCurrLocation() throws BadLocationException { 82 IndentRuleAction rule1 = new ActionStartPrevStmtPlus("", true); 83 IndentRuleAction rule2 = new ActionStartPrevStmtPlus(" ", true); 84 85 _setDocText(" foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\nx;\n"); 86 rule1.indentLine(_doc, 56, Indenter.OTHER); 87 assertEquals("prev stmt serveral lines before, no suffix", 88 " foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\n x;\n", 89 _doc.getText()); 90 91 _setDocText(" foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\nx;\n"); 92 rule2.indentLine(_doc, 56, Indenter.OTHER); 93 assertEquals("prev stmt serveral lines before, suffix two spaces", 94 " foo();\n//y=x+1;\n/*void blah {\n}*/\n ';' + blah.\n//foo\n x;\n", 95 _doc.getText()); 96 } 97 98 public void testColonNotDelim() throws BadLocationException { 99 IndentRuleAction rule = new ActionStartPrevStmtPlus("", false); 100 101 _setDocText("test2 = x ? y :\n" + " z;\n" + "foo();\n"); rule.indentLine(_doc, 21, Indenter.OTHER); 105 assertEquals("Colon is not a delimiter", 106 "test2 = x ? y :\n" + " z;\n" + "foo();\n", 109 _doc.getText()); 110 } 111 112 113 public void testAfterArrayAssign() throws BadLocationException { 114 IndentRuleAction rule = new ActionStartPrevStmtPlus("", false); 115 116 _setDocText("a = {\n" + 117 " b,c,d\n" + 118 "};\n" + 119 " a;"); rule.indentLine(_doc, 17, Indenter.OTHER); 122 assertEquals("After array assignment", 123 "a = {\n" + 124 " b,c,d\n" + 125 "};\n" + 126 "a;", 127 _doc.getText()); 128 } 129 public void testAfterArrayAssignMultiSemi() throws BadLocationException { 130 IndentRuleAction rule = new ActionStartPrevStmtPlus("", false); 131 132 _setDocText("a = {\n" + 133 " b,c,d\n" + 134 "};;;\n" + 135 " a;"); rule.indentLine(_doc, 19, Indenter.OTHER); 138 assertEquals("After array assignment multi semi colons", 139 "a = {\n" + 140 " b,c,d\n" + 141 "};;;\n" + 142 "a;", 143 _doc.getText()); 144 } 145 146 150 168 } 169 170 171 172 | Popular Tags |