Skip to content

Commit

Permalink
#83 Make sure files with trailing empty lines parse again (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
janssk1 authored and adamdougal committed Oct 8, 2019
1 parent 8fc9ee0 commit 27886e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/uk/sky/cqlmigrate/CqlFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void closedStatement(String original) {
}

private void check() {
if (!(State.IS_CLOSE_STMT.equals(curState) || State.INIT.equals(curState))) {
if (!(State.IS_CLOSE_STMT.equals(curState) || State.INIT.equals(curState) || (State.FIND_EOS.equals(curState) && curStmt.length() ==0))) {
throw new IllegalStateException("File had a non-terminated cql line");
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/uk/sky/cqlmigrate/CqlFileParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ public void shouldCopeWithSingleLineStatement() throws Exception {
.isEqualToIgnoringCase(expectedStatement)
);
}

@Test
public void trailingEmptyLinesAreAllowed() throws Exception {
Path cqlPath = getResourcePath("cql_whitespace/whitespace.cql");

List<String> cqlStatements = CqlFileParser.getCqlStatementsFrom(cqlPath);
assertThat(cqlStatements).hasSize(2);
}

}
9 changes: 9 additions & 0 deletions src/test/resources/cql_whitespace/whitespace.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE role_graphs(provider text, graphml text, PRIMARY KEY (provider));


INSERT into role_graphs (provider, graphml)
VALUES ('SKY', 'some text; some more text');
-- intentional blank lines below


-- comment

0 comments on commit 27886e7

Please sign in to comment.