Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af4b50d

Browse files
committed
fix(#2758): xmir tests + packs
1 parent 6bff264 commit af4b50d

File tree

32 files changed

+671
-284
lines changed

32 files changed

+671
-284
lines changed

eo-maven-plugin/src/main/java/org/eolang/maven/PrintMojo.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
package org.eolang.maven;
2525

2626
import com.jcabi.log.Logger;
27+
import com.jcabi.xml.XML;
28+
import com.jcabi.xml.XMLDocument;
2729
import java.io.File;
2830
import java.io.IOException;
2931
import java.nio.file.Path;
@@ -38,8 +40,10 @@
3840
import org.eolang.maven.util.HmBase;
3941
import org.eolang.maven.util.Home;
4042
import org.eolang.maven.util.Walk;
41-
import org.eolang.parser.XMIR;
43+
import org.eolang.parser.Schema;
4244
import org.eolang.parser.xmir.Xmir;
45+
import org.eolang.parser.xmir.XmirReversed;
46+
import org.eolang.parser.xmir.XmirSwap;
4347

4448
/**
4549
* Print XMIR to EO.
@@ -73,6 +77,13 @@ public final class PrintMojo extends SafeMojo {
7377
)
7478
private File printOutputDir;
7579

80+
@Parameter(
81+
property = "eo.printReversed",
82+
required = true,
83+
defaultValue = "false"
84+
)
85+
private boolean printReversed = false;
86+
7687
@Override
7788
void exec() throws IOException {
7889
final Home home = new HmBase(this.printOutputDir);
@@ -85,7 +96,16 @@ void exec() throws IOException {
8596
this.printSourcesDir.toPath().relativize(source).toString()
8697
.replace(".xmir", ".eo")
8798
);
88-
home.save(new Xmir(new TextOf(source)).toEO(), relative);
99+
final XML xml = new XMLDocument(new TextOf(source).asString());
100+
new Schema(xml).check();
101+
home.save(
102+
new XmirSwap(
103+
this.printReversed,
104+
new XmirReversed(xml),
105+
new Xmir.Default(xml)
106+
).toEO(),
107+
relative
108+
);
89109
Logger.info(
90110
this,
91111
"Printed: %s => %s", source, this.printOutputDir.toPath().resolve(relative)

eo-maven-plugin/src/main/resources/log4j.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ log4j.logger.org.eolang=INFO
88
log4j.logger.com.yegor256.xsline=INFO
99
log4j.logger.org.eolang.parser.EoSyntax=INFO
1010
log4j.logger.org.eolang.parser.Scenario=INFO
11-
log4j.logger.org.eolang.parser.XMIRTest=INFO
11+
log4j.logger.org.eolang.parser.xmir.XmirTest=INFO
1212
log4j.logger.org.eolang.maven.SodgMojo=TRACE

eo-maven-plugin/src/test/java/org/eolang/maven/PrintMojoTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
/**
4141
* Test cases for {@link PrintMojo}.
4242
* @since 0.33.0
43+
* @todo #2758:30min To test that PrintMojo prints EO in different notations depends
44+
* on given flag. When {@link org.eolang.parser.xmir.XmirReversed} and
45+
* {@link org.eolang.parser.xmir.Xmir.Default} work correctly and prints xmirs in
46+
* corresponding notations we need to check that PrintMojo uses them correctly
47+
* depends on given flag {@link PrintMojo#printReversed}.
4348
*/
4449
final class PrintMojoTest {
4550
@Test

eo-maven-plugin/src/test/resources/org/eolang/maven/print/inner/a.xmir

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
<program ms="18" name="a" time="2023-10-19T09:27:28.852003Z">
1+
<program
2+
ms="18"
3+
name="a"
4+
time="2023-10-19T09:27:28.852003Z"
5+
dob="2024-01-15T16:58:03"
6+
revision="6058559"
7+
source="/Users/maxonfjvipon/code/java/eo/eo-runtime/src/main/eo/org/eolang/a.eo"
8+
version="1.0-SNAPSHOT"
9+
>
10+
<listing>[d] &gt; a
11+
cage d &gt; this-d
12+
[] &gt; new
13+
^ &gt; @
14+
[] &gt; foo
15+
this-d.plus 1 &gt; @
16+
</listing>
217
<errors/>
318
<sheets/>
419
<license/>

eo-maven-plugin/src/test/resources/org/eolang/maven/print/inner/b.xmir

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
<program ms="18" name="a" time="2023-10-19T09:27:28.852003Z">
1+
<program
2+
ms="18"
3+
name="a"
4+
time="2023-10-19T09:27:28.852003Z"
5+
dob="2024-01-15T16:58:03"
6+
revision="6058559"
7+
source="/Users/maxonfjvipon/code/java/eo/eo-runtime/src/main/eo/org/eolang/as-phi.eo"
8+
version="1.0-SNAPSHOT"
9+
>
10+
<listing>[a] &gt; a
11+
cage a &gt; this-a
12+
[] &gt; new
13+
^ &gt; @
14+
[] &gt; foo
15+
this-a.foo.plus 2 &gt; @
16+
</listing>
217
<errors/>
318
<sheets/>
419
<license/>

eo-maven-plugin/src/test/resources/org/eolang/maven/print/main.xmir

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
<program ms="18" name="main" time="2023-10-19T09:27:28.852003Z">
1+
<program
2+
ms="18"
3+
name="main"
4+
time="2023-10-19T09:27:28.852003Z"
5+
dob="2024-01-15T16:58:03"
6+
revision="6058559"
7+
source="/Users/maxonfjvipon/code/java/eo/eo-runtime/src/main/eo/org/eolang/as-phi.eo"
8+
version="1.0-SNAPSHOT"
9+
>
210
<listing>[] &gt; main
311
[args...] &gt; main
412
b.new (a.new 42) 21
@@ -19,7 +27,7 @@
1927
<o base="int" data="bytes" line="3" pos="10">00 00 00 00 00 00 00 2A</o>
2028
</o>
2129
</o>
22-
<o base="int" data="bytes" line="3" pos="18">00 00 00 00 00 00 00 0C</o>
30+
<o base="org.eolang.int" data="bytes" line="3" pos="18">00 00 00 00 00 00 00 0C</o>
2331
</o>
2432
</o>
2533
</o>

eo-parser/src/main/java/org/eolang/parser/xmir/Xmir.java

Lines changed: 21 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
package org.eolang.parser.xmir;
2525

2626
import com.jcabi.xml.XML;
27-
import com.jcabi.xml.XMLDocument;
28-
import com.yegor256.xsline.TrClasspath;
27+
import com.yegor256.xsline.Shift;
28+
import com.yegor256.xsline.StClasspath;
2929
import com.yegor256.xsline.TrDefault;
30-
import com.yegor256.xsline.TrJoined;
30+
import com.yegor256.xsline.Train;
3131
import com.yegor256.xsline.Xsline;
32-
import org.cactoos.Text;
33-
import org.cactoos.scalar.Unchecked;
3432
import org.eolang.parser.StUnhex;
3533

3634
/**
3735
* Prints XMIR to EO.
38-
*
3936
* @since 0.35.0
4037
*/
4138
public interface Xmir {
@@ -60,93 +57,55 @@ public interface Xmir {
6057
*/
6158
final class Default implements Xmir {
6259
/**
63-
* Wrap method calls XSL.
60+
* Train of transformations.
6461
*/
65-
private static final String WRAP = "/org/eolang/parser/wrap-method-calls.xsl";
62+
private static final Train<Shift> TRAIN = new TrDefault<>(
63+
new StClasspath("/org/eolang/parser/explicit-data.xsl"),
64+
new StUnhex(),
65+
new StClasspath("/org/eolang/parser/wrap-method-calls.xsl")
66+
);
6667

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

7273
/**
73-
* The XML content.
74-
*/
75-
private final Unchecked<String> content;
76-
77-
/**
78-
* XSL transformation sheets.
79-
*/
80-
private final String[] sheets;
81-
82-
/**
83-
* Ctor.
84-
* @param src The source
74+
* The XML.
8575
*/
86-
public Default(final String src) {
87-
this(new XMLDocument(src));
88-
}
76+
private final XML xml;
8977

9078
/**
91-
* Ctor.
92-
* @param src The source
79+
* Result to-EO transformation.
9380
*/
94-
public Default(final Text src) {
95-
this(new Unchecked<>(src::asString), Xmir.Default.TO_EO);
96-
}
97-
98-
/**
99-
* Ctor.
100-
* @param src The source
101-
* @param xsl To-EO transformation
102-
*/
103-
public Default(final Text src, final String xsl) {
104-
this(new Unchecked<>(src::asString), xsl);
105-
}
106-
107-
/**
108-
* Ctor.
109-
* @param src The source
110-
*/
111-
public Default(final XML src, final String xsl) {
112-
this(new Unchecked<>(src::toString), xsl);
113-
}
81+
private final String xsl;
11482

11583
/**
11684
* Ctor.
11785
* @param src The source
11886
*/
11987
public Default(final XML src) {
120-
this(new Unchecked<>(src::toString), Xmir.Default.TO_EO);
121-
}
122-
123-
/**
124-
* Ctor.
125-
* @param src The source
126-
* @param xsl To-EO transformation
127-
*/
128-
Default(final Unchecked<String> src, final String xsl) {
129-
this(src, new String[] { Xmir.Default.WRAP, xsl });
88+
this(src, Xmir.Default.TO_EO);
13089
}
13190

13291
/**
13392
* Ctor.
13493
* @param src The source
94+
* @param classpath To-EO transformation classpath
13595
*/
136-
private Default(final Unchecked<String> src, final String[] sheets) {
137-
this.content = src;
138-
this.sheets = sheets;
96+
public Default(final XML src, final String classpath) {
97+
this.xml = src;
98+
this.xsl = classpath;
13999
}
140100

141101
@Override
142102
public String toEO() {
143103
return new Xsline(
144-
new TrJoined<>(
145-
new TrDefault<>(new StUnhex()),
146-
new TrClasspath<>(this.sheets).back()
104+
Xmir.Default.TRAIN.with(
105+
new StClasspath(this.xsl)
147106
)
148107
)
149-
.pass(new XMLDocument(this.content.value()))
108+
.pass(this.xml)
150109
.xpath("eo/text()")
151110
.get(0);
152111
}

eo-parser/src/main/java/org/eolang/parser/xmir/XmirReversed.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package org.eolang.parser.xmir;
2525

2626
import com.jcabi.xml.XML;
27-
import org.cactoos.scalar.Unchecked;
2827

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

3938
/**
4039
* Ctor.
4140
* @param xml The source xml
4241
*/
4342
public XmirReversed(final XML xml) {
44-
this(new Unchecked<>(xml::toString));
45-
}
46-
47-
/**
48-
* Ctor.
49-
* @param src The source
50-
*/
51-
private XmirReversed(final Unchecked<String> src) {
52-
super(new Xmir.Default(src, XmirReversed.REVERSED));
43+
super(new Xmir.Default(xml, XmirReversed.REVERSED));
5344
}
5445
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2023 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
/**
26+
* EO parser.
27+
*
28+
* @author Yegor Bugayenko ([email protected])
29+
* @version $Id$
30+
* @since 0.1
31+
* @see <a href="https://www.eolang.org">Project site www.eolang.org</a>
32+
* @see <a href="https://github.com/objectionary/eo">GitHub project</a>
33+
*/
34+
package org.eolang.parser.xmir;

eo-parser/src/main/resources/XMIR.xsd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ SOFTWARE.
3737
<xs:attribute name="scope" type="xs:string"/>
3838
<xs:attribute name="name"/>
3939
<xs:attribute name="base"/>
40-
<xs:attribute name="data"/>
40+
<xs:attribute name="data">
41+
<xs:simpleType>
42+
<xs:restriction base="xs:string">
43+
<xs:enumeration value="bytes"/>
44+
<xs:enumeration value="string"/>
45+
<xs:enumeration value="int"/>
46+
<xs:enumeration value="float"/>
47+
<xs:enumeration value="bool"/>
48+
</xs:restriction>
49+
</xs:simpleType>
50+
</xs:attribute>
4151
<xs:attribute name="star"/>
4252
<xs:attribute name="as"/>
4353
<xs:attribute name="atom"/>

0 commit comments

Comments
 (0)