1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 44 public final class QuestionNewParenPhraseTest extends IndentRulesTestCase { 45 46 49 public void testStartOfDocument() throws BadLocationException { 50 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 51 52 _setDocText("\nfoo();"); 54 assertTrue("first line", !rule.applyRule(_doc, 0, Indenter.OTHER)); 55 assertTrue("second line", !rule.applyRule(_doc, 2, Indenter.OTHER)); 56 } 57 58 61 public void testNoParenDelims() throws BadLocationException { 62 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 63 64 _setDocText("foo\nbar.\ny"); 66 assertTrue("second line", !rule.applyRule(_doc, 4, Indenter.OTHER)); 67 assertTrue("third line", !rule.applyRule(_doc, 9, Indenter.OTHER)); 68 } 69 70 73 public void testParenDelimsWithText() throws BadLocationException { 74 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 75 76 _setDocText("new Foo(\nx,\ny;\na[\nbar])\n{"); 78 assertTrue("line after paren", rule.applyRule(_doc, 9, Indenter.OTHER)); 79 assertTrue("line after comma", rule.applyRule(_doc, 12, Indenter.OTHER)); 80 assertTrue("line after semicolon", rule.applyRule(_doc, 15, Indenter.OTHER)); 81 assertTrue("line after bracket", rule.applyRule(_doc, 18, Indenter.OTHER)); 82 assertTrue("line after close paren", !rule.applyRule(_doc, 24, Indenter.OTHER)); 83 } 84 85 88 public void testParenDelimsNoText() throws BadLocationException { 89 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 90 91 _setDocText("(\n,\n;\n[\nfoo\nbar"); 93 assertTrue("line after paren", rule.applyRule(_doc, 2, Indenter.OTHER)); 94 assertTrue("line after comma", rule.applyRule(_doc, 4, Indenter.OTHER)); 95 assertTrue("line after semicolon", rule.applyRule(_doc, 6, Indenter.OTHER)); 96 assertTrue("line after bracket", rule.applyRule(_doc, 8, Indenter.OTHER)); 97 assertTrue("line after text", !rule.applyRule(_doc, 12, Indenter.OTHER)); 98 } 99 100 103 public void testParenDelimsWithComment() throws BadLocationException { 104 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 105 106 _setDocText("for (int i; // comment\ni < 2; /** comment */\ni++) {"); 108 assertTrue("// comment", rule.applyRule(_doc, 23, Indenter.OTHER)); 109 assertTrue("/* */ comment", rule.applyRule(_doc, 45, Indenter.OTHER)); 110 } 111 112 116 public void testMultipleBlankLinesBack() throws BadLocationException { 117 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 118 119 _setDocText("for(\n\nint i;\n\n\ni > 0;;\n)"); 121 assertTrue("line after open paren", rule.applyRule(_doc, 5, Indenter.OTHER)); 122 assertTrue("two lines after open paren", rule.applyRule(_doc, 6, Indenter.OTHER)); 123 assertTrue("line after semicolon", rule.applyRule(_doc, 13, Indenter.OTHER)); 124 assertTrue("two lines after semicolon", rule.applyRule(_doc, 16, Indenter.OTHER)); 125 } 126 127 131 public void testMultipleCommentLinesBack() throws BadLocationException { 132 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 133 134 _setDocText("for(\n//\n/** foo * /int i;\n\n// bar\ni > 0;;\n)"); 136 assertTrue("line after open paren", rule.applyRule(_doc, 7, Indenter.OTHER)); 137 assertTrue("two lines after open paren", rule.applyRule(_doc, 18, Indenter.OTHER)); 138 assertTrue("line after semicolon", rule.applyRule(_doc, 25, Indenter.OTHER)); 139 assertTrue("two lines after semicolon", rule.applyRule(_doc, 28, Indenter.OTHER)); 140 } 141 142 145 public void testDoesNotEndWithParenDelim() throws BadLocationException { 146 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 147 148 _setDocText("foo(bar.\nx,y\n)"); 150 assertTrue("line after paren", !rule.applyRule(_doc, 9, Indenter.OTHER)); 151 assertTrue("line after comma", !rule.applyRule(_doc, 13, Indenter.OTHER)); 152 } 153 154 157 public void testOperatorDelim() throws BadLocationException { 158 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 159 160 _setDocText("foo(x +\ny\n)"); 162 assertTrue("line after operator", rule.applyRule(_doc, 8, Indenter.OTHER)); 163 assertTrue("line after comma", !rule.applyRule(_doc, 10, Indenter.OTHER)); 164 } 165 166 169 public void testIgnoreDelimsOnLine() throws BadLocationException { 170 IndentRuleQuestion rule = new QuestionNewParenPhrase(null, null); 171 172 _setDocText("foo(x.\ny()\n)"); 174 assertTrue("after paren, but not new phrase", !rule.applyRule(_doc, 10, Indenter.OTHER)); 175 } 176 177 } 178 | Popular Tags |