diff --git a/src/main/java/org/xembly/Verbs.java b/src/main/java/org/xembly/Verbs.java index 650cdb1..2604ce9 100644 --- a/src/main/java/org/xembly/Verbs.java +++ b/src/main/java/org/xembly/Verbs.java @@ -106,12 +106,13 @@ final class Verbs { * @return Directives from text */ public Iterable directives() { - if (!this.text.trim().isEmpty()) { + final String trimmed = this.text.trim(); + if (!trimmed.isEmpty()) { final String semicolon = ";"; final StringBuilder builder = new StringBuilder(); Optional> 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 { diff --git a/src/test/java/org/xembly/VerbsTest.java b/src/test/java/org/xembly/VerbsTest.java index 9b9299b..94841af 100644 --- a/src/test/java/org/xembly/VerbsTest.java +++ b/src/test/java/org/xembly/VerbsTest.java @@ -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() + ); + } } diff --git a/src/test/java/org/xembly/prof/DirectivesProfTest.java b/src/test/java/org/xembly/prof/DirectivesProfTest.java index 1cf30ba..b52122d 100644 --- a/src/test/java/org/xembly/prof/DirectivesProfTest.java +++ b/src/test/java/org/xembly/prof/DirectivesProfTest.java @@ -55,5 +55,4 @@ void parsesLongProgram() { final Directives dirs = new Directives(program.toString()); MatcherAssert.assertThat(dirs, Matchers.notNullValue()); } - } diff --git a/src/test/java/org/xembly/prof/XemblerProfTest.java b/src/test/java/org/xembly/prof/XemblerProfTest.java index 3828c51..15503e0 100644 --- a/src/test/java/org/xembly/prof/XemblerProfTest.java +++ b/src/test/java/org/xembly/prof/XemblerProfTest.java @@ -65,5 +65,4 @@ void modifiesDom() throws Exception { XhtmlMatchers.hasXPath("/root/node[.='49999']") ); } - }