1 33 34 package edu.rice.cs.drjava.model.definitions.reducedmodel; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 import edu.rice.cs.drjava.model.AbstractDJDocument; 38 import edu.rice.cs.drjava.model.DJDocument; 39 import edu.rice.cs.drjava.model.definitions.indent.Indenter; 40 41 import javax.swing.text.AbstractDocument ; 42 import javax.swing.text.BadLocationException ; 43 45 49 public final class IndentInfoTest extends DrJavaTestCase { 50 private String _text; 51 private IndentInfo _info; 54 private DJDocument _document; 56 57 58 public void setUp() throws Exception { 59 super.setUp(); 60 _document = new AbstractDJDocument() { 63 protected int startCompoundEdit() { 64 return 0; 66 } 67 protected void endCompoundEdit(int key) { } 68 protected void endLastCompoundEdit() { } 69 protected void addUndoRedo(AbstractDocument.DefaultDocumentEvent chng, Runnable undoCommand, Runnable doCommand) { 70 71 } 72 protected void _styleChanged() { } 73 protected Indenter makeNewIndenter(int indentLevel) { return new Indenter(indentLevel); } 74 }; 75 } 76 77 private void _infoTestHelper(int location, String message, 78 int expDistToPrevNewline, int expDistToBrace, 79 int expDistToNewline, int expDistToBraceCurrent, 80 int expDistToNewlineCurrent) 81 { 82 _document.setCurrentLocation(location); 83 _info = _document.getIndentInformation(); 85 86 assertEquals(message + " -- distToPrevNewline", expDistToPrevNewline, _info.distToPrevNewline); 87 assertEquals(message + " -- distToBrace", expDistToBrace, _info.distToBrace); 88 assertEquals(message + " -- distToNewline", expDistToNewline, _info.distToNewline); 89 assertEquals(message + " -- distToBraceCurrent", expDistToBraceCurrent, _info.distToBraceCurrent); 90 assertEquals(message + " -- distToNewlineCurrent", expDistToNewlineCurrent, _info.distToNewlineCurrent); 91 } 92 93 public void testFieldsForCurrentLocation() throws BadLocationException { 94 95 _text = "foo {\nvoid m1(int a,\nint b) {\n}\n}"; 96 100 _document.clear(); 101 _document.insertString(0, _text, null); 102 103 _infoTestHelper(0, "DOCSTART -- no brace or newline", -1, -1, -1, -1, -1); 104 _infoTestHelper(4, "Location has no brace or newline", -1, -1, -1, -1, -1); 105 _infoTestHelper(5, "Location has a brace but no newline", -1, -1, -1, 1, -1); 106 _infoTestHelper(6, "Location has a brace and a newline", 0, 2, -1, 2, -1); 107 _infoTestHelper(10, "Location has a brace and a newline", 4, 6, -1, 6, -1); 108 _infoTestHelper(13, "Location has a brace and a newline", 7, 9, -1, 9, -1); 109 _infoTestHelper(14, "Location has a brace and a newline", 8, 10, -1, 1, 8); 110 _infoTestHelper(20, "At \\n within parens", 14, 16, -1, 7, 14); 111 _infoTestHelper(21, "Second line within parens", 0, 8, 15, 8, 15); 112 _infoTestHelper(26, "On close paren", 5, 13, 20, 13, 20); 113 _infoTestHelper(28, "On second open brace", 7, 15, 22, 24, -1); 114 _infoTestHelper(29, "On \\n in second set of braces", 8, 16, 23, 1, 8); 115 _infoTestHelper(30, "Close brace of method declaration", 0, 2, 9, 2, 9); 116 _infoTestHelper(31, "Last \\n", 1, 3, 10, 27, -1); 117 _infoTestHelper(32, "Final close brace", 0, 28, -1, 28, -1); 118 } 119 } 120 | Popular Tags |