Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#2682): unphi mojo test packs + bug fixes #2685

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void exec() {
);
home.save(
new PhiSyntax(
phi.getFileName().toString(),
phi.getFileName().toString().replace(".phi", ""),
new TextOf(phi)
).parsed().toString(),
relative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ SOFTWARE.
<xsl:value-of select="$home"/>
</xsl:when>
<xsl:when test="$n='$'">
<xsl:value-of select="eo:add-xi(not($is-name))"/>
<xsl:value-of select="$rho"/>
<xsl:value-of select="$xi"/>
</xsl:when>
<xsl:when test="$n='&lt;'">
<xsl:value-of select="eo:add-xi(not($is-name))"/>
Expand Down Expand Up @@ -311,6 +310,9 @@ SOFTWARE.
<xsl:value-of select="eo:comma($position)"/>
<xsl:choose>
<xsl:when test="@as">
<xsl:if test="matches(@as,'^[0-9][1-9]*$')">
<xsl:value-of select="$alpha"/>
</xsl:if>
<xsl:value-of select="eo:specials(@as, true())"/>
</xsl:when>
<xsl:otherwise>
Expand Down
40 changes: 34 additions & 6 deletions eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eolang.maven.util.HmBase;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -45,9 +44,6 @@
/**
* Test cases for {@link UnphiMojo}.
* @since 0.34.0
* @todo #2642:30min Create test packs for {@link UnphiMojo}. UnphiMojo seems to work correctly.
* We need to create yaml packs and enable {@link UnphiMojoTest#checksUnphiPacks(String, Path)}
* and make sure all of them are passed. Don't forget to remove the puzzle.
*/
class UnphiMojoTest {
@Test
Expand All @@ -69,7 +65,6 @@ void createsFile(@TempDir final Path temp) throws Exception {
}

@ParameterizedTest
@Disabled
@ClasspathSource(value = "org/eolang/maven/unphi", glob = "**.yaml")
void checksUnphiPacks(final String pack, @TempDir final Path temp) throws Exception {
final Map<String, Object> map = new Yaml().load(pack);
Expand All @@ -80,7 +75,9 @@ void checksUnphiPacks(final String pack, @TempDir final Path temp) throws Except
for (final String xpath : (Iterable<String>) map.get("tests")) {
final List<XML> nodes = new XMLDocument(
new TextOf(
Paths.get(String.format("target/%s/main.xmir", ParseMojo.DIR))
temp.resolve(
Paths.get(String.format("target/%s/main.xmir", ParseMojo.DIR))
)
).asString()
).nodes(xpath);
if (nodes.isEmpty()) {
Expand All @@ -96,4 +93,35 @@ void checksUnphiPacks(final String pack, @TempDir final Path temp) throws Except
Matchers.empty()
);
}

@ParameterizedTest
@ClasspathSource(value = "org/eolang/maven/phi", glob = "**.yaml")
void convertsToXmirAndBack(final String pack, @TempDir final Path temp) throws Exception {
final Map<String, Object> map = new Yaml().load(pack);
final String phi = map.get("phi").toString();
final String main = "target/phi/main.phi";
final Path path = Paths.get(main);
new HmBase(temp).save(phi, path);
final long saved = temp.resolve(path).toFile().lastModified();
final FakeMaven maven = new FakeMaven(temp).execute(UnphiMojo.class);
maven.foreignTojos().add("name")
.withXmir(temp.resolve(String.format("target/%s/main.xmir", ParseMojo.DIR)));
final Path result = maven
.execute(OptimizeMojo.class)
.execute(PhiMojo.class)
.result()
.get(main);
MatcherAssert.assertThat(
String.format("%s should have been rewritten after optimization, but it wasn't", main),
result.toFile().lastModified(),
Matchers.greaterThan(saved)
);
MatcherAssert.assertThat(
"Origin phi should equal to phi got from \"unphied\" xmir, but it isn't",
phi,
Matchers.equalTo(
new TextOf(result).asString()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ eo: |
< > vtx
^.< > self
@.@ > phi
phi: "{main ↦ ⟦x ↦ ξ.ρ.x, h ↦ Φ.org.eolang.y.σ, a ↦ ξ.ρ.a, vtx ↦ ξ.ν, self ↦ ξ.ρ.ν, phi ↦ ξ.φ.φ⟧}"
phi: "{main ↦ ⟦x ↦ ξ.ρ.x, h ↦ Φ.org.eolang.y.σ, a ↦ ξ.a, vtx ↦ ξ.ν, self ↦ ξ.ρ.ν, phi ↦ ξ.φ.φ⟧}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests:
- /program/objects/o[@name='main' and @atom and @abstract]
- /program/objects/o[@name='outer' and @abstract]
- /program/objects/o[@name='outer' and @abstract]/o[@name='inner' and @atom and @abstract]
phi:
"{main ↦ ⟦λ ⤍ Lambda⟧, outer ↦ ⟦inner ↦ ⟦λ ⤍ Lambda⟧⟧}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
tests:
- /program/objects/o[@base='Q']
- /program/objects/o[@method and @base='.org']
- /program/objects/o[@method and @base='.eolang']
- /program/objects/o[@method and @base='.x']

- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='Q']
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.org' and @method]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.eolang' and @method]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.y' and @method and @as='attr']

- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@abstract and @as='abs']
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@abstract and @as='abs']/o[@name='z' and not(@base)]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@abstract and @as='abs']/o[@base='Q']
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@abstract and @as='abs']/o[@base='.org' and @method]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@abstract and @as='abs']/o[@base='.eolang' and @method]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@abstract and @as='abs']/o[@base='.w' and @method and @name='@']

- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.int' and @method and @as='five']
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.int' and @method and @as='five']/o[@base='Q']
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.int' and @method and @as='five']/o[@base='.org' and @method]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.int' and @method and @as='five']/o[@base='.eolang' and @method]
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.int' and @method and @as='five']/o[@base='.bytes' and @method and @as='0']
- /program/objects/o[@method and @base='.x' and @name='xyz']/o[@base='.int' and @method and @as='five']/o[@base='.bytes' and @method and @as='0']/text()
phi:
"{xyz ↦ Φ.org.eolang.x(attr ↦ Φ.org.eolang.y, abs ↦ ⟦z ↦ ∅, φ ↦ Φ.org.eolang.w⟧, five ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ ⤍ 00-00-00-00-00-00-00-05)))}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests:
- /program/objects/o[@base='Q']
- /program/objects/o[@base='.org' and @method]
- /program/objects/o[@base='.eolang' and @method]
- /program/objects/o[@base='.bytes' and @method and @name='empty']
- /program/objects/o[@base='.bytes' and @method and @name='empty' and o[@base='org.eolang.bytes' and not(text())]]
phi: "{empty ↦ Φ.org.eolang.bytes(Δ ⤍ --)}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests:
- /program/objects/o[@base='Q']
- /program/objects/o[@base='.org' and @method]
- /program/objects/o[@base='.eolang' and @method]
- /program/objects/o[@base='.bytes' and @method and @name='bts' and o[@base='org.eolang.bytes' and text()='A2']]
phi: "{bts ↦ Φ.org.eolang.bytes(Δ ⤍ A2-)}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests:
- /program/metas/meta[head[text()='package'] and tail[text()='foo.bar.baz'] and part[text()='foo.bar.baz']]
- /program/objects/o[@abstract and @name='main']
- /program/objects/o[@abstract and @name='main']/o[@base='Q']
- /program/objects/o[@abstract and @name='main']/o[@base='.org' and @method]
- /program/objects/o[@abstract and @name='main']/o[@base='.eolang' and @method]
- /program/objects/o[@abstract and @name='main']/o[@base='.stdout' and @method and @name='@']
phi: "{foo ↦ ⟦bar ↦ ⟦baz ↦ ⟦main ↦ ⟦φ ↦ Φ.org.eolang.stdout⟧, λ ⤍ Package⟧, λ ⤍ Package⟧, λ ⤍ Package⟧}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
tests:
- /program/objects/o[@name='main']
- /program/objects/o[@name='main']/o[@base='$']/following-sibling::o[@base='.^' and @method]/following-sibling::o[@base='.x' and @method and @name='x']

- /program/objects/o[@name='main']/o[@base='Q']
- /program/objects/o[@name='main']/o[@base='.org' and @method]
- /program/objects/o[@name='main']/o[@base='.eolang' and @method]
- /program/objects/o[@name='main']/o[@base='.y' and @method]
- /program/objects/o[@name='main']/o[@base='.&' and @method and @name='h']

- /program/objects/o[@name='main']/o[@base='$']/following-sibling::o[@base='.a' and @method and @name='a']

- /program/objects/o[@name='main']/o[@base='$']/following-sibling::o[@base='.<' and @method and @name='vtx']

- /program/objects/o[@name='main']/o[@base='$']/following-sibling::o[@base='.^' and @method]/following-sibling::o[@base='.<' and @method and @name='self']

- /program/objects/o[@name='main']/o[@base='$']/following-sibling::o[@base='.@' and @method]/following-sibling::o[@base='.@' and @method and @name='phi']
eo: |
[] > main
^.x > x
y.& > h
$.a > a
< > vtx
^.< > self
@.@ > phi
phi: "{main ↦ ⟦x ↦ ξ.ρ.x, h ↦ Φ.org.eolang.y.σ, a ↦ ξ.ρ.a, vtx ↦ ξ.ν, self ↦ ξ.ρ.ν, phi ↦ ξ.φ.φ⟧}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests:
- /program/objects/o[@base='Q']
- /program/objects/o[@base='.org' and @method]
- /program/objects/o[@base='.eolang' and @method]
- /program/objects/o[@base='.int' and @method and @name='five']
- /program/objects/o[@base='.int' and @method and @name='five']/o[@base='Q']
- /program/objects/o[@base='.int' and @method and @name='five']/o[@base='.org' and @method]
- /program/objects/o[@base='.int' and @method and @name='five']/o[@base='.eolang' and @method]
- /program/objects/o[@base='.int' and @method and @name='five']/o[@base='.bytes' and @method and @as='0' and o[@base='org.eolang.bytes' and text()='00 00 00 00 00 00 00 05']]
phi: "{five ↦ Φ.org.eolang.int(α0 ↦ Φ.org.eolang.bytes(Δ ⤍ 00-00-00-00-00-00-00-05))}"
13 changes: 7 additions & 6 deletions eo-parser/src/main/java/org/eolang/parser/XePhiListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void exitFormation(final PhiParser.FormationContext ctx) {
if (!XePhiListener.hasLambdaPackage(ctx.bindings())) {
this.objects()
.prop("abstract")
.prop("name", this.attributes.pop());
.prop(this.properties.peek(), this.attributes.pop());
}
}

Expand Down Expand Up @@ -266,13 +266,14 @@ public void exitEmptyBinding(final PhiParser.EmptyBindingContext ctx) {

@Override
public void enterDeltaBidning(final PhiParser.DeltaBidningContext ctx) {
this.objects()
.start()
.prop("data", "bytes")
.prop("base", "org.eolang.bytes");
if (!ctx.BYTES().getText().equals("--")) {
this.objects().data(
ctx.BYTES().getText()
.replaceAll("-", " ")
.trim()
);
this.objects().data(ctx.BYTES().getText().replaceAll("-", " ").trim());
}
this.objects().leave();
}

@Override
Expand Down
17 changes: 15 additions & 2 deletions eo-parser/src/main/resources/org/eolang/parser/explicit-data.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ SOFTWARE.
</a>
</xsl:for-each>
</xsl:variable>
<xsl:template match="//o[@data and not(@data='tuple') and not(@base='org.eolang.bytes' or @base='bytes')]">
<xsl:template match="//o[@data and not(@base='org.eolang.bytes' or @base='bytes')]">
<xsl:choose>
<xsl:when test="parent::*[$literal-objects/text()=@base or $reversed/text()=@base]">
<xsl:when test="parent::*[$literal-objects/text()=@base or ($reversed/text()=@base and o[@base='.eolang' and o[@base='.org' and o[@base='Q']]])]">
<o base="org.eolang.bytes">
<xsl:attribute name="data">
<xsl:value-of select="./@data"/>
Expand Down Expand Up @@ -95,6 +95,19 @@ SOFTWARE.
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="//o[((@base='.bytes' and o[@base='.eolang' and o[@base='.org' and o[@base='Q']]]) or @base='org.eolang.bytes') and o[last() and @data]]">
<o base="org.eolang.bytes">
<xsl:for-each select="@*[name()!='data' and name()!='base']">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:attribute name="data">
<xsl:text>bytes</xsl:text>
</xsl:attribute>
<xsl:value-of select="o[@data]/text()"/>
</o>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ tests:
- //o[@base='org.eolang.float' and @name='bts' and o[@base='org.eolang.bytes' and @data]]
- //o[@base='org.eolang.float' and @name='second' and o[@base='org.eolang.bytes' and @data]]
- //o[@base='.bool' and @name='third' and count(o)=2 and o[last() and @base='org.eolang.bytes' and @data]]
- //o[@base='.bytes' and @name='fourth' and count(o)=2 and o[last() and @base='org.eolang.bytes' and @data]]
- //o[@base='org.eolang.bytes' and @name='fourth' and count(o)=0 and @data]
- //o[@base='.string' and @name='str' and count(o)=2 and o[last() and @base='org.eolang.bytes' and @data]]
- //o[@base='org.eolang.bytes' and @name='bt' and count(o)=0 and @data]
- //o[@base='org.eolang.tuple' and o[@base='org.eolang.tuple' and o[@base='org.eolang.int' and o[@base='org.eolang.bytes' and @data]]]]
eo: |
42 > first
Expand All @@ -20,6 +21,7 @@ eo: |
QQ.bytes > fourth
11-21
Q.org.eolang.string "Hey" > str
Q.org.eolang.bytes A2- > bt
tuple
* 1
2
Loading