Skip to content

Commit

Permalink
feat(objectionary#627): fix all the rest unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Jul 7, 2024
1 parent d253a2f commit 3afaeb5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class XmlInstruction implements XmlBytecodeEntry {
/**
* Instruction node.
*/
@EqualsAndHashCode.Exclude
private final XmlNode node;

/**
Expand Down Expand Up @@ -96,6 +97,7 @@ public void writeTo(final BytecodeMethod method) {
* Instruction code.
* @return Code.
*/
@EqualsAndHashCode.Include
public int opcode() {
return new HexString(this.node.firstChild().text()).decodeAsInt();
}
Expand All @@ -104,6 +106,7 @@ public int opcode() {
* Instruction arguments.
* @return Arguments.
*/
@EqualsAndHashCode.Include
public List<XmlOperand> operands() {
return this.node
.children()
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/eolang/jeo/representation/xmir/XmlMaxs.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class XmlMaxs {
/**
* XML node.
*/
@EqualsAndHashCode.Exclude
private final XmlNode node;

/**
Expand All @@ -67,6 +68,7 @@ public XmlMaxs(final XmlNode node) {
*
* @return Stack size.
*/
@EqualsAndHashCode.Include
public int stack() {
return (int) new XmlOperand(
this.node.children().collect(Collectors.toList()).get(0)
Expand All @@ -78,6 +80,7 @@ public int stack() {
*
* @return Locals size.
*/
@EqualsAndHashCode.Include
public int locals() {
return (int) new XmlOperand(
this.node.children().collect(Collectors.toList()).get(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.jeo.representation.xmir;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.eolang.jeo.representation.DataType;
import org.eolang.jeo.representation.bytecode.BytecodeAnnotation;
Expand All @@ -32,11 +33,13 @@
* @since 0.3
*/
@ToString
@EqualsAndHashCode
public final class XmlOperand {

/**
* Raw XML node which represents an instruction operand.
*/
@EqualsAndHashCode.Exclude
private final XmlNode raw;

/**
Expand All @@ -51,6 +54,7 @@ public XmlOperand(final XmlNode node) {
* Convert XML operand to an object.
* @return Object.
*/
@EqualsAndHashCode.Include
public Object asObject() {
final Object result;
final String base = this.raw.attribute("base")
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/eolang/jeo/SameXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public final class SameXml extends TypeSafeMatcher<String> {
*/
private final String expected;

/**
* Constructor.
* @param xml Expected XML document.
*/
public SameXml(final XML xml) {
this(xml.toString());
}

/**
* Constructor.
* @param expected Expected XML document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ void returnsSingleAnnotation() throws ImpossibleModificationException {
),
XhtmlMatchers.hasXPath(
String.format(
"/o[@base='tuple' and @name='annotations']/o/o[@base='string' and @name='descriptor' and text()='%s']",
"/o[@base='tuple' and @name='annotations']/o/o[1][@base='string' and text()='%s']",
new HexData(annotation).value()
)
),
XhtmlMatchers.hasXPath(
String.format(
"/o[@base='tuple' and @name='annotations']/o/o[@base='bool' and @name='visible' and text()='%s']",
"/o[@base='tuple' and @name='annotations']/o/o[2][@base='bool' and text()='%s']",
new HexData(true).value()
)
)
Expand All @@ -90,8 +90,8 @@ void createsAnnotationWithProperty() throws ImpossibleModificationException {
new Xembler(annotation).xml(),
XhtmlMatchers.hasXPaths(
"/o[@base='annotation' and count(o) = 3]",
"/o[@base='annotation']/o[@name='descriptor' and text()='4C 6A 61 76 61 2F 6C 61 6E 67 2F 4F 76 65 72 72 69 64 65 3B']",
"/o[@base='annotation']/o[@name='visible' and text()='01']",
"/o[@base='annotation']/o[1][text()='4C 6A 61 76 61 2F 6C 61 6E 67 2F 4F 76 65 72 72 69 64 65 3B']",
"/o[@base='annotation']/o[2][text()='01']",
"/o[@base='annotation']/o[@base='annotation-property']"
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import org.eolang.jeo.SameXml;
import org.eolang.jeo.representation.ClassName;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -51,8 +52,8 @@ void retrievesTopClass() {
expected,
actual
),
actual,
Matchers.equalTo(expected)
actual.toXml().toString(),
new SameXml(expected.toXml())
);
}

Expand Down

0 comments on commit 3afaeb5

Please sign in to comment.