Skip to content

Commit

Permalink
fix(#2758): xmir tests + packs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jan 16, 2024
1 parent 6bff264 commit af4b50d
Show file tree
Hide file tree
Showing 32 changed files with 671 additions and 284 deletions.
24 changes: 22 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PrintMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
package org.eolang.maven;

import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -38,8 +40,10 @@
import org.eolang.maven.util.HmBase;
import org.eolang.maven.util.Home;
import org.eolang.maven.util.Walk;
import org.eolang.parser.XMIR;
import org.eolang.parser.Schema;
import org.eolang.parser.xmir.Xmir;
import org.eolang.parser.xmir.XmirReversed;
import org.eolang.parser.xmir.XmirSwap;

/**
* Print XMIR to EO.
Expand Down Expand Up @@ -73,6 +77,13 @@ public final class PrintMojo extends SafeMojo {
)
private File printOutputDir;

@Parameter(
property = "eo.printReversed",
required = true,
defaultValue = "false"
)
private boolean printReversed = false;

@Override
void exec() throws IOException {
final Home home = new HmBase(this.printOutputDir);
Expand All @@ -85,7 +96,16 @@ void exec() throws IOException {
this.printSourcesDir.toPath().relativize(source).toString()
.replace(".xmir", ".eo")
);
home.save(new Xmir(new TextOf(source)).toEO(), relative);
final XML xml = new XMLDocument(new TextOf(source).asString());
new Schema(xml).check();
home.save(
new XmirSwap(
this.printReversed,
new XmirReversed(xml),
new Xmir.Default(xml)
).toEO(),
relative
);
Logger.info(
this,
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)
Expand Down
2 changes: 1 addition & 1 deletion eo-maven-plugin/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ log4j.logger.org.eolang=INFO
log4j.logger.com.yegor256.xsline=INFO
log4j.logger.org.eolang.parser.EoSyntax=INFO
log4j.logger.org.eolang.parser.Scenario=INFO
log4j.logger.org.eolang.parser.XMIRTest=INFO
log4j.logger.org.eolang.parser.xmir.XmirTest=INFO
log4j.logger.org.eolang.maven.SodgMojo=TRACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
/**
* Test cases for {@link PrintMojo}.
* @since 0.33.0
* @todo #2758:30min To test that PrintMojo prints EO in different notations depends
* on given flag. When {@link org.eolang.parser.xmir.XmirReversed} and
* {@link org.eolang.parser.xmir.Xmir.Default} work correctly and prints xmirs in
* corresponding notations we need to check that PrintMojo uses them correctly
* depends on given flag {@link PrintMojo#printReversed}.
*/
final class PrintMojoTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<program ms="18" name="a" time="2023-10-19T09:27:28.852003Z">
<program
ms="18"
name="a"
time="2023-10-19T09:27:28.852003Z"
dob="2024-01-15T16:58:03"
revision="6058559"
source="/Users/maxonfjvipon/code/java/eo/eo-runtime/src/main/eo/org/eolang/a.eo"
version="1.0-SNAPSHOT"
>
<listing>[d] &gt; a
cage d &gt; this-d
[] &gt; new
^ &gt; @
[] &gt; foo
this-d.plus 1 &gt; @
</listing>
<errors/>
<sheets/>
<license/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<program ms="18" name="a" time="2023-10-19T09:27:28.852003Z">
<program
ms="18"
name="a"
time="2023-10-19T09:27:28.852003Z"
dob="2024-01-15T16:58:03"
revision="6058559"
source="/Users/maxonfjvipon/code/java/eo/eo-runtime/src/main/eo/org/eolang/as-phi.eo"
version="1.0-SNAPSHOT"
>
<listing>[a] &gt; a
cage a &gt; this-a
[] &gt; new
^ &gt; @
[] &gt; foo
this-a.foo.plus 2 &gt; @
</listing>
<errors/>
<sheets/>
<license/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<program ms="18" name="main" time="2023-10-19T09:27:28.852003Z">
<program
ms="18"
name="main"
time="2023-10-19T09:27:28.852003Z"
dob="2024-01-15T16:58:03"
revision="6058559"
source="/Users/maxonfjvipon/code/java/eo/eo-runtime/src/main/eo/org/eolang/as-phi.eo"
version="1.0-SNAPSHOT"
>
<listing>[] &gt; main
[args...] &gt; main
b.new (a.new 42) 21
Expand All @@ -19,7 +27,7 @@
<o base="int" data="bytes" line="3" pos="10">00 00 00 00 00 00 00 2A</o>
</o>
</o>
<o base="int" data="bytes" line="3" pos="18">00 00 00 00 00 00 00 0C</o>
<o base="org.eolang.int" data="bytes" line="3" pos="18">00 00 00 00 00 00 00 0C</o>
</o>
</o>
</o>
Expand Down
83 changes: 21 additions & 62 deletions eo-parser/src/main/java/org/eolang/parser/xmir/Xmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@
package org.eolang.parser.xmir;

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.StClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.Train;
import com.yegor256.xsline.Xsline;
import org.cactoos.Text;
import org.cactoos.scalar.Unchecked;
import org.eolang.parser.StUnhex;

/**
* Prints XMIR to EO.
*
* @since 0.35.0
*/
public interface Xmir {
Expand All @@ -60,93 +57,55 @@ public interface Xmir {
*/
final class Default implements Xmir {
/**
* Wrap method calls XSL.
* Train of transformations.
*/
private static final String WRAP = "/org/eolang/parser/wrap-method-calls.xsl";
private static final Train<Shift> TRAIN = new TrDefault<>(
new StClasspath("/org/eolang/parser/explicit-data.xsl"),
new StUnhex(),
new StClasspath("/org/eolang/parser/wrap-method-calls.xsl")
);

/**
* Default xmir-to-eo XSL transformation.
*/
private static final String TO_EO = "/org/eolang/parser/xmir-to-eo.xsl";

/**
* The XML content.
*/
private final Unchecked<String> content;

/**
* XSL transformation sheets.
*/
private final String[] sheets;

/**
* Ctor.
* @param src The source
* The XML.
*/
public Default(final String src) {
this(new XMLDocument(src));
}
private final XML xml;

/**
* Ctor.
* @param src The source
* Result to-EO transformation.
*/
public Default(final Text src) {
this(new Unchecked<>(src::asString), Xmir.Default.TO_EO);
}

/**
* Ctor.
* @param src The source
* @param xsl To-EO transformation
*/
public Default(final Text src, final String xsl) {
this(new Unchecked<>(src::asString), xsl);
}

/**
* Ctor.
* @param src The source
*/
public Default(final XML src, final String xsl) {
this(new Unchecked<>(src::toString), xsl);
}
private final String xsl;

/**
* Ctor.
* @param src The source
*/
public Default(final XML src) {
this(new Unchecked<>(src::toString), Xmir.Default.TO_EO);
}

/**
* Ctor.
* @param src The source
* @param xsl To-EO transformation
*/
Default(final Unchecked<String> src, final String xsl) {
this(src, new String[] { Xmir.Default.WRAP, xsl });
this(src, Xmir.Default.TO_EO);
}

/**
* Ctor.
* @param src The source
* @param classpath To-EO transformation classpath
*/
private Default(final Unchecked<String> src, final String[] sheets) {
this.content = src;
this.sheets = sheets;
public Default(final XML src, final String classpath) {
this.xml = src;
this.xsl = classpath;
}

@Override
public String toEO() {
return new Xsline(
new TrJoined<>(
new TrDefault<>(new StUnhex()),
new TrClasspath<>(this.sheets).back()
Xmir.Default.TRAIN.with(
new StClasspath(this.xsl)
)
)
.pass(new XMLDocument(this.content.value()))
.pass(this.xml)
.xpath("eo/text()")
.get(0);
}
Expand Down
13 changes: 2 additions & 11 deletions eo-parser/src/main/java/org/eolang/parser/xmir/XmirReversed.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.eolang.parser.xmir;

import com.jcabi.xml.XML;
import org.cactoos.scalar.Unchecked;

/**
* Converts to EO with reversed methods.
Expand All @@ -34,21 +33,13 @@ public final class XmirReversed extends XmirEnvelope {
/**
* XSL transformation that converts XMIR to EO with reversed methods.
*/
private static final String REVERSED = "/org/eolang/parser/xmir-to-eo-reversed.xsl";
private static final String REVERSED = "/org/eolang/parser/xmir-to-eo.xsl";

/**
* Ctor.
* @param xml The source xml
*/
public XmirReversed(final XML xml) {
this(new Unchecked<>(xml::toString));
}

/**
* Ctor.
* @param src The source
*/
private XmirReversed(final Unchecked<String> src) {
super(new Xmir.Default(src, XmirReversed.REVERSED));
super(new Xmir.Default(xml, XmirReversed.REVERSED));
}
}
34 changes: 34 additions & 0 deletions eo-parser/src/main/java/org/eolang/parser/xmir/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* EO parser.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.1
* @see <a href="https://www.eolang.org">Project site www.eolang.org</a>
* @see <a href="https://github.com/objectionary/eo">GitHub project</a>
*/
package org.eolang.parser.xmir;
12 changes: 11 additions & 1 deletion eo-parser/src/main/resources/XMIR.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ SOFTWARE.
<xs:attribute name="scope" type="xs:string"/>
<xs:attribute name="name"/>
<xs:attribute name="base"/>
<xs:attribute name="data"/>
<xs:attribute name="data">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="bytes"/>
<xs:enumeration value="string"/>
<xs:enumeration value="int"/>
<xs:enumeration value="float"/>
<xs:enumeration value="bool"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="star"/>
<xs:attribute name="as"/>
<xs:attribute name="atom"/>
Expand Down
Loading

0 comments on commit af4b50d

Please sign in to comment.