@Test void testErrorAfterPosition() throws RedPenException { String sampleText = "きょうは Cokeを飲みたい。"; Configuration configuration = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("SpaceBetweenAlphabeticalWord")) .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("SpaceBetweenAlphabeticalWord", errors.get(0).getValidatorName()); assertEquals(new LineOffset(1, 9), errors.get(0).getStartPosition().get()); assertEquals(new LineOffset(1, 10), errors.get(0).getEndPosition().get()); }
@Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } SpaceBetweenAlphabeticalWordValidator(); }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } SpaceBetweenAlphabeticalWordValidator(); @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence); }
SpaceBetweenAlphabeticalWordValidator extends Validator { @Override public void validate(Sentence sentence) { if (!getBoolean("forbidden")) { char prevCharacter = ' '; int idx = 0; for (char character : sentence.getContent().toCharArray()) { if (notHasWhiteSpaceBeforeLeftParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("Before", sentence, idx, idx + 1); } else if (notHasWhiteSpaceAfterRightParenthesis(prevCharacter, character)) { addLocalizedErrorWithPosition("After", sentence, idx, idx + 1); } prevCharacter = character; idx++; } } else { final Matcher m = pat.matcher(sentence.getContent()); while (m.find()) { final String word = m.group(1); if (!word.contains(" ")) { addLocalizedError("Forbidden", sentence, word); } } } } SpaceBetweenAlphabeticalWordValidator(); @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence);  }