org.jline.reader.ParsedLine Java Examples

The following examples show how to use org.jline.reader.ParsedLine. 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: SqlCompleter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
	String statement = line.line();

	// remove ';' at the end
	if (statement.endsWith(";")) {
		statement = statement.substring(0, statement.length() - 1);
	}

	// handle SQL client specific commands
	final String statementNormalized = statement.toUpperCase().trim();
	for (String commandHint : COMMAND_HINTS) {
		if (commandHint.startsWith(statementNormalized) && line.cursor() < commandHint.length()) {
			candidates.add(createCandidate(commandHint));
		}
	}

	// fallback to Table API hinting
	try {
		executor.completeStatement(context, statement, line.cursor())
			.forEach(hint -> candidates.add(createCandidate(hint)));
	} catch (SqlExecutionException e) {
		LOG.debug("Could not complete statement at " + line.cursor() + ":" + statement, e);
	}
}
 
Example #2
Source File: ConnectionCompleter.java    From sqlline with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override public void complete(
    LineReader lineReader, ParsedLine parsedLine, List<Candidate> list) {
  DatabaseConnections databaseConnections = sqlLine.getDatabaseConnections();
  if (databaseConnections.size() == 0) {
    return;
  }
  int i = 0;
  for (DatabaseConnection dbConnection: databaseConnections) {
    String strValue = String.valueOf(i);
    list.add(new SqlLineCommandCompleter.SqlLineCandidate(
        sqlLine, strValue, strValue, sqlLine.loc("connections"),
        dbConnection.getNickname() == null
            ? dbConnection.getUrl() : dbConnection.getNickname(),
        null, null, true));
    i++;
  }
}
 
Example #3
Source File: JLineCompleter.java    From jsqsh with Apache License 2.0 6 votes vote down vote up
@Override
public void complete(LineReader lineReader, ParsedLine parsedLine, List<Candidate> list) {

    Session session = ctx.getCurrentSession();
    ConnectionContext conn = session.getConnectionContext();
    if (conn != null) {
        
        Completer completer = conn.getTabCompleter(session,
            parsedLine.line(), parsedLine.cursor(), parsedLine.word());
        String name = completer.next();
        while (name != null) {
            
            list.add(new Candidate(name));
            name = completer.next();
        }
    }
}
 
Example #4
Source File: CommandCompleter.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Override
public void complete(LineReader lineReader, ParsedLine parsedLine, List<Candidate> candidates) {
  String buffer = parsedLine.word().trim();

  if (Strings.isNullOrEmpty(buffer)) {
    candidates.addAll(_commandStrs.stream().map(Candidate::new).collect(Collectors.toList()));
  } else {
    for (String match : _commandStrs.tailSet(buffer)) {
      if (!match.startsWith(buffer)) {
        break;
      }

      candidates.add(new Candidate(match));
    }
  }

  // if the match was unique and the complete command was specified, print the command usage
  if (candidates.size() == 1 && candidates.get(0).displ().equals(buffer)) {
    candidates.clear();
    candidates.add(
        new Candidate(
            " " + Command.getUsageMap().get(Command.getNameMap().get(buffer)).getUsage()));
  }
}
 
Example #5
Source File: Shell.java    From joinery with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void complete(final LineReader reader,
        final ParsedLine line, final List<Candidate> candidates) {
    final String expr = line.word().substring(0, line.wordCursor());
    final int dot = expr.lastIndexOf('.') + 1;
    if (dot > 1) {
        final String sym = expr.substring(0, dot - 1);
        final Object value = get(sym, Repl.this);
        if (value instanceof ScriptableObject) {
            ScriptableObject so = (ScriptableObject)value;
            final Object[] ids = so.getAllIds();
            for (final Object id : ids) {
                final String candidate = sym + "." + id;
                candidates.add(new Candidate(
                        candidate,
                        candidate,
                        null,
                        null,
                        null,
                        null,
                        false
                    ));
            }
        }
    }
}
 
Example #6
Source File: SqlMultiLineParser.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public ParsedLine parse(String line, int cursor, ParseContext context) {
	if (!line.trim().endsWith(EOF_CHARACTER) && context != ParseContext.COMPLETE) {
		throw new EOFError(
			-1,
			-1,
			"New line without EOF character.",
			NEW_LINE_PROMPT);
	}
	final ArgumentList parsedLine = (ArgumentList) super.parse(line, cursor, context);
	return new SqlArgumentList(
		parsedLine.line(),
		parsedLine.words(),
		parsedLine.wordIndex(),
		parsedLine.wordCursor(),
		parsedLine.cursor(),
		null,
		parsedLine.rawWordCursor(),
		parsedLine.rawWordLength());
}
 
Example #7
Source File: SqlCompleter.java    From flink with Apache License 2.0 6 votes vote down vote up
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
	String statement = line.line();

	// remove ';' at the end
	if (statement.endsWith(";")) {
		statement = statement.substring(0, statement.length() - 1);
	}

	// handle SQL client specific commands
	final String statementNormalized = statement.toUpperCase().trim();
	for (String commandHint : COMMAND_HINTS) {
		if (commandHint.startsWith(statementNormalized) && line.cursor() < commandHint.length()) {
			candidates.add(createCandidate(getCompletionHint(statementNormalized, commandHint)));
		}
	}

	// fallback to Table API hinting
	try {
		executor.completeStatement(sessionId, statement, line.cursor())
			.forEach(hint -> candidates.add(createCandidate(hint)));
	} catch (SqlExecutionException e) {
		LOG.debug("Could not complete statement at " + line.cursor() + ":" + statement, e);
	}
}
 
Example #8
Source File: ArchiveNameCompleter.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
    if (line.words().size() == 2) {
        String cmd = line.words().get(0);
        String word = line.word();

        if (COMMANDS.contains(cmd)) {
            // group is already specified; only provide artifacts now
            if (word.contains(":")) {
                String group = word.split(":")[0] + ":";
                archivesFromCache().stream().filter(a -> a.startsWith(group))
                        .collect(Collectors.toSet())
                        .forEach(a -> candidates.add(new Candidate(a)));
            }
            // sill completing group
            else {
                archivesFromCache().stream().map(a -> a.split(":")[0])
                        .collect(Collectors.toSet()).forEach(a -> candidates
                                .add(new Candidate(a + ":", a, null, null, null, null, false)));
            }
        }
    }
}
 
Example #9
Source File: PicocliJLineCompleter.java    From picocli with Apache License 2.0 6 votes vote down vote up
/**
 * Populates <i>candidates</i> with a list of possible completions for the <i>command line</i>.
 *
 * The list of candidates will be sorted and filtered by the LineReader, so that
 * the list of candidates displayed to the user will usually be smaller than
 * the list given by the completer.  Thus it is not necessary for the completer
 * to do any matching based on the current buffer.  On the contrary, in order
 * for the typo matcher to work, all possible candidates for the word being
 * completed should be returned.
 *
 * @param reader        The line reader
 * @param line          The parsed command line
 * @param candidates    The {@link List} of candidates to populate
 */
//@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
   // let picocli generate completion candidates for the token where the cursor is at
    String[] words = new String[line.words().size()];
    words = line.words().toArray(words);
    List<CharSequence> cs = new ArrayList<CharSequence>();
    AutoComplete.complete(spec,
            words,
            line.wordIndex(),
            0,
            line.cursor(),
            cs);
    for(CharSequence c: cs){
        candidates.add(new Candidate((String)c)); 
    }
}
 
Example #10
Source File: InteractiveMode.java    From rdflint with MIT License 6 votes vote down vote up
/**
 * Overrided parse method. Need double return to perform command.
 */
@Override
public ParsedLine parse(final String line, final int cursor, ParseContext context) {
  ParsedLine pl = super.parse(line, cursor, context);

  if (context != ParseContext.ACCEPT_LINE) {
    return pl;
  }
  if (line.length() == 0) {
    throw new EOFError(-1, -1, "No command", "command");
  }
  if (!line.endsWith("\n") && line.trim().charAt(0) != ':') {
    throw new EOFError(-1, -1, "Single new line", "double newline");
  }
  return pl;
}
 
Example #11
Source File: InputParser.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public ParsedLine parse(String line, int cursor, ParseContext context)
        throws SyntaxError
{
    String command = whitespace().trimFrom(line);
    if (command.isEmpty() || SPECIAL.contains(command.toLowerCase(ENGLISH))) {
        return new DefaultParser().parse(line, cursor, context);
    }

    StatementSplitter splitter = new StatementSplitter(line, STATEMENT_DELIMITERS);
    if (splitter.getCompleteStatements().isEmpty()) {
        throw new EOFError(-1, -1, null);
    }

    return new DefaultParser().parse(line, cursor, context);
}
 
Example #12
Source File: SqlMultiLineParser.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public ParsedLine parse(String line, int cursor, ParseContext context) {
	if (!line.trim().endsWith(EOF_CHARACTER) && context != ParseContext.COMPLETE) {
		throw new EOFError(
			-1,
			-1,
			"New line without EOF character.",
			NEW_LINE_PROMPT);
	}
	final ArgumentList parsedLine = (ArgumentList) super.parse(line, cursor, context);
	return new SqlArgumentList(
		parsedLine.line(),
		parsedLine.words(),
		parsedLine.wordIndex(),
		parsedLine.wordCursor(),
		parsedLine.cursor(),
		null,
		parsedLine.rawWordCursor(),
		parsedLine.rawWordLength());
}
 
Example #13
Source File: SqlCompleter.java    From flink with Apache License 2.0 6 votes vote down vote up
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
	String statement = line.line();

	// remove ';' at the end
	if (statement.endsWith(";")) {
		statement = statement.substring(0, statement.length() - 1);
	}

	// handle SQL client specific commands
	final String statementNormalized = statement.toUpperCase().trim();
	for (String commandHint : COMMAND_HINTS) {
		if (commandHint.startsWith(statementNormalized) && line.cursor() < commandHint.length()) {
			candidates.add(createCandidate(commandHint));
		}
	}

	// fallback to Table API hinting
	try {
		executor.completeStatement(context, statement, line.cursor())
			.forEach(hint -> candidates.add(createCandidate(hint)));
	} catch (SqlExecutionException e) {
		LOG.debug("Could not complete statement at " + line.cursor() + ":" + statement, e);
	}
}
 
Example #14
Source File: SqlMultiLineParser.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public ParsedLine parse(String line, int cursor, ParseContext context) {
	if (!line.trim().endsWith(EOF_CHARACTER) && context != ParseContext.COMPLETE) {
		throw new EOFError(
			-1,
			-1,
			"New line without EOF character.",
			NEW_LINE_PROMPT);
	}
	final ArgumentList parsedLine = (ArgumentList) super.parse(line, cursor, context);
	return new SqlArgumentList(
		parsedLine.line(),
		parsedLine.words(),
		parsedLine.wordIndex(),
		parsedLine.wordCursor(),
		parsedLine.cursor(),
		null,
		parsedLine.rawWordCursor(),
		parsedLine.rawWordLength());
}
 
Example #15
Source File: DemoCommandTest.java    From ssh-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void prepare() {
    cmd = new DemoCommand(new SshShellHelper());
    terminal = mock(Terminal.class);
    when(terminal.getSize()).thenReturn(size);
    PrintWriter writer = mock(PrintWriter.class);
    lr = mock(LineReader.class);
    ParsedLine line = mock(ParsedLine.class);
    when(line.line()).thenReturn("y");
    when(lr.getParsedLine()).thenReturn(line);
    when(lr.getTerminal()).thenReturn(terminal);
    when(terminal.writer()).thenReturn(writer);
    reader = mock(NonBlockingReader.class);
    when(terminal.reader()).thenReturn(reader);
    when(terminal.getType()).thenReturn("osx");
    auth = new SshAuthentication("user", "user", null, null, null);
    SshContext ctx = new SshContext(new SshShellRunnable(new SshShellProperties(), null, null, null, null, null,
            null, null, null, null, null, null, null, null), terminal, lr, auth);
    SshShellCommandFactory.SSH_THREAD_CONTEXT.set(ctx);
}
 
Example #16
Source File: DynamicCompleter.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine parsedLine, List<Candidate> candidates) {
	List<String> commands = LineUtils.parse(parsedLine.line());

	// Primary level frist arguments
	if (commands.isEmpty()) {
		new StringsCompleter(registry.getHelpOptions().keySet()).complete(reader, parsedLine, candidates);
	}
	// Secondary primary arguments
	else {
		HelpOptions options = registry.getHelpOptions().get(commands.get(0));
		// Continue before completion
		if (completingCompleted(commands, options)) {
			List<String> candes = new ArrayList<>();
			for (Option opt : options.getOptions()) {
				candes.add(GNU_CMD_SHORT + opt.getOpt());
				candes.add(GNU_CMD_LONG + opt.getLongOpt());
			}
			new StringsCompleter(candes).complete(reader, parsedLine, candidates);
		}
	}

}
 
Example #17
Source File: SpecialCommandCompleter.java    From Arend with Apache License 2.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
  int cursor = line.cursor();
  var command = CommandHandler.splitCommand(line.line());
  if (command.proj1 != null && cursor > command.proj1.length() && CommandHandler.INSTANCE
    .determineEntries(command.proj1)
    .map(Map.Entry::getValue)
    .anyMatch(commandClass::isInstance)
  ) completer.complete(reader, line, candidates);
}
 
Example #18
Source File: JLineParser.java    From jsqsh with Apache License 2.0 5 votes vote down vote up
@Override
public ParsedLine parse(String s, int i, ParseContext parseContext) throws SyntaxError {

    switch (parseContext) {

        case ACCEPT_LINE:
            if (! context.getCurrentSession().isInputComplete(s, i))
                throw INPUT_NOT_COMPLETE;
            // FALL-THROUGH
        default:
            return super.parse(s, i, parseContext);
    }
}
 
Example #19
Source File: CliClientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void verifySqlCompletion(String statement, int position, List<String> expectedHints, List<String> notExpectedHints) throws IOException {
	final SessionContext context = new SessionContext("test-session", new Environment());
	final MockExecutor mockExecutor = new MockExecutor();

	final SqlCompleter completer = new SqlCompleter(context, mockExecutor);
	final SqlMultiLineParser parser = new SqlMultiLineParser();

	try (Terminal terminal = TerminalUtils.createDummyTerminal()) {
		final LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();

		final ParsedLine parsedLine = parser.parse(statement, position, Parser.ParseContext.COMPLETE);
		final List<Candidate> candidates = new ArrayList<>();
		final List<String> results = new ArrayList<>();
		completer.complete(reader, parsedLine, candidates);
		candidates.forEach(item -> results.add(item.value()));

		assertTrue(results.containsAll(expectedHints));

		assertEquals(statement, mockExecutor.receivedStatement);
		assertEquals(context, mockExecutor.receivedContext);
		assertEquals(position, mockExecutor.receivedPosition);
		assertTrue(results.contains("HintA"));
		assertTrue(results.contains("Hint B"));

		results.retainAll(notExpectedHints);
		assertEquals(0, results.size());
	}
}
 
Example #20
Source File: CliClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void verifySqlCompletion(String statement, int position, List<String> expectedHints, List<String> notExpectedHints) throws IOException {
	final SessionContext context = new SessionContext("test-session", new Environment());
	final MockExecutor mockExecutor = new MockExecutor();
	String sessionId = mockExecutor.openSession(context);

	final SqlCompleter completer = new SqlCompleter(sessionId, mockExecutor);
	final SqlMultiLineParser parser = new SqlMultiLineParser();

	try (Terminal terminal = TerminalUtils.createDummyTerminal()) {
		final LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();

		final ParsedLine parsedLine = parser.parse(statement, position, Parser.ParseContext.COMPLETE);
		final List<Candidate> candidates = new ArrayList<>();
		final List<String> results = new ArrayList<>();
		completer.complete(reader, parsedLine, candidates);
		candidates.forEach(item -> results.add(item.value()));

		assertTrue(results.containsAll(expectedHints));

		assertEquals(statement, mockExecutor.receivedStatement);
		assertEquals(context, mockExecutor.receivedContext);
		assertEquals(position, mockExecutor.receivedPosition);
		assertTrue(results.contains("HintA"));
		assertTrue(results.contains("Hint B"));

		results.retainAll(notExpectedHints);
		assertEquals(0, results.size());
	}
}
 
Example #21
Source File: CliClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void verifySqlCompletion(String statement, int position, List<String> expectedHints, List<String> notExpectedHints) throws IOException {
	final SessionContext context = new SessionContext("test-session", new Environment());
	final MockExecutor mockExecutor = new MockExecutor();

	final SqlCompleter completer = new SqlCompleter(context, mockExecutor);
	final SqlMultiLineParser parser = new SqlMultiLineParser();

	try (Terminal terminal = TerminalUtils.createDummyTerminal()) {
		final LineReader reader = LineReaderBuilder.builder().terminal(terminal).build();

		final ParsedLine parsedLine = parser.parse(statement, position, Parser.ParseContext.COMPLETE);
		final List<Candidate> candidates = new ArrayList<>();
		final List<String> results = new ArrayList<>();
		completer.complete(reader, parsedLine, candidates);
		candidates.forEach(item -> results.add(item.value()));

		assertTrue(results.containsAll(expectedHints));

		assertEquals(statement, mockExecutor.receivedStatement);
		assertEquals(context, mockExecutor.receivedContext);
		assertEquals(position, mockExecutor.receivedPosition);
		assertTrue(results.contains("HintA"));
		assertTrue(results.contains("Hint B"));

		results.retainAll(notExpectedHints);
		assertEquals(0, results.size());
	}
}
 
Example #22
Source File: ScopeCompleter.java    From Arend with Apache License 2.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
  String command = CommandHandler.splitCommand(line.line()).proj1;
  if (command != null && CommandHandler.INSTANCE
    .determineEntries(command)
    .noneMatch(entry -> entry.getValue() instanceof ExpressionArgumentCommand)
  ) return;
  String word = line.word();
  var firstChar = word.isEmpty() ? '+' : word.charAt(0);
  if ("~!@#$%^&*-+=<>?/|:".indexOf(firstChar) > 0 || Character.isAlphabetic(firstChar)) {
    for (Referable referable : scopeSupplier.get())
      candidates.add(new Candidate(referable.getRefName()));
  }
}
 
Example #23
Source File: ImportCompleter.java    From Arend with Apache License 2.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
  if (line.words().size() < 1) return;
  if (!Objects.equals("\\import", line.words().get(0))) return;
  if (line.wordIndex() == 1)
    candidates.addAll(moduleSupplier.get().map(Candidate::new).collect(Collectors.toList()));
}
 
Example #24
Source File: CommandsCompleter.java    From Arend with Apache License 2.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
  if (line.cursor() >= 1 && ':' == line.line().charAt(0) && line.wordIndex() < 1) {
    for (var string : CommandHandler.INSTANCE.commandMap.keySet())
      candidates.add(new Candidate(":" + string));
  }
}
 
Example #25
Source File: KeywordCompleter.java    From Arend with Apache License 2.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
  if (!line.word().startsWith("\\")) return;
  String command = CommandHandler.splitCommand(line.line()).proj1;
  if (command != null && CommandHandler.INSTANCE
    .determineEntries(command)
    .noneMatch(entry -> entry.getValue() instanceof ExpressionArgumentCommand)
  ) return;
  for (var arendKeyword : arendKeywords) candidates.add(new Candidate("\\" + arendKeyword));
}
 
Example #26
Source File: FileAndDirectoryNameCompleter.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine commandLine, List<Candidate> candidates) {
    if (commandLine.words().size() > 1) {
        String word = commandLine.words().get(commandLine.words().size() - 2);
        if ("-C".equals(word) || "--change-dir".equals(word)) {
            super.complete(reader, commandLine, candidates);
        }
        else if (commandLine.line().startsWith(Constants.SHELL_ESCAPE)) {
            super.complete(reader, commandLine, candidates);
        }
    }
}
 
Example #27
Source File: AbstractCommandTest.java    From ssh-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
protected void setCtx(String response) throws Exception {
    LineReader lr = mock(LineReader.class);
    Terminal t = mock(Terminal.class);
    when(lr.getTerminal()).thenReturn(t);
    when(t.getSize()).thenReturn(new Size(300, 20));
    when(t.writer()).thenReturn(new PrintWriter("target/rh.tmp"));
    ParsedLine pl = mock(ParsedLine.class);
    when(pl.line()).thenReturn(response);
    when(lr.getParsedLine()).thenReturn(pl);
    SSH_THREAD_CONTEXT.set(new SshContext(null, t, lr, null));
}
 
Example #28
Source File: SqlLineOpts.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override public void complete(LineReader lineReader, ParsedLine parsedLine,
    List<Candidate> list) {
  try {
    new StringsCompleter(propertyNames())
        .complete(lineReader, parsedLine, list);
  } catch (Throwable ignored) {
  }
}
 
Example #29
Source File: PicocliCommands.java    From picocli with Apache License 2.0 5 votes vote down vote up
@Override
public void complete(LineReader reader, ParsedLine commandLine, List<Candidate> candidates) {
    assert commandLine != null;
    assert candidates != null;
    String word = commandLine.word();
    List<String> words = commandLine.words();
    CommandLine sub = findSubcommandLine(words, commandLine.wordIndex());
    if (sub == null) {
        return;
    }
    if (word.startsWith("-")) {
        String buffer = word.substring(0, commandLine.wordCursor());
        int eq = buffer.indexOf('=');
        for (OptionSpec option : sub.getCommandSpec().options()) {
            if (option.arity().max() == 0 && eq < 0) {
                addCandidates(candidates, Arrays.asList(option.names()));
            } else {
                if (eq > 0) {
                    String opt = buffer.substring(0, eq);
                    if (Arrays.asList(option.names()).contains(opt) && option.completionCandidates() != null) {
                        addCandidates(candidates, option.completionCandidates(), buffer.substring(0, eq + 1), "", true);
                    }
                } else {
                    addCandidates(candidates, Arrays.asList(option.names()), "", "=", false);
                }
            }
        }
    } else {
        addCandidates(candidates, sub.getSubcommands().keySet());
        for (CommandLine s : sub.getSubcommands().values()) {
            addCandidates(candidates, Arrays.asList(s.getCommandSpec().aliases()));
        }
    }
}
 
Example #30
Source File: InteractiveModeTest.java    From rdflint with MIT License 5 votes vote down vote up
@Test
public void interactiveCompleterPrefixUri() throws Exception {
  ParsedLine pl = mock(ParsedLine.class);
  when(pl.line()).thenReturn("PREFIX rdfs: ");
  when(pl.words()).thenReturn(Arrays.asList("PREFIX", "rdfs:", ""));
  when(pl.word()).thenReturn("");
  Model m = mock(Model.class);
  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
  when(m.getNsPrefixMap()).thenReturn(prefixMap);
  InteractiveMode.InteractiveCompleter completer = new InteractiveMode.InteractiveCompleter(m);
  List<Candidate> candidates = new LinkedList<>();
  completer.complete(null, pl, candidates);
  assertEquals("<http://www.w3.org/2000/01/rdf-schema#>", candidates.get(0).value());
}