}
@Test
public void testNumericExpansions() throws Exception {
ConsoleReader reader = createConsole();
MemoryHistory history = new MemoryHistory();
history.setMaxSize(3);
// Seed history with three entries:
// 1 history1
// 2 history2
// 3 history3
history.add("history1");
history.add("history2");
history.add("history3");
reader.setHistory(history);
// Validate !n
assertExpansionIllegalArgumentException(reader, "!0");
assertEquals("history1", reader.expandEvents("!1"));
assertEquals("history2", reader.expandEvents("!2"));
assertEquals("history3", reader.expandEvents("!3"));
assertExpansionIllegalArgumentException(reader, "!4");
// Validate !-n
assertExpansionIllegalArgumentException(reader, "!-0");
assertEquals("history3", reader.expandEvents("!-1"));
assertEquals("history2", reader.expandEvents("!-2"));
assertEquals("history1", reader.expandEvents("!-3"));
assertExpansionIllegalArgumentException(reader, "!-4");
// Validate !!
assertEquals("history3", reader.expandEvents("!!"));
// Add two new entries. Because maxSize=3, history is:
// 3 history3
// 4 history4
// 5 history5
history.add("history4");
history.add("history5");
// Validate !n
assertExpansionIllegalArgumentException(reader, "!0");
assertExpansionIllegalArgumentException(reader, "!1");
assertExpansionIllegalArgumentException(reader, "!2");