CliArgParser { public static String[] parse(final String input) { List<Token> tokens = lex(input); Parser parser = new Parser(); for (Token token : tokens) { parser.parseNext(token); } return parser.getArgs().toArray(new String[0]); } private  CliArgParser(); static String[] parse(final String input);  }
@Test public void testComplexLine() { final String[] parsed = CliArgParser .parse("some \"command with\" -q\"uot\\\" e\\\"d\" args\\ and\\\\ stuff"); assertArrayEquals("parsed is", new String[]{"some", "command with", "-quot\" e\"d", "args and\\", "stuff"}, parsed); }
@Test(expected = IllegalStateException.class) public void testUnterminatedEscape() { CliArgParser.parse("ends with a backslash\\"); }
@Test(expected = IllegalStateException.class) public void testUnterminatedQuote() { CliArgParser.parse("ends with a quote\""); }