1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 39 public class ActionStartPrevLinePlusTest extends IndentRulesTestCase { 40 41 45 private IndentRuleAction makeAction(String suffix) { return new ActionStartPrevLinePlus(suffix); } 46 47 public void testLeaveBe() throws javax.swing.text.BadLocationException { 48 _setDocText("foo\nbar"); 49 _doc.setCurrentLocation(4); 50 makeAction("").indentLine(_doc, Indenter.OTHER); 51 assertEquals(7, _doc.getLength()); 52 assertEquals("foo\nbar", _doc.getText()); 53 } 54 public void testLeaveBeMidLine() throws javax.swing.text.BadLocationException { 55 _setDocText("foo\nbar"); 56 _doc.setCurrentLocation(6); 57 makeAction("").indentLine(_doc, Indenter.OTHER); 58 assertEquals(7, _doc.getLength()); 59 assertEquals("foo\nbar", _doc.getText()); 60 } 61 public void testAddSpaces() throws javax.swing.text.BadLocationException { 62 _setDocText("foo\nbar"); 63 _doc.setCurrentLocation(4); 64 makeAction(" ").indentLine(_doc, Indenter.OTHER); assertEquals(10, _doc.getLength()); 66 assertEquals("foo\n bar", _doc.getText()); 67 } 68 public void testAddSpacesMidLine() throws javax.swing.text.BadLocationException { 69 _setDocText("foo\nbar"); 70 _doc.setCurrentLocation(6); 71 makeAction(" ").indentLine(_doc, Indenter.OTHER); assertEquals(10, _doc.getLength()); 73 assertEquals("foo\n bar", _doc.getText()); 74 } 75 public void testBothIndented() throws javax.swing.text.BadLocationException { 76 _setDocText(" foo\n bar"); 77 _doc.setCurrentLocation(9); 78 makeAction("").indentLine(_doc, Indenter.OTHER); 79 assertEquals(11, _doc.getLength()); 80 assertEquals(" foo\n bar", _doc.getText()); 81 } 82 public void testBothIndentedAddSpaces() throws javax.swing.text.BadLocationException { 83 _setDocText(" foo\n bar"); 84 _doc.setCurrentLocation(9); 85 makeAction(" ").indentLine(_doc, Indenter.OTHER); 86 assertEquals(14, _doc.getLength()); 87 assertEquals(" foo\n bar", _doc.getText()); 88 } 89 public void testBothIndentedAddStuff() throws javax.swing.text.BadLocationException { 90 _setDocText(" foo\n bar"); 91 _doc.setCurrentLocation(9); 92 makeAction("abc").indentLine(_doc, Indenter.OTHER); 93 assertEquals(14, _doc.getLength()); 94 assertEquals(" foo\n abcbar", _doc.getText()); 95 } 96 public void testSecondLineMisindented() throws javax.swing.text.BadLocationException { 97 _setDocText(" foo\n bar"); 98 _doc.setCurrentLocation(9); 99 makeAction("abc").indentLine(_doc, Indenter.OTHER); 100 assertEquals(14, _doc.getLength()); 101 assertEquals(" foo\n abcbar", _doc.getText()); 102 } 103 public void testLeavesOtherLinesAlone() throws javax.swing.text.BadLocationException { 104 _setDocText("foo\nbar\nblah"); 105 _doc.setCurrentLocation(10); 106 makeAction(" ").indentLine(_doc, Indenter.OTHER); assertEquals(15, _doc.getLength()); 108 assertEquals("foo\nbar\n blah", _doc.getText()); 109 } 110 public void testOtherLinesIndented() throws javax.swing.text.BadLocationException { 111 _setDocText(" foo\n bar\n blah"); 112 _doc.setCurrentLocation(15); 113 makeAction(" ").indentLine(_doc, Indenter.OTHER); assertEquals(20, _doc.getLength()); 115 assertEquals(" foo\n bar\n blah", _doc.getText()); 116 } 117 } 118 | Popular Tags |