Skip to content

Commit

Permalink
#34 - Allow single DDL script with no trailing semi-colon to be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Oct 18, 2017
1 parent 277b11f commit a35e754
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/io/ebean/migration/ddl/DdlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public List<String> parse(StringReader reader) {
s = s.trim();
statements.nextLine(s);
}

statements.endOfContent();
return statements.statements;

} catch (IOException e) {
Expand Down Expand Up @@ -109,5 +109,16 @@ void nextLine(String line) {
}
}
}

/**
* Append trailing non-terminated content as an extra statement.
*/
void endOfContent() {
String remaining = sb.toString().trim();
if (remaining.length() > 0) {
statements.add(remaining);
sb = new StringBuilder();
}
}
}
}
14 changes: 14 additions & 0 deletions src/test/java/io/ebean/migration/ddl/DdlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,18 @@ public void parse_semiInContent_withTailingComments() throws Exception {
List<String> stmts = parser.parse(new StringReader("insert (';one'); -- aaa\ninsert (';two'); -- bbb"));
assertThat(stmts).containsExactly("insert (';one');", "insert (';two');");
}

@Test
public void parse_noTailingSemi() throws Exception {

List<String> stmts = parser.parse(new StringReader("one"));
assertThat(stmts).containsExactly("one");
}

@Test
public void parse_noTailingSemi_multiLine() throws Exception {

List<String> stmts = parser.parse(new StringReader("one\ntwo"));
assertThat(stmts).containsExactly("one two");
}
}

0 comments on commit a35e754

Please sign in to comment.