1 /* 2 * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved. 3 * 4 * This software is distributable under the BSD license. See the terms of the 5 * BSD license in the documentation provided with this software. 6 */ 7 package jline; 8 9 10 /** 11 * Tests various features of editing lines. 12 * 13 * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a> 14 */ 15 public class TestEditLine extends JLineTestCase { TestEditLine(String test)16 public TestEditLine(String test) { 17 super(test); 18 } 19 testDeletePreviousWord()20 public void testDeletePreviousWord() throws Exception { 21 Buffer b = new Buffer("This is a test"); 22 23 assertBuffer("This is a ", b = b.op(ConsoleReader.DELETE_PREV_WORD)); 24 assertBuffer("This is ", b = b.op(ConsoleReader.DELETE_PREV_WORD)); 25 assertBuffer("This ", b = b.op(ConsoleReader.DELETE_PREV_WORD)); 26 assertBuffer("", b = b.op(ConsoleReader.DELETE_PREV_WORD)); 27 assertBuffer("", b = b.op(ConsoleReader.DELETE_PREV_WORD)); 28 assertBuffer("", b = b.op(ConsoleReader.DELETE_PREV_WORD)); 29 } 30 testMoveToEnd()31 public void testMoveToEnd() throws Exception { 32 Buffer b = new Buffer("This is a test"); 33 34 assertBuffer("This is a XtestX", 35 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 36 .append('X') 37 .op(ConsoleReader.MOVE_TO_END) 38 .append('X')); 39 40 assertBuffer("This is Xa testX", 41 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 42 .op(ConsoleReader.PREV_WORD) 43 .append('X') 44 .op(ConsoleReader.MOVE_TO_END) 45 .append('X')); 46 47 assertBuffer("This Xis a testX", 48 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 49 .op(ConsoleReader.PREV_WORD) 50 .op(ConsoleReader.PREV_WORD) 51 .append('X') 52 .op(ConsoleReader.MOVE_TO_END) 53 .append('X')); 54 } 55 testPreviousWord()56 public void testPreviousWord() throws Exception { 57 assertBuffer("This is a Xtest", 58 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 59 .append('X')); 60 assertBuffer("This is Xa test", 61 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 62 .op(ConsoleReader.PREV_WORD) 63 .append('X')); 64 assertBuffer("This Xis a test", 65 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 66 .op(ConsoleReader.PREV_WORD) 67 .op(ConsoleReader.PREV_WORD) 68 .append('X')); 69 assertBuffer("XThis is a test", 70 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 71 .op(ConsoleReader.PREV_WORD) 72 .op(ConsoleReader.PREV_WORD) 73 .op(ConsoleReader.PREV_WORD) 74 .append('X')); 75 assertBuffer("XThis is a test", 76 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 77 .op(ConsoleReader.PREV_WORD) 78 .op(ConsoleReader.PREV_WORD) 79 .op(ConsoleReader.PREV_WORD) 80 .op(ConsoleReader.PREV_WORD) 81 .append('X')); 82 assertBuffer("XThis is a test", 83 new Buffer("This is a test").op(ConsoleReader.PREV_WORD) 84 .op(ConsoleReader.PREV_WORD) 85 .op(ConsoleReader.PREV_WORD) 86 .op(ConsoleReader.PREV_WORD) 87 .op(ConsoleReader.PREV_WORD) 88 .op(ConsoleReader.PREV_WORD) 89 .append('X')); 90 } 91 testLineStart()92 public void testLineStart() throws Exception { 93 assertBuffer("XThis is a test", 94 new Buffer("This is a test").ctrlA().append('X')); 95 assertBuffer("TXhis is a test", 96 new Buffer("This is a test").ctrlA().right().append('X')); 97 } 98 testClearLine()99 public void testClearLine() throws Exception { 100 assertBuffer("", new Buffer("This is a test").ctrlU()); 101 assertBuffer("t", new Buffer("This is a test").left().ctrlU()); 102 assertBuffer("st", new Buffer("This is a test").left().left().ctrlU()); 103 } 104 testRight()105 public void testRight() throws Exception { 106 Buffer b = new Buffer("This is a test"); 107 b = b.left().right().back(); 108 assertBuffer("This is a tes", b); 109 b = b.left().left().left().right().left().back(); 110 assertBuffer("This is ates", b); 111 b.append('X'); 112 assertBuffer("This is aXtes", b); 113 } 114 testLeft()115 public void testLeft() throws Exception { 116 Buffer b = new Buffer("This is a test"); 117 b = b.left().left().left(); 118 assertBuffer("This is a est", b = b.back()); 119 assertBuffer("This is aest", b = b.back()); 120 assertBuffer("This is est", b = b.back()); 121 assertBuffer("This isest", b = b.back()); 122 assertBuffer("This iest", b = b.back()); 123 assertBuffer("This est", b = b.back()); 124 assertBuffer("Thisest", b = b.back()); 125 assertBuffer("Thiest", b = b.back()); 126 assertBuffer("Thest", b = b.back()); 127 assertBuffer("Test", b = b.back()); 128 assertBuffer("est", b = b.back()); 129 assertBuffer("est", b = b.back()); 130 assertBuffer("est", b = b.back()); 131 assertBuffer("est", b = b.back()); 132 assertBuffer("est", b = b.back()); 133 } 134 testBackspace()135 public void testBackspace() throws Exception { 136 Buffer b = new Buffer("This is a test"); 137 assertBuffer("This is a tes", b = b.back()); 138 assertBuffer("This is a te", b = b.back()); 139 assertBuffer("This is a t", b = b.back()); 140 assertBuffer("This is a ", b = b.back()); 141 assertBuffer("This is a", b = b.back()); 142 assertBuffer("This is ", b = b.back()); 143 assertBuffer("This is", b = b.back()); 144 assertBuffer("This i", b = b.back()); 145 assertBuffer("This ", b = b.back()); 146 assertBuffer("This", b = b.back()); 147 assertBuffer("Thi", b = b.back()); 148 assertBuffer("Th", b = b.back()); 149 assertBuffer("T", b = b.back()); 150 assertBuffer("", b = b.back()); 151 assertBuffer("", b = b.back()); 152 assertBuffer("", b = b.back()); 153 assertBuffer("", b = b.back()); 154 assertBuffer("", b = b.back()); 155 } 156 testBuffer()157 public void testBuffer() throws Exception { 158 assertBuffer("This is a test", new Buffer("This is a test")); 159 } 160 } 161