Skip to content

Commit

Permalink
Allowing non-top headers to start document
Browse files Browse the repository at this point in the history
Changes:
- redpen-core/src/main/java/cc/redpen/validator/section/GappedSectionValidator.java: Latching on the first header level.
- redpen-core/src/test/java/cc/redpen/validator/section/GappedSectionValidatorTest.java: Added test case.
  • Loading branch information
alterakey committed Jun 8, 2016
1 parent 44f7aa2 commit 8999e2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ public void validate(Document document) {
int seen = 0;
for (Section s: document) {
final int current = s.getLevel();
if (current <= seen) {
seen = current;
} else {
if (current == seen + 1) {
if (seen > 0) {
if (current <= seen) {
seen = current;
} else {
addLocalizedError(s.getJoinedHeaderContents(), current, seen + 1);
if (current == seen + 1) {
seen = current;
} else {
addLocalizedError(s.getJoinedHeaderContents(), s.getJoinedHeaderContents().getContent(), current, seen + 1);
}
}
} else {
seen = current;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,22 @@ public void testValid() {

assertEquals(0, errors.size());
}

@Test
public void testFailureCase() {
Document document =
Document.builder()
.addSection(2)
.addSectionHeader("Section 1.1")
.addSection(3)
.addSectionHeader("Section 1.1.1")
.build();

List<ValidationError> errors = new ArrayList<>();
validator.setErrorList(errors);
validator.validate(document);

assertEquals(0, errors.size());
}

}

0 comments on commit 8999e2c

Please sign in to comment.