org.aesh.readline.util.Parser Java Examples
The following examples show how to use
org.aesh.readline.util.Parser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void multiLineQuote() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo \"bar", 100); buffer.setMultiLine(true); buffer.updateMultiLineBuffer(); outConsumer.clear(); buffer.insert(outConsumer::add, " bar ", 100); assertEquals("> bar ", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), outConsumer.get(0).length-7, outConsumer.get(0).length ))); assertEquals("foo \"bar"+Config.getLineSeparator()+" bar ", buffer.asString()); //buffer.insert(outConsumer::add, "\\", 100); buffer.updateMultiLineBuffer(); outConsumer.clear(); buffer.insert(outConsumer::add, "gar\"", 100); assertEquals("> gar\"", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), outConsumer.get(0).length-6, outConsumer.get(0).length ))); assertEquals("foo \"bar"+Config.getLineSeparator()+" bar "+Config.getLineSeparator()+"gar\"", buffer.asString()); }
Example #2
Source File: CompletionHandler.java From aesh-readline with Apache License 2.0 | 6 votes |
/** * Display all possible completions * * @param completions all completion items */ private void displayCompletions(List<TerminalString> completions, Buffer buffer, InputProcessor inputProcessor) { completions.sort(new CaseInsensitiveComparator()); //if the buffer is longer than one line, we need to move the cursor down the number of lines //before we continue if(inputProcessor.buffer().buffer().length() > inputProcessor.buffer().size().getWidth()) { int numRows = inputProcessor.buffer().buffer().length() / inputProcessor.buffer().size().getWidth(); int cursorRow = inputProcessor.buffer().buffer().cursor() / inputProcessor.buffer().size().getWidth(); for(; cursorRow < numRows; cursorRow++) inputProcessor.buffer().writeOut(new int[] {27, '[', 'B' }); } //finally move to a new line inputProcessor.buffer().writeOut(Config.CR); //then we print out the completions inputProcessor.buffer().writeOut(Parser.formatDisplayListTerminalString(completions, inputProcessor.buffer().size().getHeight(), inputProcessor.buffer().size().getWidth())); //then on the next line we write the line again inputProcessor.buffer().drawLineForceDisplay(); }
Example #3
Source File: CompleteOperationImpl.java From aesh-readline with Apache License 2.0 | 6 votes |
private void setBuffer(String buffer) { //if buffer is longer than cursor it means we try to complete //with the cursor not at the end of the buffer, if so we crop away //what is beyond the cursor if(buffer != null && buffer.length() > cursor+1) { trimmed = true; nonTrimmedBuffer = buffer; this.buffer = buffer.substring(0, cursor); } if(buffer != null && buffer.startsWith(" ")) { trimmed = true; this.buffer = Parser.trimInFront(buffer); nonTrimmedBuffer = buffer; setCursor(cursor - getTrimmedSize()); } //make sure we dont forget to set the buffer if(this.buffer == null) this.buffer = buffer; }
Example #4
Source File: HistoryTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testDupes() { History history = new InMemoryHistory(10); history.push(Parser.toCodePoints("1")); history.push(Parser.toCodePoints("2")); history.push(Parser.toCodePoints("3")); history.push(Parser.toCodePoints("1")); history.push(Parser.toCodePoints("1")); assertArrayEquals(Parser.toCodePoints("1"), history.getPreviousFetch()); assertArrayEquals(Parser.toCodePoints("3"), history.getPreviousFetch()); assertArrayEquals(Parser.toCodePoints("1"), history.getNextFetch()); assertArrayEquals(Parser.toCodePoints("3"), history.getPreviousFetch()); assertArrayEquals(Parser.toCodePoints("2"), history.getPreviousFetch()); assertArrayEquals(Parser.toCodePoints("1"), history.getPreviousFetch()); assertEquals(4, history.getAll().size()); }
Example #5
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void disablePrompt() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo", 100); assertEquals(": foo", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), outConsumer.get(0).length-5, outConsumer.get(0).length ))); buffer.clear(); buffer.insert(outConsumer::add, "foo", 100); assertEquals(": foo", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), outConsumer.get(0).length-5, outConsumer.get(0).length ))); buffer.clear(); buffer.disablePrompt(true); buffer.insert(outConsumer::add, "foo", 100); assertEquals("foo", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), outConsumer.get(0).length-3, outConsumer.get(0).length ))); }
Example #6
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testArrayContains() { int[] source = new int[] {1,2,3,4,5,6,7,8}; int[] target = new int[] {7}; assertTrue(Parser.arrayContains(source, target)); target = new int[] {7,8}; assertTrue(Parser.arrayContains(source, target)); target = new int[] {7,8,9}; assertFalse(Parser.arrayContains(source, target)); target = new int[] {1,2,3,4}; assertTrue(Parser.arrayContains(source, target)); target = new int[] {1,2,3,4,6}; assertFalse(Parser.arrayContains(source, target)); target = new int[] {0,1,2,3,4}; assertFalse(Parser.arrayContains(source, target)); }
Example #7
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testArrayIndexOf() { int[] source = new int[] {1,2,3,4,5,6,7,8}; int[] target = new int[] {7}; assertEquals(6, Parser.arrayIndexOf(source, target)); target = new int[] {7,8}; assertEquals(6, Parser.arrayIndexOf(source, target)); target = new int[] {7,8,9}; assertEquals(-1, Parser.arrayIndexOf(source, target)); target = new int[] {1,2,3,4}; assertEquals(0, Parser.arrayIndexOf(source, target)); target = new int[] {1,2,3,4,6}; assertEquals(-1, Parser.arrayIndexOf(source, target)); target = new int[] {0,1,2,3,4}; assertEquals(-1, Parser.arrayIndexOf(source, target)); }
Example #8
Source File: MaskingReadlineTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void maskingTest() { TestConnection term = new TestConnection(new Prompt("", '\u0000')); term.read("MMyPassword"); term.assertOutputBuffer(""); term.read(Key.BACKSPACE); term.read(Key.ENTER); term.assertLine("MMyPasswor"); term = new TestConnection(new Prompt(Parser.toCodePoints("[foo] "), '%')); term.read("MMyPassword"); term.assertOutputBuffer("[foo] %%%%%%%%%%%"); term.clearOutputBuffer(); term.read(Key.BACKSPACE); term.read(Key.ENTER); term.assertLine("MMyPasswor"); }
Example #9
Source File: ConsoleBufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void testMovement() throws IOException { SimpleConnection connection = new SimpleConnection(); ConsoleBuffer consoleBuffer = createConsoleBuffer(connection,""); consoleBuffer.writeString("foo0"); consoleBuffer.moveCursor(-1); assertEquals("foo0" + Parser.fromCodePoints(ANSI.printAnsi("1D")), connection.bufferBuilder.toString()); consoleBuffer.moveCursor(-10); assertEquals("foo0" + Parser.fromCodePoints(ANSI.printAnsi("1D")) + Parser.fromCodePoints(ANSI.printAnsi("3D")), connection.bufferBuilder.toString()); consoleBuffer.writeString("1"); assertEquals("1foo0", consoleBuffer.buffer().asString()); connection.bufferBuilder.delete(0, connection.bufferBuilder.length()); consoleBuffer.moveCursor(1); assertEquals(Parser.fromCodePoints(ANSI.printAnsi("1C")), connection.bufferBuilder.toString()); consoleBuffer.writeString("2"); assertEquals("1f2oo0", consoleBuffer.buffer().asString()); }
Example #10
Source File: Buffer.java From aesh-readline with Apache License 2.0 | 6 votes |
public void updateMultiLineBuffer() { int originalSize = multiLineBuffer.length; // Store the size of each line. int cmdSize; if (lineEndsWithBackslash()) { cmdSize = size - 1; multiLineBuffer = Arrays.copyOf(multiLineBuffer, originalSize + size-1); System.arraycopy(line, 0, multiLineBuffer, originalSize, size-1); } //here we have an open quote, so we need to feed a new-line into the buffer else { cmdSize = size + Config.getLineSeparator().length(); multiLineBuffer = Arrays.copyOf(multiLineBuffer, originalSize + cmdSize); System.arraycopy(line, 0, multiLineBuffer, originalSize, size); // add new line int[] lineSeparator = Parser.toCodePoints(Config.getLineSeparator()); System.arraycopy(lineSeparator, 0, multiLineBuffer, originalSize+size, lineSeparator.length); } locator.addLine(cmdSize, prompt.getLength()); clear(); prompt = new Prompt("> "); cursor = 0; size = 0; }
Example #11
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void insertLooongText() { String input = "/x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ayList<>(); buffer.insert(outConsumer::add, input, 100); assertEquals(input.length(), buffer.length()); assertEquals(input, Parser.fromCodePoints( outConsumer.get(0))); buffer = new Buffer(new Prompt("")); outConsumer = new ArrayList<>(); for(char c : input.toCharArray()) buffer.insert(outConsumer::add, c, 100); assertEquals(input.length(), buffer.length()); assertEquals(input.length(), outConsumer.size()); assertArrayEquals(new int[] {47}, outConsumer.get(input.length()-1)); }
Example #12
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void replace() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo bar", 100); outConsumer.clear(); buffer.replace(outConsumer::add, " gar", 120); assertEquals(" gar", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), outConsumer.get(0).length-4, outConsumer.get(0).length ))); outConsumer.clear(); buffer.insert(outConsumer::add, 'd', 100); assertEquals(" gard", buffer.asString()); assertEquals("d", Parser.fromCodePoints((outConsumer.get(0)))); }
Example #13
Source File: Line.java From aesh-readline with Apache License 2.0 | 6 votes |
@Override public void apply() { MoveAction move = new MoveAction(index); move.apply(); char c = buffer.asString().charAt(index); // Usage of Intensity.BRIGHT breaks coloring on Windows. // Bold works on both windows and MacOSX, keeping BOLD for all for now. //if (OSUtils.IS_WINDOWS) { TerminalCharacter characterData = new TerminalCharacter(c, new TerminalColor(text, background)); if (bright) { connection.stdoutHandler().accept(Parser.toCodePoints(ANSI.BOLD)); } else { connection.stdoutHandler().accept(Parser.toCodePoints(ANSI.BOLD_OFF)); } connection.stdoutHandler().accept(Parser.toCodePoints(characterData.toString())); //} else { // TerminalColor color = bright ? new TerminalColor(text, background, Color.Intensity.BRIGHT) : new TerminalColor(text, background); // TerminalCharacter characterData = new TerminalCharacter(c, color); // connection.stdoutHandler().accept(Parser.toCodePoints(characterData.toString())); //} moveBackward(1); }
Example #14
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void changeCase() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo bar", 100); buffer.move(outConsumer::add, -1, 120); outConsumer.clear(); buffer.upCase(outConsumer::add); assertEquals("R", Parser.fromCodePoints(outConsumer.get(0))); assertEquals("foo baR", buffer.asString()); buffer.move(outConsumer::add, -4, 120); outConsumer.clear(); buffer.changeCase(outConsumer::add); assertEquals("foO baR", buffer.asString()); outConsumer.clear(); buffer.changeCase(outConsumer::add); assertEquals("foo baR", buffer.asString()); buffer.move(outConsumer::add, 10, 120); outConsumer.clear(); buffer.downCase(outConsumer::add); assertEquals("foo baR", buffer.asString()); buffer.move(outConsumer::add, -1, 120); outConsumer.clear(); buffer.downCase(outConsumer::add); assertEquals("foo bar", buffer.asString()); }
Example #15
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void replaceChar() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo bar", 100); outConsumer.clear(); buffer.replace(outConsumer::add, 'R'); assertEquals("R", Parser.fromCodePoints(outConsumer.get(0))); outConsumer.clear(); assertEquals("foo bar", buffer.asString()); buffer.move(outConsumer::add, -1, 120); buffer.replace(outConsumer::add, 'R'); assertEquals("foo baR", buffer.asString()); buffer.move(outConsumer::add, -4, 120); buffer.replace(outConsumer::add, 'O'); assertEquals("foO baR", buffer.asString()); }
Example #16
Source File: SearchHistory.java From aesh-readline with Apache License 2.0 | 6 votes |
private void printSearch(int[] searchTerm, int[] result, InputProcessor inputProcessor) { //cursor should be placed at the index of searchTerm int cursor = Parser.arrayIndexOf(result, searchTerm); IntArrayBuilder builder; if(inputProcessor.buffer().history().getSearchDirection() == SearchDirection.REVERSE) builder = new IntArrayBuilder(REVERSE_SEARCH_TEXT); else builder = new IntArrayBuilder(FORWARD_SEARCH_TEXT); builder.append(searchTerm).append(DIVIDER); cursor += builder.size(); //LOGGER.info("setting cursor to: "+cursor); builder.append(result); inputProcessor.buffer().moveCursor(-inputProcessor.buffer().buffer().cursor()); inputProcessor.buffer().buffer().disablePrompt(true); inputProcessor.buffer().writeOut(ANSI.CURSOR_START); inputProcessor.buffer().writeOut(ANSI.ERASE_WHOLE_LINE); inputProcessor.buffer().replace(builder.toArray()); //inputProcessor.buffer().drawLine(false, false); //LOGGER.info("moving to: "+cursor); inputProcessor.buffer().moveCursor(cursor-inputProcessor.buffer().buffer().cursor()); inputProcessor.buffer().buffer().disablePrompt(false); }
Example #17
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void moveAndInsert() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo bar", 100); buffer.move(outConsumer::add, -1, 120); buffer.insert(outConsumer::add, 'A', 100); outConsumer.clear(); assertEquals("foo baAr", buffer.asString()); buffer.move(outConsumer::add, -1, 120); outConsumer.clear(); buffer.insert(outConsumer::add, 'b', 100); assertEquals("foo babAr", buffer.asString()); buffer.move(outConsumer::add, -10, 120); outConsumer.clear(); buffer.insert(outConsumer::add, "foo ", 100); assertEquals("foo foo babAr", buffer.asString()); buffer.move(outConsumer::add, 20, 120); outConsumer.clear(); buffer.insert(outConsumer::add, " bar", 100); assertEquals(" bar", Parser.fromCodePoints(outConsumer.get(0))); }
Example #18
Source File: InMemoryHistory.java From aesh-readline with Apache License 2.0 | 6 votes |
@Override public void push(int[] entry) { if(isEnabled() && entry != null && !Parser.isTrimmedArrayEmpty(entry)) { // Don't add repeated lines to the history if(historyList.size() > 0 && Arrays.equals(historyList.get(historyList.size()-1), entry)) { //historyList.get(historyList.size()-1).equals(entry.trim())) { lastId = size(); return; } if(historyList.size() >= maxSize) { historyList.remove(0); } historyList.add(entry); lastId = size(); } }
Example #19
Source File: InMemoryHistory.java From aesh-readline with Apache License 2.0 | 6 votes |
private int[] searchReverse(int[] search) { if(lastId <= 0 || lastId > size()-1) lastId = size()-1; else if(lastSearchArgument != null && Arrays.equals(lastSearchArgument, search) && lastId > 0) lastId--; for(; lastId >= 0; lastId--) if(Parser.arrayContains(historyList.get(lastId), search)) { //if(historyList.get(lastId).contains(search)) { lastSearchArgument = search; if(lastId < 0) lastId = 0; return get(lastId); } return null; }
Example #20
Source File: InMemoryHistory.java From aesh-readline with Apache License 2.0 | 6 votes |
private int[] searchForward(int[] search) { if(lastId >= size()) lastId = 0; else if(lastSearchArgument != null && Arrays.equals(lastSearchArgument, search)) lastId++; for(; lastId < size(); lastId++ ) { if(Parser.arrayContains(historyList.get(lastId), search)) { //if(historyList.get(lastId).contains(search)) { lastSearchArgument = search; return get(lastId); } } return null; }
Example #21
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 6 votes |
@Test public void insertString() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, "foo bar", 100); buffer.insert(outConsumer::add, " ", 100); buffer.insert(outConsumer::add, "foo bar", 100); assertEquals(": ", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), 0, 2 ))); assertEquals("foo bar", Parser.fromCodePoints(Arrays.copyOfRange(outConsumer.get(0), 2, 9 ))); assertEquals(" ", Parser.fromCodePoints(outConsumer.get(1))); assertEquals("foo bar", Parser.fromCodePoints(outConsumer.get(2))); buffer = new Buffer(new Prompt(": ")); outConsumer.clear(); buffer.insert(outConsumer::add, "foo", 100); buffer.move(outConsumer::add, -10, 100); outConsumer.clear(); buffer.insert(outConsumer::add, "1", 100); assertArrayEquals( new int[]{'1','f','o','o',27,'[','3','D'}, outConsumer.get(0)); }
Example #22
Source File: FileHistory.java From aesh-readline with Apache License 2.0 | 6 votes |
/** * Write the content of the history buffer to file * * @throws IOException io */ private void writeFile() throws IOException { historyFile.delete(); try (FileWriter fw = new FileWriter(historyFile)) { for(int i=0; i < size();i++) fw.write(Parser.fromCodePoints(get(i)) + (Config.getLineSeparator())); } if (historyFilePermission != null) { historyFile.setReadable(false, false); historyFile.setReadable(historyFilePermission.isReadable(), historyFilePermission.isReadableOwnerOnly()); historyFile.setWritable(false, false); historyFile.setWritable(historyFilePermission.isWritable(), historyFilePermission.isWritableOwnerOnly()); historyFile.setExecutable(false, false); historyFile.setExecutable(historyFilePermission.isExecutable(), historyFilePermission.isExecutableOwnerOnly()); } }
Example #23
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void insert() { Buffer buffer = new Buffer(new Prompt(": ")); List<int[]> outConsumer = new ArrayList<>(); buffer.print(outConsumer::add, 100); buffer.insert(outConsumer::add, 65, 100); assertEquals(1, buffer.length()); assertEquals(65, buffer.get(0)); buffer.insert(outConsumer::add, 66, 100); buffer.insert(outConsumer::add, 67, 100); assertEquals(66, buffer.get(1)); assertEquals(67, buffer.get(2)); //outConsumer.clear(); //buffer.print(outConsumer::add, 120); //assertArrayEquals(ANSI.CURSOR_START, // Arrays.copyOfRange(outConsumer.get(0), 0, 3)); assertEquals(": ", Parser.fromCodePoints( outConsumer.get(0))); assertArrayEquals(new int[] {65}, outConsumer.get(1)); assertArrayEquals(new int[] {66}, outConsumer.get(2)); assertArrayEquals(new int[] {67}, outConsumer.get(3)); assertEquals("ABC", buffer.asString()); buffer.reset(); outConsumer.clear(); buffer.print(outConsumer::add, 120); assertEquals(": ", Parser.fromCodePoints( outConsumer.get(0))); assertEquals(1, outConsumer.size()); buffer.insert(outConsumer::add, 'A', 100); buffer.insert(outConsumer::add, 'B', 100); buffer.insert(outConsumer::add, 'C', 100); assertEquals(66, buffer.get(1)); assertEquals(67, buffer.get(2)); outConsumer.clear(); buffer.insert(outConsumer::add, " foo", 100); assertEquals(" foo", Parser.fromCodePoints(outConsumer.get(0))); }
Example #24
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testStripAwayAnsiPattern() { assertEquals("foo", Parser.stripAwayAnsiCodes(ANSI.BLACK_TEXT + "foo")); assertEquals("foo", Parser.stripAwayAnsiCodes(ANSI.BOLD + ANSI.CYAN_BG + "foo")); assertEquals("foo", Parser.stripAwayAnsiCodes("foo" + ANSI.BOLD + ANSI.CYAN_BG)); assertEquals("foo", Parser.stripAwayAnsiCodes(ANSI.ALTERNATE_BUFFER + "foo")); assertEquals("foo", Parser.stripAwayAnsiCodes(ANSI.CURSOR_ROW + "foo")); assertEquals("foo bar", Parser.stripAwayAnsiCodes("foo" + ANSI.RESET + " bar")); }
Example #25
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testContainsSpace() { assertTrue(Parser.containsNonEscapedSpace("foo bar")); assertFalse(Parser.containsNonEscapedSpace("foobar")); assertFalse(Parser.containsNonEscapedSpace("foo\\ bar")); assertFalse(Parser.containsNonEscapedSpace("foo\\ bar\\ ")); assertFalse(Parser.containsNonEscapedSpace("\\ foo\\ bar\\ ")); assertTrue(Parser.containsNonEscapedSpace(" foo\\ bar\\ ")); assertTrue(Parser.containsNonEscapedSpace("\\ foo\\ bar ")); }
Example #26
Source File: BufferTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void insertNoPrompt() { Buffer buffer = new Buffer(); List<int[]> outConsumer = new ArrayList<>(); buffer.insert(outConsumer::add, 65, 10); assertEquals(1, buffer.length()); assertEquals(65, buffer.get(0)); buffer.insert(outConsumer::add, 66, 10); buffer.insert(outConsumer::add, 67, 10); assertEquals(66, buffer.get(1)); assertEquals(67, buffer.get(2)); assertArrayEquals(new int[] {65}, outConsumer.get(0)); assertArrayEquals(new int[] {66}, outConsumer.get(1)); assertArrayEquals(new int[] {67}, outConsumer.get(2)); buffer.reset(); outConsumer.clear(); buffer.print(outConsumer::add, 120); assertTrue(outConsumer.get(0).length == 0); buffer.insert(outConsumer::add, 'A', 10); buffer.insert(outConsumer::add, 'B', 10); buffer.insert(outConsumer::add, 'C', 10); assertEquals(66, buffer.get(1)); assertEquals(67, buffer.get(2)); outConsumer.clear(); buffer.insert(outConsumer::add, " foo", 10); //buffer.print(outConsumer::add, 120); Assert.assertEquals(" foo", Parser.fromCodePoints(outConsumer.get(0))); }
Example #27
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testFormatDisplayCompactListTerminalString() { TerminalString terminalLong = new TerminalString("This string is too long to terminal width"); TerminalString terminalShort1 = new TerminalString("str1"); TerminalString terminalShort2 = new TerminalString("str2"); TerminalString terminalShort3 = new TerminalString("str3"); TerminalString terminalShort4 = new TerminalString("str4"); TerminalString terminalLonger1 = new TerminalString("longer1"); TerminalString terminalLonger2 = new TerminalString("longer2"); TerminalString terminalLonger3 = new TerminalString("longer3"); assertEquals( terminalLong.toString() + Config.getLineSeparator(), Parser.formatDisplayCompactListTerminalString(Collections.singletonList(terminalLong), 10)); assertEquals( terminalShort1.toString() + " " + terminalShort2.toString() + Config.getLineSeparator(), Parser.formatDisplayCompactListTerminalString(Arrays.asList(terminalShort1, terminalShort2), 20)); assertEquals( terminalShort1.toString() + Config.getLineSeparator() + terminalShort2.toString() + Config.getLineSeparator(), Parser.formatDisplayCompactListTerminalString(Arrays.asList(terminalShort1, terminalShort2), 10)); assertEquals( terminalShort1.toString() + " " + terminalShort3.toString() + Config.getLineSeparator() + terminalShort2.toString() + Config.getLineSeparator(), Parser.formatDisplayCompactListTerminalString(Arrays.asList(terminalShort1, terminalShort2, terminalShort3), 15)); assertEquals( terminalShort1.toString() + " " + terminalShort3.toString() + Config.getLineSeparator() + terminalShort2.toString() + " " + terminalShort4.toString() + Config.getLineSeparator(), Parser.formatDisplayCompactListTerminalString(Arrays.asList(terminalShort1, terminalShort2, terminalShort3, terminalShort4), 15)); assertEquals( terminalLonger1.toString() + " " + terminalShort1.toString() + Config.getLineSeparator() + terminalLonger2.toString() + Config.getLineSeparator() + terminalLonger3.toString() + Config.getLineSeparator(), Parser.formatDisplayCompactListTerminalString( Arrays.asList(terminalLonger1, terminalLonger2, terminalLonger3, terminalShort1), 15)); }
Example #28
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testDoesStringContainQuote() { assertFalse(Parser.doesStringContainOpenQuote("foo bar is bar")); assertFalse(Parser.doesStringContainOpenQuote("\"foo bar is bar is foo is bar\"")); assertFalse(Parser.doesStringContainOpenQuote("\"foo bar \"is bar is \"foo is bar\"")); assertFalse(Parser.doesStringContainOpenQuote("\'foo bar \"is bar is \"foo is bar\'")); assertTrue(Parser.doesStringContainOpenQuote("\"foo bar is bar is \"foo is bar\"")); assertFalse(Parser.doesStringContainOpenQuote("\"foo bar is bar is \\\"foo is bar\"")); assertTrue(Parser.doesStringContainOpenQuote("\"foo bar is bar is \\\"foo is bar\'")); }
Example #29
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testFindNumberOfSpaces() { assertEquals(4, Parser.findNumberOfSpacesInWord("this is a word ")); assertEquals(4, Parser.findNumberOfSpacesInWord("this is a word !")); assertEquals(5, Parser.findNumberOfSpacesInWord(" this is a word !")); assertEquals(4, Parser.findNumberOfSpacesInWord(" this is a\\ word !")); }
Example #30
Source File: ParserTest.java From aesh-readline with Apache License 2.0 | 5 votes |
@Test public void testIsTrimmedArrayEmpty() { int[] input = {}; assertTrue(Parser.isTrimmedArrayEmpty(input)); input = new int[]{32,32}; assertTrue(Parser.isTrimmedArrayEmpty(input)); input = new int[]{32,32,68}; assertFalse(Parser.isTrimmedArrayEmpty(input)); input = new int[]{68,32,32}; assertFalse(Parser.isTrimmedArrayEmpty(input)); input = new int[]{70}; assertFalse(Parser.isTrimmedArrayEmpty(input)); }