From 6e3bd101d2e50568df59a7a2710f545fb8c6a0fe Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Tue, 30 Jan 2024 19:17:32 +0300 Subject: [PATCH] Added ability to parse with new lines --- src/main/java/org/xembly/Verbs.java | 5 +++-- src/test/java/org/xembly/VerbsTest.java | 18 ++++++++++++++++++ .../org/xembly/prof/DirectivesProfTest.java | 1 - .../java/org/xembly/prof/XemblerProfTest.java | 1 - 4 files changed, 21 insertions(+), 4 deletions(-) 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']") ); } - }