1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 46 public final class QuestionStartAfterOpenBraceTest extends IndentRulesTestCase 47 { 48 private String _text; 49 50 private IndentRuleQuestion _rule = new QuestionStartAfterOpenBrace(null, null); 51 52 public void testNoBrace() throws BadLocationException 53 { 54 _text = "method(\nint[] a, String b) {}"; 55 _setDocText(_text); 56 assertTrue("START has no preceding brace.", !_rule.applyRule(_doc, 0, Indenter.OTHER)); 57 assertTrue("START immediately follows an open paren, not a brace.", !_rule.applyRule(_doc, 8, Indenter.OTHER)); 58 assertTrue("START immediately follows an open paren, not a brace.", !_rule.applyRule(_doc, _text.length()-1, Indenter.OTHER)); 59 } 60 61 public void testRightAfterBrace() throws BadLocationException 62 { 63 64 _text = 65 "boolean method() {\n" + 66 "}"; 67 68 _setDocText(_text); 69 assertTrue("START immediately follows an open brace.", _rule.applyRule(_doc, 19, Indenter.OTHER)); 70 71 72 _text = 73 "boolean method(\n" + 74 " int[] a, String b)\n" + 75 "{\n" + 76 "}"; 77 78 _setDocText(_text); 79 assertTrue("START immediately follows an open paren.", !_rule.applyRule(_doc, 40, Indenter.OTHER)); 80 assertTrue("START immediately follows an open brace.", _rule.applyRule(_doc, 41, Indenter.OTHER)); 81 82 } 83 84 public void testWSAfterBrace() throws BadLocationException 85 { 86 87 _text = 88 "if (<cond>) {\n" + 89 "\n" + 90 " if (\n" + 91 " <cond>) { ... }}"; 92 93 _setDocText(_text); 94 95 assertTrue("START immediatly follows an open brace.", _rule.applyRule(_doc, 14, Indenter.OTHER)); 96 assertTrue("Only WS between open brace and START.", _rule.applyRule(_doc, 15, Indenter.OTHER)); 97 assertTrue("Only WS between open brace and START.", _rule.applyRule(_doc, 23, Indenter.OTHER)); 98 assertTrue("START immediatly follows an open paren.", !_rule.applyRule(_doc, 25, Indenter.OTHER)); 99 100 } 101 102 public void testCommentsAfterBrace() throws BadLocationException 103 { 104 105 _text = 106 "class Foo { \n" + 107 " \n" + 108 " /* \n" + 109 " * \n" + 110 " */ \n" + 111 " int field; \n" + 112 "}"; 113 114 _setDocText(_text); 115 116 assertTrue("START = DOCSTART.", !_rule.applyRule(_doc, 0, Indenter.OTHER)); 117 assertTrue("START = DOCSTART.", !_rule.applyRule(_doc, 14, Indenter.OTHER)); 118 assertTrue("Only WS between START and open brace.", _rule.applyRule(_doc, 15, Indenter.OTHER)); 119 assertTrue("Only WS between START and open brace.", _rule.applyRule(_doc, 30, Indenter.OTHER)); 120 assertTrue("Only WS between START and open brace.", _rule.applyRule(_doc, 44, Indenter.OTHER)); 121 assertTrue("Only comment and WS between START and open brace.", _rule.applyRule(_doc, 45, Indenter.OTHER)); 122 assertTrue("Only comment and WS between START and open brace.", _rule.applyRule(_doc, 60, Indenter.OTHER)); 123 assertTrue("Only comment and WS between START and open brace.", _rule.applyRule(_doc, 77, Indenter.OTHER)); 124 } 125 126 public void testBraceLastCharOnLine() throws BadLocationException { 127 _setDocText("{\n"); 128 assertTrue("Brace only char on line.", _rule.applyRule(_doc, 2, Indenter.OTHER)); 129 130 _setDocText("void foo() {\n"); 131 assertTrue("Brace last char on line.", _rule.applyRule(_doc, 13, Indenter.OTHER)); 132 } 133 134 public void testTextAfterBrace() throws BadLocationException { 135 _setDocText("{ hello\n foo();"); 136 assertTrue("Text on line after brace.", _rule.applyRule(_doc, 8, Indenter.OTHER)); 137 } 138 } 139 140 | Popular Tags |