Skip to content

Commit

Permalink
#2750 fix xmir-to-eo.xsl
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Jan 11, 2024
1 parent c2f48b7 commit 43b1897
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
17 changes: 7 additions & 10 deletions eo-parser/src/main/java/org/eolang/parser/StUnhex.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,19 @@ public StUnhex() {
StUnhex.xpath("string"),
xml -> StUnhex.append(
"string",
String.format(
"\"%s\"",
StringEscapeUtils.escapeJava(
new String(
StUnhex.buffer(
StUnhex.unspace(xml.xpath("./o/text()").get(0))
).array(),
StandardCharsets.UTF_8
)
StringEscapeUtils.escapeJava(
new String(
StUnhex.buffer(
StUnhex.unspace(xml.xpath("./o/text()").get(0))
).array(),
StandardCharsets.UTF_8
)
)
)
),
new StXPath(
"(//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")
xml -> new Directives().set("").attr("data", "string")
)
)
)
Expand Down
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 Down
6 changes: 3 additions & 3 deletions eo-parser/src/test/java/org/eolang/parser/StUnhexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ void convertsStringFromHexToEo() {
)
),
XhtmlMatchers.hasXPaths(
"//o[text()='\"AB\\n\\t\"' and @data='string']",
"//o[text()='\"AB\"' and @data='string']"
"//o[text()='AB\\n\\t' and @data='string']",
"//o[text()='AB' and @data='string']"
)
);
}
Expand All @@ -88,7 +88,7 @@ void convertsEmptyStringFromHexToEo() {
)
),
XhtmlMatchers.hasXPaths(
"//o[text()='\"\"' and @data='string']"
"//o[empty(text()) and @data='string']"
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions eo-parser/src/test/java/org/eolang/parser/XMIRTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ final class XMIRTest {
@ParameterizedTest
@ClasspathSource(value = "org/eolang/parser/xmir-samples/", glob = "**.eo")
void printsToEO(final String src) throws Exception {
Logger.debug(this, "Original EOLANG:%n%s", src);
Logger.warnForced(this, "Original EOLANG:%n%s", src);
final XML first = XMIRTest.clean(XMIRTest.parse(src));
Logger.debug(this, "First:%n%s", first);
Logger.warnForced(this, "First:%n%s", first);
final String eolang = new XMIR(first).toEO();
Logger.debug(this, "EOLANG:%n%s", eolang);
Logger.warnForced(this, "EOLANG:%n%s", eolang);
final XML second = XMIRTest.clean(XMIRTest.parse(eolang));
Logger.debug(this, "Second:%n%s", second);
Logger.warnForced(this, "Second:%n%s", second);
final String ignore = "data=\"\\S+\"";
MatcherAssert.assertThat(
first
Expand Down

0 comments on commit 43b1897

Please sign in to comment.