KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jline > TestHistory


1 /**
2  * jline - Java console input library
3  * Copyright (c) 2002-2006, Marc Prud'hommeaux mwp1@cornell.edu
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or
7  * without modification, are permitted provided that the following
8  * conditions are met:
9  *
10  * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer
15  * in the documentation and/or other materials provided with
16  * the distribution.
17  *
18  * Neither the name of JLine nor the names of its contributors
19  * may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26  * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34  * OF THE POSSIBILITY OF SUCH DAMAGE.
35  */

36 package jline;
37
38
39 /**
40  * Tests command history.
41  *
42  * @author <a HREF="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a>
43  */

44 public class TestHistory
45     extends JLineTestCase
46 {
47     public TestHistory (String JavaDoc test)
48     {
49         super (test);
50     }
51
52
53     public void testSingleHistory ()
54         throws Exception JavaDoc
55     {
56         Buffer b = new Buffer ()
57             .append ("test line 1").op (ConsoleReader.NEWLINE)
58             .append ("test line 2").op (ConsoleReader.NEWLINE)
59             .append ("test line 3").op (ConsoleReader.NEWLINE)
60             .append ("test line 4").op (ConsoleReader.NEWLINE)
61             .append ("test line 5").op (ConsoleReader.NEWLINE)
62             .append ("");
63
64         assertBuffer ("", b);
65
66         assertBuffer ("test line 5", b = b.op (ConsoleReader.PREV_HISTORY));
67         assertBuffer ("test line 4", b = b.op (ConsoleReader.PREV_HISTORY));
68         assertBuffer ("test line 5", b = b.op (ConsoleReader.NEXT_HISTORY));
69         assertBuffer ("test line 4", b = b.op (ConsoleReader.PREV_HISTORY));
70         assertBuffer ("test line 3", b = b.op (ConsoleReader.PREV_HISTORY));
71         assertBuffer ("test line 2", b = b.op (ConsoleReader.PREV_HISTORY));
72         assertBuffer ("test line 1", b = b.op (ConsoleReader.PREV_HISTORY));
73
74         // beginning of history
75
assertBuffer ("test line 1", b = b.op (ConsoleReader.PREV_HISTORY));
76         assertBuffer ("test line 1", b = b.op (ConsoleReader.PREV_HISTORY));
77         assertBuffer ("test line 1", b = b.op (ConsoleReader.PREV_HISTORY));
78         assertBuffer ("test line 1", b = b.op (ConsoleReader.PREV_HISTORY));
79
80
81         assertBuffer ("test line 2", b = b.op (ConsoleReader.NEXT_HISTORY));
82         assertBuffer ("test line 3", b = b.op (ConsoleReader.NEXT_HISTORY));
83         assertBuffer ("test line 4", b = b.op (ConsoleReader.NEXT_HISTORY));
84         assertBuffer ("test line 5", b = b.op (ConsoleReader.NEXT_HISTORY));
85
86
87         // end of history
88
assertBuffer ("", b = b.op (ConsoleReader.NEXT_HISTORY));
89         assertBuffer ("", b = b.op (ConsoleReader.NEXT_HISTORY));
90         assertBuffer ("", b = b.op (ConsoleReader.NEXT_HISTORY));
91
92
93         assertBuffer ("test line 5", b = b.op (ConsoleReader.PREV_HISTORY));
94         assertBuffer ("test line 4", b = b.op (ConsoleReader.PREV_HISTORY));
95         b = b.op (ConsoleReader.MOVE_TO_BEG).append ("XXX").op (ConsoleReader.NEWLINE);
96         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.PREV_HISTORY));
97         assertBuffer ("test line 5", b = b.op (ConsoleReader.PREV_HISTORY));
98         assertBuffer ("test line 4", b = b.op (ConsoleReader.PREV_HISTORY));
99         assertBuffer ("test line 5", b = b.op (ConsoleReader.NEXT_HISTORY));
100         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.NEXT_HISTORY));
101         assertBuffer ("", b = b.op (ConsoleReader.NEXT_HISTORY));
102
103
104         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.PREV_HISTORY));
105         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.NEWLINE)
106             .op (ConsoleReader.PREV_HISTORY));
107         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.NEWLINE)
108             .op (ConsoleReader.PREV_HISTORY));
109         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.NEWLINE)
110             .op (ConsoleReader.PREV_HISTORY));
111         assertBuffer ("XXXtest line 4", b = b.op (ConsoleReader.NEWLINE)
112             .op (ConsoleReader.PREV_HISTORY));
113     }
114 }
115
116
Popular Tags