Crossfire JXClient, Trunk
CommandExpanderTest.java
Go to the documentation of this file.
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 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 /*
149  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
150  *
151  * JXClient is free software; you can redistribute it and/or modify
152  * it under the terms of the GNU General Public License as published by
153  * the Free Software Foundation; either version 2 of the License, or
154  * (at your option) any later version.
155  *
156  * JXClient is distributed in the hope that it will be useful,
157  * but WITHOUT ANY WARRANTY; without even the implied warranty of
158  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159  * GNU General Public License for more details.
160  *
161  * You should have received a copy of the GNU General Public License
162  * along with JXClient; if not, write to the Free Software
163  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
164  *
165  * Copyright (C) 2005-2008 Yann Chachkoff
166  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
167  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
168  */
169 
170 package com.realtime.crossfire.jxclient.commands;
171 
174 import java.util.Arrays;
175 import java.util.Collection;
176 import org.jetbrains.annotations.NotNull;
177 import org.junit.Assert;
178 import org.junit.Test;
179 
184 public class CommandExpanderTest {
185 
190  @Test
191  public void testExpandSingle() {
192  final Commands commands = new Commands();
193  check("xyz", commands, new CommandExec(null, "xyz"));
194  }
195 
200  @Test
201  public void testExpandMultiple() {
202  final Commands commands = new Commands();
203  check("xyz;abc;abc", commands, new CommandExec(null, "xyz"), new CommandExec(null, "abc"), new CommandExec(null, "abc"));
204  }
205 
210  @Test
212  final Commands commands = new Commands();
213  check("xyz;abc", commands, new CommandExec(null, "xyz"), new CommandExec(null, "abc"));
214  check("xyz ;abc", commands, new CommandExec(null, "xyz"), new CommandExec(null, "abc"));
215  check("xyz; abc", commands, new CommandExec(null, "xyz"), new CommandExec(null, "abc"));
216  check("xyz ; abc", commands, new CommandExec(null, "xyz"), new CommandExec(null, "abc"));
217  }
218 
223  @Test
224  public void testExpandIgnoreEmpty() {
225  final Commands commands = new Commands();
226  check("", commands);
227  check(";;;", commands);
228  check(" ; xyz ; abc ; ", commands, new CommandExec(null, "xyz"), new CommandExec(null, "abc"));
229  }
230 
235  @Test
236  public void testExpandPredefined() {
237  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
238  final Commands commands = new Commands();
239  final TestCommand cmd = new TestCommand("cmd", false, crossfireServerConnection);
240  commands.addCommand(cmd);
241  check("cmd", commands, new CommandExec(cmd, ""));
242  check("cmd abc", commands, new CommandExec(cmd, "abc"));
243  check("cm", commands, new CommandExec(null, "cm"));
244  check("cmd2", commands, new CommandExec(null, "cmd2"));
245  check("cmd;cmd;cm;cmd;cmd2", commands, new CommandExec(cmd, ""), new CommandExec(cmd, ""), new CommandExec(null, "cm"), new CommandExec(cmd, ""), new CommandExec(null, "cmd2"));
246  }
247 
252  @Test
253  public void testExpandArguments() {
254  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
255  final Commands commands = new Commands();
256  final TestCommand cmd = new TestCommand("cmd", false, crossfireServerConnection);
257  commands.addCommand(cmd);
258  check("cmd", commands, new CommandExec(cmd, ""));
259  check("cmd abc", commands, new CommandExec(cmd, "abc"));
260  check("cmd abc", commands, new CommandExec(cmd, "abc"));
261  check("cm", commands, new CommandExec(null, "cm"));
262  check("cm abc", commands, new CommandExec(null, "cm abc"));
263  check("cm abc", commands, new CommandExec(null, "cm abc"));
264  }
265 
271  @Test
273  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
274  final Commands commands = new Commands();
275  final TestCommand cmd = new TestCommand("cmd", false, crossfireServerConnection);
276  commands.addCommand(cmd);
277  check("cmd", commands, new CommandExec(cmd, ""));
278  check("Cmd", commands, new CommandExec(cmd, ""));
279  check("cmD", commands, new CommandExec(cmd, ""));
280  check("CMD", commands, new CommandExec(cmd, ""));
281  }
282 
287  @Test
288  public void testExpandAllArguments() {
289  final CrossfireServerConnection crossfireServerConnection = new TestCrossfireServerConnection();
290  final Commands commands = new Commands();
291  final TestCommand cmd = new TestCommand("cmd", false, crossfireServerConnection);
292  final TestCommand bind = new TestCommand("bind", true, crossfireServerConnection);
293  commands.addCommand(cmd);
294  commands.addCommand(bind);
295  check("cmd bind", commands, new CommandExec(cmd, "bind"));
296  check("bind cmd", commands, new CommandExec(bind, "cmd"));
297  check("cmd bind;bind cmd", commands, new CommandExec(cmd, "bind"), new CommandExec(bind, "cmd"));
298  check("bind cmd;cmd bind", commands, new CommandExec(bind, "cmd;cmd bind"));
299  check("cmd bind;bind cmd;cmd bind", commands, new CommandExec(cmd, "bind"), new CommandExec(bind, "cmd;cmd bind"));
300  check("bind cmd;cmd bind;bind cmd", commands, new CommandExec(bind, "cmd;cmd bind;bind cmd"));
301  check("cmd bind ; bind cmd ; cmd bind", commands, new CommandExec(cmd, "bind"), new CommandExec(bind, "cmd ; cmd bind"));
302  check("bind cmd ; cmd bind ; bind cmd", commands, new CommandExec(bind, "cmd ; cmd bind ; bind cmd"));
303  }
304 
312  private static void check(@NotNull final CharSequence command, @NotNull final Commands commands, @NotNull final CommandExec... commandList) {
313  final Collection<CommandExec> expandedCommands = CommandExpander.expand(command, commands);
314  Assert.assertEquals(Arrays.asList(commandList), expandedCommands);
315  }
316 
317 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.commands.TestCommand
Definition: TestCommand.java:32
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.commands.Commands.addCommand
void addCommand(@NotNull final Command command)
Definition: Commands.java:49
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandSingle
void testExpandSingle()
Definition: CommandExpanderTest.java:191
com.realtime.crossfire.jxclient.commands.CommandExpanderTest
Definition: CommandExpanderTest.java:184
com.realtime.crossfire.jxclient.commands.CommandExpander
Definition: CommandExpander.java:35
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandIgnoreWhitespace
void testExpandIgnoreWhitespace()
Definition: CommandExpanderTest.java:211
com.realtime.crossfire.jxclient.commands.CommandExec
Definition: CommandExec.java:32
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandArguments
void testExpandArguments()
Definition: CommandExpanderTest.java:253
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.check
static void check(@NotNull final CharSequence command, @NotNull final Commands commands, @NotNull final CommandExec... commandList)
Definition: CommandExpanderTest.java:312
com.realtime.crossfire.jxclient.commands.CommandExpander.expand
static Collection< CommandExec > expand(@NotNull final CharSequence commandList, @NotNull final Commands commands)
Definition: CommandExpander.java:63
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandAllArguments
void testExpandAllArguments()
Definition: CommandExpanderTest.java:288
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandIgnoreEmpty
void testExpandIgnoreEmpty()
Definition: CommandExpanderTest.java:224
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandPredefined
void testExpandPredefined()
Definition: CommandExpanderTest.java:236
com.realtime.crossfire.jxclient.server.crossfire.TestCrossfireServerConnection
Definition: TestCrossfireServerConnection.java:39
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.commands.Commands
Definition: Commands.java:37
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandCaseInsensitiveCommandNames
void testExpandCaseInsensitiveCommandNames()
Definition: CommandExpanderTest.java:272
com.realtime.crossfire.jxclient.commands.CommandExpanderTest.testExpandMultiple
void testExpandMultiple()
Definition: CommandExpanderTest.java:201