@Test void testErrorPosition() throws RedPenException { String sampleText = "Hello You know."; Configuration configuration = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("InvalidExpression")) .build(); DocumentParser parser = DocumentParser.MARKDOWN; List<Document> documents = new ArrayList<>(); Document document = parser.parse(sampleText, new SentenceExtractor(configuration.getSymbolTable()), configuration.getTokenizer()); documents.add(document); RedPen redPen = new RedPen(configuration); List<ValidationError> errors = redPen.validate(documents).get(documents.get(0)); assertEquals(1, errors.size()); assertEquals("InvalidExpression", errors.get(0).getValidatorName()); assertEquals(new LineOffset(1, 6), errors.get(0).getStartPosition().get()); assertEquals(new LineOffset(1, 14), errors.get(0).getEndPosition().get()); }
@Override public void validate(Sentence sentence) { streamDictionary().forEach(value -> { int startPosition = sentence.getContent().indexOf(value); if (startPosition != -1) { addLocalizedErrorWithPosition(sentence, startPosition, startPosition + value.length(), value); } }); }
InvalidExpressionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { streamDictionary().forEach(value -> { int startPosition = sentence.getContent().indexOf(value); if (startPosition != -1) { addLocalizedErrorWithPosition(sentence, startPosition, startPosition + value.length(), value); } }); } }
InvalidExpressionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { streamDictionary().forEach(value -> { int startPosition = sentence.getContent().indexOf(value); if (startPosition != -1) { addLocalizedErrorWithPosition(sentence, startPosition, startPosition + value.length(), value); } }); } InvalidExpressionValidator(); }
InvalidExpressionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { streamDictionary().forEach(value -> { int startPosition = sentence.getContent().indexOf(value); if (startPosition != -1) { addLocalizedErrorWithPosition(sentence, startPosition, startPosition + value.length(), value); } }); } InvalidExpressionValidator(); @Override void validate(Sentence sentence); }
InvalidExpressionValidator extends DictionaryValidator { @Override public void validate(Sentence sentence) { streamDictionary().forEach(value -> { int startPosition = sentence.getContent().indexOf(value); if (startPosition != -1) { addLocalizedErrorWithPosition(sentence, startPosition, startPosition + value.length(), value); } }); } InvalidExpressionValidator(); @Override void validate(Sentence sentence);  }