| 1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.BadLocationException ; 37 38 46 public final class QuestionLineContainsTest extends IndentRulesTestCase { 47 48 52 public void testLineContainsColon() throws BadLocationException { 53 IndentRuleQuestion rule = new QuestionLineContains(':', null, null); 54 55 _setDocText("return test ? x : y;\n}\n"); 57 _doc.setCurrentLocation(0); 58 assertTrue("colon in text (after startdoc)", 59 rule.applyRule(_doc, Indenter.OTHER)); 60 _setDocText("foo();\nreturn test ? x : y;\n}\n"); 61 _doc.setCurrentLocation(10); 62 assertTrue("colon in text (after newline)", 63 rule.applyRule(_doc, Indenter.OTHER)); 64 _doc.setCurrentLocation(25); 65 assertTrue("colon in text (after colon on line)", 66 rule.applyRule(_doc, Indenter.OTHER)); 67 } 68 69 73 public void testLineDoesNotContainColon() throws BadLocationException { 74 IndentRuleQuestion rule = new QuestionLineContains(':', null, null); 75 76 _setDocText("foo();\nreturn test ? x : y;\n}\n"); 78 _doc.setCurrentLocation(6); 79 assertTrue("no colon", !rule.applyRule(_doc, Indenter.OTHER)); 80 _doc.setCurrentLocation(28); 81 assertTrue("line of close brace (no colon in text)", !rule.applyRule(_doc, Indenter.OTHER)); 82 } 83 84 89 public void testLineDoesNotContainColonDueToComments() throws BadLocationException { 90 IndentRuleQuestion rule = new QuestionLineContains(':', null, null); 91 92 _setDocText("//case 1:\nreturn test; //? x : y\n}\n"); 94 _doc.setCurrentLocation(0); 95 assertTrue("entire line with colon in comment (no colon, single line comment)", 96 !rule.applyRule(_doc, Indenter.OTHER)); 97 _doc.setCurrentLocation(10); 98 assertTrue("part of line with colon in comment (no colon, single line comment)", 99 !rule.applyRule(_doc, Indenter.OTHER)); 100 101 _setDocText("foo();\nreturn test; /*? x : y*/\n}\n"); 103 _doc.setCurrentLocation(7); 104 assertTrue("no colon, colon in multi-line comment", !rule.applyRule(_doc, Indenter.OTHER)); 105 } 106 107 112 public void testLineDoesNotContainColonDueToQuotes() throws BadLocationException { 113 IndentRuleQuestion rule = new QuestionLineContains(':', null, null); 114 115 _setDocText("foo();\nreturn \"total: \" + sum\n}\n"); 117 _doc.setCurrentLocation(7); 118 assertTrue("no colon, colon in quotes", !rule.applyRule(_doc, Indenter.OTHER)); 119 } 120 } 121 | Popular Tags |