Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 30, 2022
2 parents 3a77b34 + 7f10502 commit 314a544
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 83 deletions.
33 changes: 33 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SodgMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.StBefore;
import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.StEndless;
import com.yegor256.xsline.StSchema;
import com.yegor256.xsline.StXSL;
import com.yegor256.xsline.TrClasspath;
Expand All @@ -45,11 +46,13 @@
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.regex.Pattern;
Expand All @@ -67,6 +70,7 @@
import org.cactoos.text.UncheckedText;
import org.eolang.maven.util.Home;
import org.eolang.maven.util.Rel;
import org.eolang.parser.StXPath;
import org.xembly.Directive;
import org.xembly.Directives;
import org.xembly.Xembler;
Expand Down Expand Up @@ -158,6 +162,22 @@ public final class SodgMojo extends SafeMojo {
"/org/eolang/maven/sodg/pre-clean.xsl",
"/org/eolang/maven/sodg/remove-leveled.xsl"
).back(),
new TrDefault<>(
new StEndless(
new StXPath(
"(//o[@name and @atom and not(@base) and @loc and not(@lambda)])[1]",
xml -> {
final String loc = xml.xpath("@loc").get(0);
return new Directives().attr(
"lambda",
SodgMojo.locToHex(
loc.substring(loc.indexOf('.') + 1)
)
);
}
)
)
),
new TrLogged(
new TrMapped<>(
(Function<String, Shift>) path -> new StBefore(
Expand Down Expand Up @@ -451,4 +471,17 @@ private void makeDot(final XML graph, final Path sodg) throws IOException {
}
}

/**
* Lambda to HEX.
* @param loc The lambda
* @return Hexadecimal value as string.
*/
private static String locToHex(final String loc) {
final StringJoiner out = new StringJoiner("-");
for (final byte bty : loc.getBytes(StandardCharsets.UTF_8)) {
out.add(String.format("%02X", bty));
}
return out.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,32 @@ SOFTWARE.
</xsl:copy>
</xsl:template>
<xsl:template match="o[@name and @atom and not(@base)]" mode="sodg" priority="1">
<xsl:if test="not(@lambda)">
<xsl:message terminate="yes">
<xsl:text>The @lambda is absent at '</xsl:text>
<xsl:value-of select="@loc"/>
<xsl:text>'</xsl:text>
</xsl:message>
</xsl:if>
<xsl:if test="@lambda = ''">
<xsl:message terminate="yes">
<xsl:text>The @lambda is empty at '</xsl:text>
<xsl:value-of select="@loc"/>
<xsl:text>'</xsl:text>
</xsl:message>
</xsl:if>
<xsl:call-template name="i">
<xsl:with-param name="name" select="'PUT'"/>
<xsl:with-param name="args" as="item()*">
<xsl:sequence>
<xsl:value-of select="eo:var(@loc)"/>
</xsl:sequence>
<xsl:sequence>
<xsl:value-of select="substring-after(@loc, '.')"/>
<xsl:variable name="data">
<xsl:text>01-</xsl:text>
<xsl:value-of select="replace(@lambda, ' ', '-')"/>
</xsl:variable>
<xsl:value-of select="$data"/>
</xsl:sequence>
</xsl:with-param>
<xsl:with-param name="comment">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ SOFTWARE.
</xsl:sequence>
<xsl:sequence>
<xsl:variable name="data">
<xsl:text>00-</xsl:text>
<xsl:value-of select="replace(text(), ' ', '-')"/>
<xsl:if test="not(contains(text(), ' '))">
<xsl:text>-</xsl:text>
</xsl:if>
</xsl:variable>
<xsl:value-of select="$data"/>
</xsl:sequence>
Expand Down
26 changes: 22 additions & 4 deletions eo-maven-plugin/src/test/java/org/eolang/maven/SodgMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import org.cactoos.set.SetOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.xax.XaxStory;
Expand Down Expand Up @@ -262,7 +264,7 @@ private void matches(final String item) {
final String data = sub.substring(2);
final boolean matches = !node.xpath(
String.format(
"data[text() = '%s']/text()", data
"data[text() = '00-%s']/text()", data
)
).isEmpty();
if (!matches) {
Expand All @@ -285,16 +287,20 @@ private void matches(final String item) {
);
}
final String data = sub.substring(2);
final String hex = SodgMojoTest.ExistsIn.bytesToHex(
data.getBytes(StandardCharsets.UTF_8)
);
final boolean matches = !node.xpath(
String.format(
"data[text() = '%s']/text()", data
"data[text() = '01-%s']/text()",
hex
)
).isEmpty();
if (!matches) {
throw new IllegalArgumentException(
String.format(
"Lambda '%s' at '%s' is not equal to '%s'",
node.xpath("data/text()").get(0), vertex, data
"Lambda '%s' at '%s' is not equal to '%s' (01-%s)",
node.xpath("data/text()").get(0), vertex, data, hex
)
);
}
Expand Down Expand Up @@ -322,6 +328,18 @@ private void matches(final String item) {
}
}

/**
* Bytes to HEX.
* @param bytes Bytes.
* @return Hexadecimal value as string.
*/
private static String bytesToHex(final byte... bytes) {
final StringJoiner out = new StringJoiner("-");
for (final byte bty : bytes) {
out.add(String.format("%02X", bty));
}
return out.toString();
}
}

}
1 change: 1 addition & 0 deletions eo-maven-plugin/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ log4j.logger.com.jcabi.log.VerboseProcess=INFO
log4j.logger.org.eolang.parser.Syntax=INFO
log4j.logger.org.eolang.parser.Program=INFO
log4j.logger.org.eolang.maven.SodgMojo=INFO
log4j.logger.org.eolang.maven.SodgMojoTest=INFO
log4j.logger.org.eolang.maven.TargetSpy=INFO
log4j.logger.org.eolang.parser.Scenario=INFO
log4j.logger.org.eolang.maven.Save=INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ sheets:
document:
<program>
<objects loc="Φ">
<o name="x" atom="" loc="Φ.a.b.x"/>
<o name="x" atom="" loc="Φ.a.b.x" lambda='01-02-03'/>
</objects>
<sodg/>
</program>
asserts:
- //sodg[count(i)=1]
- //i[@name='PUT' and a='$Φ.a.b.x' and a='a.b.x']
- //i[@name='PUT' and a='$Φ.a.b.x' and a='01-01-02-03']
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ document:
</program>
asserts:
- //sodg[count(i)=1]
- //i[@name='PUT' and a='$Φ.a.b.x' and a='01-']
- //i[@name='PUT' and a='$Φ.a.b.x' and a='00-01']
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locators:
- .data .f Δ=40-09-21-FB-4D-12-D8-4A .π >float
- .data .b Δ=01- .π >bool
- .data .b Δ=01 .π >bool
- .data .i Δ=00-00-00-00-00-01-00-00 .π >int
- .data .s Δ=D0-B4-D1-80-D1-83-D0-B3 .π >string
eo: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ locators:
- .org .eolang .bool
- .org .eolang .bool !.not
- .org .eolang .int !.plus
- .dots .x .ξ/.not Δ=01- .π >bool
- .dots .x .ξ/.not Δ=01 .π >bool
- .dots .y >b
- .dots .z .π/.times .π/.plus Δ=00-00-00-00-00-00-00-2A .π >int
eo: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ locators:
- .boom
- .foo
- .bar
- .simple .φ .ρ .φ .σ .φ .α0 .α0 Δ=01- .π >bool
- .simple .φ .ρ .φ .σ .φ .α0 .α0 Δ=01 .π >bool
- .simple .φ .α1 Δ=00-00-00-00-00-00-00-2A .π >int
- .simple .φ .α2 >boom
eo: |
Expand Down
Loading

0 comments on commit 314a544

Please sign in to comment.