01: /*
02: * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved.
03: *
04: * This software is distributable under the BSD license. See the terms of the
05: * BSD license in the documentation provided with this software.
06: */
07: package jline;
08:
09: import java.util.*;
10:
11: /**
12: * Tests command history.
13: *
14: * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a>
15: */
16: public class TestCompletion extends JLineTestCase {
17: public TestCompletion(String test) {
18: super (test);
19: }
20:
21: public void testSimpleCompletor() throws Exception {
22: // clear any current completors
23: for (Iterator i = console.getCompletors().iterator(); i
24: .hasNext(); console.removeCompletor((Completor) i
25: .next())) {
26: ;
27: }
28:
29: console.addCompletor(new SimpleCompletor(new String[] { "foo",
30: "bar", "baz" }));
31:
32: assertBuffer("foo ", new Buffer("f").op(ConsoleReader.COMPLETE));
33: // single tab completes to unabbiguous "ba"
34: assertBuffer("ba", new Buffer("b").op(ConsoleReader.COMPLETE));
35: assertBuffer("ba", new Buffer("ba").op(ConsoleReader.COMPLETE));
36: assertBuffer("baz ", new Buffer("baz")
37: .op(ConsoleReader.COMPLETE));
38: }
39:
40: public void testArgumentCompletor() throws Exception {
41: // clear any current completors
42: for (Iterator i = console.getCompletors().iterator(); i
43: .hasNext(); console.removeCompletor((Completor) i
44: .next())) {
45: ;
46: }
47:
48: console.addCompletor(new ArgumentCompletor(new SimpleCompletor(
49: new String[] { "foo", "bar", "baz" })));
50:
51: assertBuffer("foo foo ", new Buffer("foo f")
52: .op(ConsoleReader.COMPLETE));
53: assertBuffer("foo ba", new Buffer("foo b")
54: .op(ConsoleReader.COMPLETE));
55: assertBuffer("foo ba", new Buffer("foo ba")
56: .op(ConsoleReader.COMPLETE));
57: assertBuffer("foo baz ", new Buffer("foo baz")
58: .op(ConsoleReader.COMPLETE));
59:
60: // test completion in the mid range
61: assertBuffer("foo baz", new Buffer("f baz").left().left()
62: .left().left().op(ConsoleReader.COMPLETE));
63: assertBuffer("ba foo", new Buffer("b foo").left().left().left()
64: .left().op(ConsoleReader.COMPLETE));
65: assertBuffer("foo ba baz", new Buffer("foo b baz").left()
66: .left().left().left().op(ConsoleReader.COMPLETE));
67: assertBuffer("foo foo baz", new Buffer("foo f baz").left()
68: .left().left().left().op(ConsoleReader.COMPLETE));
69: }
70: }
|