Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 15, 2024
2 parents 1669d16 + a582e18 commit 12bc873
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 44 deletions.
14 changes: 7 additions & 7 deletions eo-parser/src/main/java/org/eolang/parser/StUnhex.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public StUnhex() {
"float",
Double.toString(
StUnhex.buffer(
StUnhex.unspace(xml.xpath("text()").get(0))
StUnhex.unspace(xml.xpath("./o/text()").get(0))
).getDouble()
)
)
Expand All @@ -67,7 +67,7 @@ public StUnhex() {
"int",
Long.toString(
StUnhex.buffer(
StUnhex.unspace(xml.xpath("text()").get(0))
StUnhex.unspace(xml.xpath("./o/text()").get(0))
).getLong()
)
)
Expand All @@ -78,7 +78,7 @@ public StUnhex() {
"bool",
Boolean.toString(
!"00".equals(
StUnhex.unspace(xml.xpath("text()").get(0))
StUnhex.unspace(xml.xpath("./o/text()").get(0))
)
).toUpperCase(Locale.ENGLISH)
)
Expand All @@ -90,16 +90,16 @@ public StUnhex() {
StringEscapeUtils.escapeJava(
new String(
StUnhex.buffer(
StUnhex.unspace(xml.xpath("text()").get(0))
StUnhex.unspace(xml.xpath("./o/text()").get(0))
).array(),
StandardCharsets.UTF_8
)
)
)
),
new StXPath(
"(//o[@data='bytes' and (@base='string' or @base='org.eolang.string') and empty(text())])[1]",
xml -> new Directives().attr("data", "string")
"(//o[@data='bytes' and (@base='bytes' or @base='org.eolang.bytes') and empty(text())]/parent::o[(@base='string' or @base='org.eolang.string')])[1]",
xml -> new Directives().set("").attr("data", "string")
)
)
)
Expand Down Expand Up @@ -144,7 +144,7 @@ private static String unspace(final String txt) {
*/
private static String xpath(final String type) {
return String.format(
"(//o[@data='bytes' and (@base='%s' or @base='org.eolang.%1$s') and not(empty(text()))])[1]",
"(//o[@data='bytes' and (@base='bytes' or @base='org.eolang.bytes') and not(empty(text()))]/parent::o[(@base='%s' or @base='org.eolang.%1$s')])[1]",
type
);
}
Expand Down
9 changes: 8 additions & 1 deletion eo-parser/src/main/java/org/eolang/parser/XMIR.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.Xsline;
import org.cactoos.Text;
import org.cactoos.scalar.Unchecked;
Expand Down Expand Up @@ -95,7 +97,12 @@ private XMIR(final Unchecked<String> src) {
* @return The program in EO
*/
public String toEO() {
return new Xsline(new TrClasspath<>(XMIR.SHEETS).back())
return new Xsline(
new TrJoined<>(
new TrDefault<>(new StUnhex()),
new TrClasspath<>(XMIR.SHEETS).back()
)
)
.pass(new XMLDocument(this.content.value()))
.xpath("eo/text()")
.get(0);
Expand Down
17 changes: 2 additions & 15 deletions eo-parser/src/main/resources/org/eolang/parser/xmir-to-eo.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ SOFTWARE.
</xsl:if>
</xsl:template>
<!-- DATA BYTES -->
<xsl:template match="o[@data='bytes']" mode="head">
<xsl:template match="o[@data]" mode="head">
<xsl:choose>
<xsl:when test="@base='string'">
<xsl:text>"""</xsl:text>
Expand All @@ -141,20 +141,7 @@ SOFTWARE.
<xsl:value-of select="$eol"/>
<xsl:text>"""</xsl:text>
</xsl:when>
<xsl:when test="@base='bool'">
<xsl:choose>
<xsl:when test="text() = '01'">
<xsl:text>TRUE</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>FALSE</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="@base='int'">
<xsl:value-of select="eo:bytes-to-int(replace(text(), ' ', ''))"/>
</xsl:when>
<xsl:when test="@base='float'">
<xsl:when test="@base='bool' or @base='int' or @base='float'">
<xsl:value-of select="text()"/>
</xsl:when>
<xsl:otherwise>
Expand Down
8 changes: 8 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/StEoLoggedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -74,7 +75,14 @@ void delegatesWithoutException() {
);
}

/**
* Check EO log message on exception thrown.
* @todo #2750:30min After removing conversion from bytes to value from 'xmir-to-eo.xsl' this
* test fails. All logic related to bytes conversion was moved to {@link StUnhex} class. Need
* to fix or remove this test.
*/
@Test
@Disabled
void printsMessageWithEoIfExceptionIsThrown() {
final FakeLog log = new FakeLog();
Assertions.assertThrows(
Expand Down
18 changes: 9 additions & 9 deletions eo-parser/src/test/java/org/eolang/parser/StUnhexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void convertsIntFromHexToEo() {
MatcherAssert.assertThat(
new Xsline(new StUnhex()).pass(
new XMLDocument(
"<p><o base='int' data='bytes'>01 02 E4 F3 04 67 32 E1</o></p>"
"<p><o base='int'><o base='org.eolang.bytes' data='bytes'>01 02 E4 F3 04 67 32 E1</o></o></p>"
)
),
XhtmlMatchers.hasXPaths("//o[text()='72872276393407201' and @data='int']")
Expand All @@ -53,7 +53,7 @@ void convertsMaxIntFromHexToEo() {
MatcherAssert.assertThat(
new Xsline(new StUnhex()).pass(
new XMLDocument(
"<p><o base='org.eolang.int' data='bytes'>FF FF FF FF FF FF FF FF</o></p>"
"<p><o base='int'><o base='org.eolang.bytes' data='bytes'>FF FF FF FF FF FF FF FF</o></o></p>"
)
),
XhtmlMatchers.hasXPaths("//o[text()='-1' and @data='int']")
Expand All @@ -67,8 +67,8 @@ void convertsStringFromHexToEo() {
new XMLDocument(
String.join(
"",
"<p><o base='string' data='bytes'>41 42 0A 09</o>",
"<o base='string' data='bytes'>41 42</o></p>"
"<p><o base='string'><o base='bytes' data='bytes'>41 42 0A 09</o></o>",
"<o base='string'><o base='bytes' data='bytes'>41 42</o></o></p>"
)
)
),
Expand All @@ -84,7 +84,7 @@ void convertsEmptyStringFromHexToEo() {
MatcherAssert.assertThat(
new Xsline(new StUnhex()).pass(
new XMLDocument(
"<p><o base='string' data='bytes'/></p>"
"<p><o base='string'><o base='bytes' data='bytes'/></o></p>"
)
),
XhtmlMatchers.hasXPaths(
Expand All @@ -98,7 +98,7 @@ void convertsFloatFromHexToEo() {
MatcherAssert.assertThat(
new Xsline(new StUnhex()).pass(
new XMLDocument(
"<p><o base='org.eolang.float' data='bytes'>41 42 43 67 AE CD 3E FD</o></p>"
"<p><o base='float'><o base='org.eolang.bytes' data='bytes'>41 42 43 67 AE CD 3E FD</o></o></p>"
)
),
XhtmlMatchers.hasXPaths(
Expand All @@ -114,8 +114,8 @@ void convertsTrueFromHexToEo() {
new XMLDocument(
String.join(
"",
"<p><o base='bool' data='bytes' name='a'>01</o>",
"<o><o base='bool' data='bytes' name='b'>00</o></o></p>"
"<p><o base='bool' name='a'><o base='bytes' data='bytes'>01</o></o>",
"<o base='bool' name='b'><o base='bytes' data='bytes'>00</o></o></p>"
)
)
),
Expand All @@ -131,7 +131,7 @@ void convertsFalseFromHexToEo() {
MatcherAssert.assertThat(
new Xsline(new StUnhex()).pass(
new XMLDocument(
"<p><o base='org.eolang.bool' data='bytes'>00</o></p>"
"<p><o base='bool'><o base='org.eolang.bytes' data='bytes'>00</o></o></p>"
)
),
XhtmlMatchers.hasXPaths("//o[text()='FALSE' and @data='bool']")
Expand Down
26 changes: 14 additions & 12 deletions eo-parser/src/test/java/org/eolang/parser/XMIRTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.jcabi.xml.ClasspathSources;
import com.jcabi.xml.XML;
import com.jcabi.xml.XSLDocument;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.Xsline;
import java.io.IOException;
import org.cactoos.io.InputOf;
import org.eolang.jucs.ClasspathSource;
Expand All @@ -46,12 +48,11 @@ final class XMIRTest {
* Convert EO to xmir and back and compare.
* @param src EO source.
* @throws Exception If fails.
* @todo #2729:30min Xmir samples are not converted successfully. Since we have data only in
* bytes and after changing 'xmir-to-eo.xsl' many test are not passed anymore. The reason is
* next: if we have an integer in EO, it's converted to bytes in xmir, then it's converted to
* bytes in EO. Here we loose information about an integer while program still works the same.
* Need to either resolve such loosing or just rewrite the test. Previous samples were moved
* from "org/eolang/parser/xmir-samples" directory to "org/eolang/parser/xmir-samples-wrong"
* @todo #2750:30min Empty bytes in EO ("--") are not converted successfully. The test
* `org/eolang/parser/xmir-samples-wrong/empty-bytes.eo` fails. Transformation `xmir-to-eo.xsl`
* need to be fixed. Don't forget to move `empty-bytes.eo` test from
* `org/eolang/parser/xmir-samples-wrong` to `org/eolang/parser/xmir-samples` after fixing
* `xmir-to-eo.xsl`.
*/
@ParameterizedTest
@ClasspathSource(value = "org/eolang/parser/xmir-samples/", glob = "**.eo")
Expand Down Expand Up @@ -83,12 +84,13 @@ void printsToEO(final String src) throws Exception {
* @throws IOException If fails
*/
private static XML parse(final String source) throws IOException {
return new XSLDocument(
XMIRTest.class.getResourceAsStream("wrap-method-calls.xsl")
).with(new ClasspathSources()).transform(
new EoSyntax(
"test", new InputOf(source)
).parsed()
return new Xsline(
new TrClasspath<>(
"/org/eolang/parser/wrap-method-calls.xsl",
"/org/eolang/parser/explicit-data.xsl"
).back()
).pass(
new EoSyntax("test", new InputOf(source)).parsed()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- > empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[] > app
QQ.io.stdout > @
QQ.txt.sprintf ""

3 comments on commit 12bc873

@0pdd
Copy link

@0pdd 0pdd commented on 12bc873 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2729-2c784c24 disappeared from eo-parser/src/test/java/org/eolang/parser/XMIRTest.java), that's why I closed #2750. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 12bc873 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2750-1a6a1697 discovered in eo-parser/src/test/java/org/eolang/parser/StEoLoggedTest.java) and submitted as #2779. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 12bc873 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2750-54cc3dad discovered in eo-parser/src/test/java/org/eolang/parser/XMIRTest.java) and submitted as #2780. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.