public PipeLineFactory getLast() { if (next != null) { return next.getLast(); } return this; } }
@Override public Language getImplementation() { return ScriptRepl.getInstance().getLanguage(); } }
public static Token parse(CharSequence s) { return parse(s, 0); }
public void testPipe() throws CommandException { PipeLineFactory e = Token.parse("a|b").createFactory(); assertEquals("a", e.getLine()); assertEquals("b", e.getNext().getLine()); assertNull(e.getNext().getNext()); }
public CommandInvoker<?, ?> resolve(String s) throws CommandException { CRaSHSession session = (CRaSHSession)getSession(); Token token2 = Token.parse(s); try { PipeLineFactory factory = token2.createFactory(); return factory.create(session); } catch (CommandNotFoundException e) { throw new CommandException(ErrorKind.SYNTAX, e.getMessage(), e); } }
private void assertSyntaxException(String s) { try { Token.parse(s).createFactory(); fail(); } catch (CommandException e) { assertEquals(ErrorKind.SYNTAX, e.getErrorKind()); } } }
public void testBlank() throws CommandException { assertNull(Token.parse("").createFactory()); assertNull(Token.parse(" ").createFactory()); }
public PipeLineFactory createFactory() throws CommandException { if (next != null) { PipeLineFactory nextFactory = next.createFactory(); if (nextFactory != null) { return new PipeLineFactory(value, nextFactory); } else { throw new CommandException(ErrorKind.SYNTAX, ""); } } else { return Utils.notBlank(value) ? new PipeLineFactory(value, null) : null; } }
public void testComposite() { TestTokenizer tokenizer = new TestTokenizer("a | b c"); tokenizer.assertCommand("a "); tokenizer.assertCommand(" b c"); tokenizer.assertEOF(); }
public static Token parse(final CharSequence s, final int index) { Character lastQuote = null; int pos = index; while (pos < s.length()) { char c = s.charAt(pos); if (lastQuote == null) { if (c == '|') { break; } else if (c == '"' || c == '\'') { lastQuote = c; } } else { if (lastQuote == c) { lastQuote = null; } } pos++; } Token next = pos < s.length() ? parse(s, pos + 1) : null; return new Token(s.subSequence(index, pos).toString(), next); } }
public void testException() { lifeCycle.bindScript("test", "fail this_is_an_exception"); Throwable t = assertError("test", ErrorKind.EVALUATION); assertEquals(Exception.class, t.getClass()); assertEquals("this_is_an_exception", t.getMessage()); }
public Token getLast() { return next != null ? next.getLast() : this; }
public void testExecute() { lifeCycle.bindScript("test", "echo abc\n" + "echo def"); assertEquals("abcdef", assertOk("test")); }
public void testSyntaxException() { assertSyntaxException("|"); assertSyntaxException("a|"); assertSyntaxException("|b"); }
public void testCommand() throws CommandException { PipeLineFactory e = Token.parse("a").createFactory(); assertEquals("a", e.getLine()); assertNull(e.getNext()); }
public void testEmpty() { new TestTokenizer("").assertCommand("").assertEOF(); new TestTokenizer(" ").assertCommand(" ").assertEOF(); }
private TestTokenizer(CharSequence s) throws NullPointerException { current = Token.parse(s); }
public void testError() { lifeCycle.bindScript("test", "fail -t ERROR this_is_an_error"); Throwable t = assertError("test", ErrorKind.INTERNAL); assertEquals(Error.class, t.getClass()); assertEquals("this_is_an_error", t.getMessage()); } }
public void testPipe() { new TestTokenizer("|").assertCommand("").assertCommand("").assertEOF(); }
public void testCommand() { new TestTokenizer("a").assertCommand("a").assertEOF(); new TestTokenizer("' '").assertCommand("' '").assertEOF(); new TestTokenizer("\" \"").assertCommand("\" \"").assertEOF(); new TestTokenizer("'\"'").assertCommand("'\"'").assertEOF(); new TestTokenizer("\"'\"").assertCommand("\"'\"").assertEOF(); new TestTokenizer(" ' ' ").assertCommand(" ' ' ").assertEOF(); // Test escape special char in simple quote new TestTokenizer("'+'").assertCommand("'+'").assertEOF(); new TestTokenizer("'|'").assertCommand("'|'").assertEOF(); // Test escape special char in double quote new TestTokenizer("\"+\"").assertCommand("\"+\"").assertEOF(); new TestTokenizer("\"|\"").assertCommand("\"|\"").assertEOF(); // Non terminated quotes new TestTokenizer("\"").assertCommand("\"").assertEOF(); new TestTokenizer("'").assertCommand("'").assertEOF(); // new TestTokenizer("a b").assertCommand("a b").assertEOF(); } public void testPipe() {