JsonXpathSuggestionSource implements SuggestionSource<BasicSuggestion> { protected String lineForPosition(String text, int position) { int start = max(0, text.substring(0, min(text.length(), position)).lastIndexOf('\n')); int end = text.indexOf('\n', position); if (end == -1) { end = text.length(); } return text.substring(start, end).replaceAll("\r", "").replace("\n", ""); } JsonXpathSuggestionSource(); void setJsonPaths(Set<String> jsonPaths); void setJsonDoc(String jsonDoc); void setPropertyDoc(String propertyDoc); @Override List<BasicSuggestion> getSuggestions(SuggestionQuery query); static final String JSON; }
@Test(dataProvider = "lineForPosition") public void testLineForPosition(String text, int position, String expected) { final JsonXpathSuggestionSource jsonXpathSuggestionSource = new JsonXpathSuggestionSource(); final String line = jsonXpathSuggestionSource.lineForPosition(text, position); assertEquals(line, expected); }