@Test
 public void testWithSectionWithoutHeader() {
   Section section = new Section(0);
   Paragraph paragraph = new Paragraph();
   paragraph.appendSentence("it like a piece of a cake.", 0);
   section.appendParagraph(paragraph);
   List<ValidationError> errors = new ArrayList<>();
   validator.setErrorList(errors);
   validator.validate(section);
   assertEquals(1, errors.size());
 }
示例#2
0
文件: RedPen.java 项目: so-c/redpen
  private void runSentenceValidators(
      List<Document> documents, Map<Document, List<ValidationError>> docErrorsMap) {
    // run Sentence PreProcessors to documents
    for (Document document : documents) {
      for (Section section : document) {
        // apply Sentence PreProcessors to section
        // apply paragraphs
        for (Paragraph paragraph : section.getParagraphs()) {
          validators.forEach(e -> paragraph.getSentences().forEach(e::preValidate));
        }
        // apply to section header
        validators.forEach(e -> section.getHeaderContents().forEach(e::preValidate));

        // apply to lists
        for (ListBlock listBlock : section.getListBlocks()) {
          for (ListElement listElement : listBlock.getListElements()) {
            validators.forEach(e -> listElement.getSentences().forEach(e::preValidate));
          }
        }
      }
    }
    // run Sentence Validators to documents
    for (Document document : documents) {
      for (Section section : document) {
        List<ValidationError> errors = docErrorsMap.get(document);

        // apply SentenceValidations to section
        // apply paragraphs
        for (Paragraph paragraph : section.getParagraphs()) {
          validators.forEach(
              e -> {
                e.setErrorList(errors);
                paragraph.getSentences().forEach(sentence -> e.validate(sentence));
              });
        }
        // apply to section header
        validators.forEach(
            e -> {
              e.setErrorList(errors);
              section.getHeaderContents().forEach(sentence -> e.validate(sentence));
            });
        // apply to lists
        for (ListBlock listBlock : section.getListBlocks()) {
          for (ListElement listElement : listBlock.getListElements()) {
            validators.forEach(
                e -> {
                  e.setErrorList(errors);
                  listElement.getSentences().forEach(sentence -> e.validate(sentence));
                });
          }
        }
      }
    }
  }