Skip to content

Commit

Permalink
Added ability to parse with new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jan 30, 2024
1 parent 24dee5d commit 6e3bd10
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/xembly/Verbs.java
Expand Up @@ -106,12 +106,13 @@ final class Verbs {
* @return Directives from text
*/
public Iterable<Directive> directives() {
if (!this.text.trim().isEmpty()) {
final String trimmed = this.text.trim();
if (!trimmed.isEmpty()) {
final String semicolon = ";";
final StringBuilder builder = new StringBuilder();
Optional<Callback<Directive>> command;
try {
for (final String part : this.text.split(semicolon)) {
for (final String part : trimmed.split(semicolon)) {
if (builder.length() == 0) {
builder.append(Verbs.ltrim(part));
} else {
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/xembly/VerbsTest.java
Expand Up @@ -52,4 +52,22 @@ void throwsOnBrokenSyntax() {
Matchers.containsString("near [broken;]")
);
}

@Test
void worksWithSpacesAfterLastCommand() {
Assertions.assertDoesNotThrow(
() -> new Xembler(
new Directives("ADD 'o'; ATTR 'base', 'int'; ")
).xml()
);
}

@Test
void worksWithNewLines() {
Assertions.assertDoesNotThrow(
() -> new Xembler(
new Directives("\n\nADD 'o';\nATTR 'base','int';\n\n")
).xml()
);
}
}
1 change: 0 additions & 1 deletion src/test/java/org/xembly/prof/DirectivesProfTest.java
Expand Up @@ -55,5 +55,4 @@ void parsesLongProgram() {
final Directives dirs = new Directives(program.toString());
MatcherAssert.assertThat(dirs, Matchers.notNullValue());
}

}
1 change: 0 additions & 1 deletion src/test/java/org/xembly/prof/XemblerProfTest.java
Expand Up @@ -65,5 +65,4 @@ void modifiesDom() throws Exception {
XhtmlMatchers.hasXPath("/root/node[.='49999']")
);
}

}

0 comments on commit 6e3bd10

Please sign in to comment.