1 33 34 package edu.rice.cs.drjava.model.repl; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 import edu.rice.cs.util.text.EditDocumentException; 38 39 42 public final class InteractionsDocumentTest extends DrJavaTestCase { 43 protected InteractionsDocument _doc; 44 45 final String _testBanner = "This is a test banner"; 46 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 _doc = new InteractionsDocument(new InteractionsDJDocument(), _testBanner); 52 } 53 54 55 public void testCannotEditBeforePrompt() throws EditDocumentException { 56 TestBeep testBeep = new TestBeep(); 57 _doc.setBeep(testBeep); 58 int origLength = _doc.getLength(); 59 60 _doc.insertText(1, "text", InteractionsDocument.DEFAULT_STYLE); 62 assertEquals("Number of beeps", 1, testBeep.numBeeps); 63 assertEquals("Doc length", origLength, _doc.getLength()); 64 } 65 66 67 public void testClearCurrent() throws EditDocumentException { 68 int origLength = _doc.getLength(); 69 _doc.insertText(origLength, "text", InteractionsDocument.DEFAULT_STYLE); 70 _doc.insertBeforeLastPrompt("before", InteractionsDocument.DEFAULT_STYLE); 71 assertEquals("Length after inserts", origLength + 10, _doc.getLength()); _doc.clearCurrentInteraction(); 73 assertEquals("Length after clear", origLength + 6, _doc.getLength()); } 75 76 77 public void testContentsAndReset() throws EditDocumentException { 78 String banner = _testBanner; 79 String prompt = _doc.getPrompt(); 80 String newBanner = "THIS IS A NEW BANNER\n"; 81 assertEquals("Contents before insert", banner + prompt, _doc.getDocText(0, _doc.getLength())); 82 _doc.insertText(_doc.getLength(), "text", InteractionsDocument.DEFAULT_STYLE); 84 _doc.insertBeforeLastPrompt("before", InteractionsDocument.DEFAULT_STYLE); 85 assertEquals("Contents before reset", banner + "before" + prompt + "text", 86 _doc.getDocText(0, _doc.getLength())); 87 _doc.reset(newBanner); 88 assertEquals("Contents after reset", newBanner + prompt, _doc.getDocText(0, _doc.getLength())); 89 } 90 91 92 public void testInsertNewLine() throws EditDocumentException { 93 int origLength = _doc.getLength(); 94 _doc.insertText(origLength, "command", InteractionsDocument.DEFAULT_STYLE); 95 assertEquals("current interaction before newline", "command", _doc.getCurrentInteraction()); 96 _doc.insertNewLine(origLength + 2); 97 assertEquals("current interaction after newline", "co" + System.getProperty("line.separator") + "mmand", 98 _doc.getCurrentInteraction()); 99 } 100 101 102 public void testRecallFromHistory() throws EditDocumentException { 103 String origText = _doc.getDocText(0, _doc.getLength()); 104 _doc.addToHistory("command"); 105 assertEquals("Contents before recall prev", origText, _doc.getDocText(0, _doc.getLength())); 106 107 _doc.recallPreviousInteractionInHistory(); 108 assertEquals("Contents after recall prev", origText + "command", _doc.getDocText(0, _doc.getLength())); 109 110 _doc.recallNextInteractionInHistory(); 111 assertEquals("Contents after recall next", origText, _doc.getDocText(0, _doc.getLength())); 112 } 113 114 115 116 public static class TestBeep implements Runnable { 117 int numBeeps = 0; 118 public void run() { numBeeps++; } 119 } 120 } 121 122 123 124 | Popular Tags |