/
ShellCommandTest.java
91 lines (68 loc) · 3.32 KB
/
ShellCommandTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.aesh;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.jboss.aesh.cl.CommandLine;
import org.jboss.aesh.cl.exception.RequiredOptionException;
import org.jboss.aesh.complete.CompleteOperation;
import org.junit.Test;
/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class ShellCommandTest {
@Test
public void testShellCommandCompletion() throws Exception {
ForgeShell forgeShell = new ForgeShell();
ShellCommand command = new ShellCommand(new FooCommand(), forgeShell);
CompleteOperation completeOperation = new CompleteOperation("foo-bar -",8);
command.complete(completeOperation);
assertEquals("--name", completeOperation.getCompletionCandidates().get(0));
assertEquals("--help", completeOperation.getCompletionCandidates().get(1));
completeOperation = new CompleteOperation("foo-bar ",7);
command.complete(completeOperation);
assertEquals("--name", completeOperation.getCompletionCandidates().get(0));
assertEquals("--help", completeOperation.getCompletionCandidates().get(1));
completeOperation = new CompleteOperation("foo-bar --na",12);
command.complete(completeOperation);
assertEquals("--name", completeOperation.getCompletionCandidates().get(0));
completeOperation = new CompleteOperation("foo-bar --name",14);
command.complete(completeOperation);
assertEquals("--name", completeOperation.getCompletionCandidates().get(0));
completeOperation = new CompleteOperation("foo-bar --h",14);
command.complete(completeOperation);
assertEquals("--help", completeOperation.getCompletionCandidates().get(0));
completeOperation = new CompleteOperation("foo-bar --b",14);
command.complete(completeOperation);
assertEquals("--bool", completeOperation.getCompletionCandidates().get(0));
assertEquals("--bar", completeOperation.getCompletionCandidates().get(1));
assertEquals("--bar2", completeOperation.getCompletionCandidates().get(2));
/*
completeOperation = new CompleteOperation("foo-bar --bar ",14);
command.complete(completeOperation);
System.out.println(completeOperation);
*/
}
@Test
public void testShellCommandParse() throws Exception {
ForgeShell forgeShell = new ForgeShell();
ShellCommand command = new ShellCommand(new FooCommand(), forgeShell);
CommandLine cl = command.parse("foo-bar --name FOO --help halp --bar BAR");
assertEquals("FOO", cl.getOptionValue("name"));
assertEquals("halp", cl.getOptionValue("help"));
cl = command.parse("foo-bar --name FOO --help halp --targetLocation /tmp --bar BAR");
assertEquals("FOO", cl.getOptionValue("name"));
assertEquals("halp", cl.getOptionValue("help"));
assertEquals("/tmp", cl.getOptionValue("targetLocation"));
try {
cl = command.parse("foo-bar --name FOO --help halp --targetLocation /tmp");
fail();
}
catch (RequiredOptionException iae) {
}
}
}