From 195f413d79dd9df843505312fac6a41d1e4acbea Mon Sep 17 00:00:00 2001 From: Alekseeva Yana Date: Mon, 15 Jan 2024 12:20:30 +0300 Subject: [PATCH] feat(#2764):added hash in xml files and added test --- .../src/main/java/org/eolang/parser/EoSyntax.java | 13 ++++++++----- .../src/main/java/org/eolang/parser/PhiSyntax.java | 11 +++++++---- .../test/java/org/eolang/parser/EoSyntaxTest.java | 13 +++++++++++++ .../test/java/org/eolang/parser/PhiSyntaxTest.java | 11 +++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java index 6200d5f8d1..825354b85f 100644 --- a/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/EoSyntax.java @@ -26,6 +26,7 @@ import com.jcabi.log.Logger; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; +import com.yegor256.xsline.Xsline; import java.io.IOException; import java.util.List; import org.antlr.v4.runtime.CommonTokenStream; @@ -70,7 +71,7 @@ public EoSyntax(final String nme, final Input ipt) { } /** - * Compile it to XML and save. + * Compile it to XML. * *

No exception will be thrown if the syntax is invalid. In any case, XMIR will * be generated and saved. Read it in order to find the errors, @@ -92,10 +93,12 @@ public XML parsed() throws IOException { parser.addErrorListener(spy); final XeEoListener xel = new XeEoListener(this.name); new ParseTreeWalker().walk(xel, parser.program()); - final XML dom = new XMLDocument( - new Xembler( - new Directives(xel).append(spy) - ).domQuietly() + final XML dom = new Xsline(new StHash()).pass( + new XMLDocument( + new Xembler( + new Directives(xel).append(spy) + ).domQuietly() + ) ); new Schema(dom).check(); if (spy.size() == 0) { diff --git a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java index c06438cdd0..79a7265632 100644 --- a/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java +++ b/eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java @@ -26,6 +26,7 @@ import com.jcabi.log.Logger; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; +import com.yegor256.xsline.Xsline; import java.io.IOException; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; @@ -84,10 +85,12 @@ public XML parsed() throws IOException { parser.removeErrorListeners(); parser.addErrorListener(spy); new ParseTreeWalker().walk(xel, parser.program()); - final XML dom = new XMLDocument( - new Xembler( - new Directives(xel).append(spy) - ).domQuietly() + final XML dom = new Xsline(new StHash()).pass( + new XMLDocument( + new Xembler( + new Directives(xel).append(spy) + ).domQuietly() + ) ); new Schema(dom).check(); if (spy.size() == 0) { diff --git a/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java b/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java index 6757a7fe3d..a86dacbff3 100644 --- a/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java @@ -47,6 +47,7 @@ * * @since 0.1 */ +@SuppressWarnings("PMD.TooManyMethods") final class EoSyntaxTest { @Test void parsesSimpleCode() throws Exception { @@ -175,6 +176,18 @@ void parsesDefinition() throws IOException { ); } + @Test + void containsHash() throws IOException { + MatcherAssert.assertThat( + "XML file should have 'hash' attribute on program node, but didn't", + new EoSyntax( + "test-it-5", + new InputOf("[v] > p\n f.write > @\n") + ).parsed(), + XhtmlMatchers.hasXPath("/program/@hash") + ); + } + @Test void parsesMethodCalls() throws IOException { MatcherAssert.assertThat( diff --git a/eo-parser/src/test/java/org/eolang/parser/PhiSyntaxTest.java b/eo-parser/src/test/java/org/eolang/parser/PhiSyntaxTest.java index 835c490614..4da109a7dd 100644 --- a/eo-parser/src/test/java/org/eolang/parser/PhiSyntaxTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/PhiSyntaxTest.java @@ -46,4 +46,15 @@ void addsError() throws IOException { ) ); } + + @Test + void containsHash() throws IOException { + MatcherAssert.assertThat( + "Result XML must contain hash", + new PhiSyntax( + "empty ↦ Φ.org.eolang.bytes" + ).parsed(), + XhtmlMatchers.hasXPath("/program/@hash") + ); + } }