Skip to content

Commit

Permalink
feat(#2764):added hash in xml files and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Jan 15, 2024
1 parent c940de5 commit 195f413
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
13 changes: 8 additions & 5 deletions eo-parser/src/main/java/org/eolang/parser/EoSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +71,7 @@ public EoSyntax(final String nme, final Input ipt) {
}

/**
* Compile it to XML and save.
* Compile it to XML.
*
* <p>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,
Expand All @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions eo-parser/src/main/java/org/eolang/parser/PhiSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
*
* @since 0.1
*/
@SuppressWarnings("PMD.TooManyMethods")
final class EoSyntaxTest {
@Test
void parsesSimpleCode() throws Exception {
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/PhiSyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
}

0 comments on commit 195f413

Please sign in to comment.