1 33 34 35 36 package edu.rice.cs.drjava.model.definitions.indent; 37 38 44 public class ActionStartPrevLinePlusBackupTest extends ActionStartPrevLinePlusTest { 45 46 53 private IndentRuleAction makeAction(String suffix) { 54 return new ActionStartPrevLinePlusBackup(suffix, suffix.length()); 55 } 56 57 65 private IndentRuleAction makeBackupAction(String suffix, int position) { 66 return new ActionStartPrevLinePlusBackup(suffix, position); 67 } 68 69 private String _noIndent = "foo\nbar"; 70 private String _evenIndent = " foo\n bar"; 71 private String _unevenIndent = " foo\nbar"; 72 private String _noIndentRes = "foo\nabc bar"; 73 private String _evenIndentRes = " foo\n abc bar"; 74 private String _unevenIndentRes = " foo\n abc bar"; 75 76 79 public void testMoveToStart() throws javax.swing.text.BadLocationException { 80 moveTestHelper(_noIndent, _noIndentRes, 0, 7, 0, 4); 81 moveTestHelper(_evenIndent, _evenIndentRes, 0, 11, 0, 8); 82 moveTestHelper(_unevenIndent, _unevenIndentRes, 2, 9, 0, 8); 83 } 84 85 88 public void testMoveToEnd() throws javax.swing.text.BadLocationException { 89 moveTestHelper(_noIndent, _noIndentRes, 0, 4, 4, 8); 90 moveTestHelper(_evenIndent, _evenIndentRes, 0, 6, 4, 12); 91 moveTestHelper(_unevenIndent, _unevenIndentRes, 2, 6, 4, 12); 92 } 93 94 97 public void testMoveToMiddle() throws javax.swing.text.BadLocationException { 98 moveTestHelper(_noIndent, _noIndentRes, 0, 4, 2, 6); 99 moveTestHelper(_evenIndent, _evenIndentRes, 0, 6, 2, 10); 100 moveTestHelper(_unevenIndent, _unevenIndentRes, 2, 6, 2, 10); 101 } 102 103 112 private void moveTestHelper(String text, String result, int deltaLen, 113 int before, int position, int after) 114 throws javax.swing.text.BadLocationException { 115 _setDocText(text); 116 _doc.setCurrentLocation(before); 118 String suffix = "abc "; 119 makeBackupAction(suffix, position).indentLine(_doc, Indenter.OTHER); 120 assertEquals("text length", 121 text.length() + deltaLen + suffix.length(), 122 _doc.getLength()); 123 assertEquals("text contents", result, _doc.getText()); 124 assertEquals("location", after, _doc.getCurrentLocation()); 125 } 126 } 127 | Popular Tags |