Skip to content

Commit c240764

Browse files
committed
bug(#4828): mandatory as attribute
1 parent 530b3f6 commit c240764

9 files changed

Lines changed: 147 additions & 21 deletions

File tree

eo-integration-tests/src/test/java/integration/ReadmeSnippetsIT.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.stream.Stream;
2121
import org.hamcrest.MatcherAssert;
2222
import org.hamcrest.Matchers;
23-
import org.junit.jupiter.api.Disabled;
2423
import org.junit.jupiter.api.Tag;
2524
import org.junit.jupiter.api.extension.ExtendWith;
2625
import org.junit.jupiter.params.ParameterizedTest;
@@ -30,15 +29,10 @@
3029
/**
3130
* Integration test for EO snippets in `README.md`.
3231
* @since 0.56.3
33-
* @todo #4679:30min Enable ReadmeSnippetsIT when it's possible. The test was
34-
* disabled because because Attr interface was returned back and now these
35-
* tests don't work anymore. These tests must be enabled when new EO release
36-
* is made.
3732
*/
3833
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
3934
final class ReadmeSnippetsIT {
4035

41-
@Disabled
4236
@Tag("snippets")
4337
@ParameterizedTest
4438
@ExtendWith(MktmpResolver.class)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.hamcrest.Matchers;
2020
import org.hamcrest.io.FileMatchers;
2121
import org.junit.jupiter.api.Assertions;
22-
import org.junit.jupiter.api.Disabled;
2322
import org.junit.jupiter.api.Test;
2423
import org.junit.jupiter.api.extension.ExtendWith;
2524

@@ -32,7 +31,6 @@
3231
@ExtendWith(MktmpResolver.class)
3332
@ExtendWith(RandomProgramResolver.class)
3433
final class MjLintTest {
35-
@Disabled
3634
@Test
3735
void doesNotFailWithNoErrorsAndWarnings(@Mktmp final Path temp) throws IOException {
3836
new FakeMaven(temp)
@@ -123,7 +121,6 @@ void detectsWarningWithCorrespondingFlag(@Mktmp final Path temp) throws IOExcept
123121
);
124122
}
125123

126-
@Disabled
127124
@Test
128125
void doesNotDetectWarningWithoutCorrespondingFlag(@Mktmp final Path temp) {
129126
Assertions.assertDoesNotThrow(
@@ -165,7 +162,6 @@ void failsParsingOnError(@Mktmp final Path temp) throws Exception {
165162
);
166163
}
167164

168-
@Disabled
169165
@Test
170166
void skipsAlreadyLinted(@Mktmp final Path temp) throws IOException {
171167
final FakeMaven maven = new FakeMaven(temp)
@@ -184,7 +180,6 @@ void skipsAlreadyLinted(@Mktmp final Path temp) throws IOException {
184180
);
185181
}
186182

187-
@Disabled
188183
@Test
189184
void savesVerifiedResultsToCache(@Mktmp final Path temp) throws IOException {
190185
final Path cache = temp.resolve("cache");

eo-parser/src/main/java/org/eolang/parser/EoSyntax.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public final class EoSyntax implements Syntax {
101101
"/org/eolang/parser/parse/add-default-package.xsl",
102102
"/org/eolang/parser/parse/roll-bases.xsl",
103103
"/org/eolang/parser/parse/cti-adds-errors.xsl",
104-
"/org/eolang/parser/parse/decorate.xsl"
104+
"/org/eolang/parser/parse/decorate.xsl",
105+
"/org/eolang/parser/parse/mandatory-as.xsl"
105106
).back(),
106107
new TrDefault<>(new StHex())
107108
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public final class Xmir implements XML {
4343
new StClasspath("/org/eolang/parser/print/tuples-to-stars.xsl"),
4444
new StClasspath("/org/eolang/parser/print/inline-cactoos.xsl"),
4545
new StClasspath("/org/eolang/parser/print/dataized-to-const.xsl"),
46+
new StClasspath("/org/eolang/parser/print/unnecessary-as.xsl"),
4647
new StClasspath("/org/eolang/parser/print/to-eo.xsl")
4748
)
4849
)

eo-parser/src/main/resources/org/eolang/parser/parse/add-as-attributes-inside-application.xsl renamed to eo-parser/src/main/resources/org/eolang/parser/parse/mandatory-as.xsl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
44
* SPDX-License-Identifier: MIT
55
-->
6-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="add-as-attributes-inside-application" version="2.0">
6+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="mandatory-as" version="2.0">
77
<!--
88
Here we are going through all the applications (objects with `@base`), and add `@as`
99
attributes for each inner object. The content of `@as` attribute is based on `αN`, where `N` is
10-
an identifier of attribute in the current level of nesting. Object methods (objects with `@base`
11-
starting with `.` (dot) must not have `@as` attributes.
10+
an identifier of attribute in the current level of nesting.
1211
-->
1312
<xsl:template match="@*|node()">
1413
<xsl:copy>
@@ -25,4 +24,14 @@
2524
<xsl:apply-templates select="node()"/>
2625
</xsl:copy>
2726
</xsl:template>
27+
<xsl:template match="o[@base and starts-with(@base, '.') and count(o)&gt;1]/o[position()&gt;1 and not(@as)]">
28+
<xsl:copy>
29+
<xsl:apply-templates select="@*"/>
30+
<xsl:attribute name="as">
31+
<xsl:text>α</xsl:text>
32+
<xsl:value-of select="count(preceding-sibling::o[not(@as)]) - 1"/>
33+
</xsl:attribute>
34+
<xsl:apply-templates select="node()"/>
35+
</xsl:copy>
36+
</xsl:template>
2837
</xsl:stylesheet>

eo-parser/src/main/resources/org/eolang/parser/print/tuples-to-stars.xsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Performs the reverse operation of "/org/eolang/parser/stars-to-tuples.xsl"
99
-->
1010
<xsl:output encoding="UTF-8" method="xml"/>
11-
<xsl:template match="o[(starts-with(@base, 'Φ.org.eolang.tuple') or starts-with(@base, 'Φ̇.org.eolang.tuple')) and o[1][starts-with(@base, 'Φ.org.eolang.tuple') or starts-with(@base, 'Φ̇.org.eolang.tuple')]]">
11+
<xsl:template match="o[starts-with(@base, 'Φ.org.eolang.tuple') and o[1][starts-with(@base, 'Φ.org.eolang.tuple')]]">
1212
<xsl:variable name="arg">
1313
<xsl:apply-templates select="o[2]"/>
1414
</xsl:variable>
@@ -20,7 +20,7 @@
2020
</xsl:copy>
2121
</xsl:template>
2222
<xsl:template match="o" mode="inner">
23-
<xsl:if test="starts-with(@base, 'Φ.org.eolang.tuple') or starts-with(@base, 'Φ̇.org.eolang.tuple')">
23+
<xsl:if test="starts-with(@base, 'Φ.org.eolang.tuple')">
2424
<xsl:variable name="arg">
2525
<xsl:apply-templates select="o[2]"/>
2626
</xsl:variable>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
4+
* SPDX-License-Identifier: MIT
5+
-->
6+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="unnecessary-as" version="2.0">
7+
<!--
8+
Performs the reverse operation of "/org/eolang/parser/stars-to-tuples.xsl"
9+
-->
10+
<xsl:output encoding="UTF-8" method="xml"/>
11+
<xsl:function name="eo:all-alphas">
12+
<xsl:param name="index"/>
13+
<xsl:param name="elem"/>
14+
<xsl:choose>
15+
<xsl:when test="$elem/@as=concat('α', string($index))">
16+
<xsl:choose>
17+
<xsl:when test="$elem/following-sibling::o">
18+
<xsl:sequence select="eo:all-alphas($index + 1, $elem/following-sibling::o)"/>
19+
</xsl:when>
20+
<xsl:otherwise>
21+
<xsl:sequence select="true()"/>
22+
</xsl:otherwise>
23+
</xsl:choose>
24+
</xsl:when>
25+
<xsl:otherwise>
26+
<xsl:sequence select="false()"/>
27+
</xsl:otherwise>
28+
</xsl:choose>
29+
</xsl:function>
30+
<xsl:template match="o[@base and not(starts-with(@base, '.')) and count(o[@as])=count(o)]">
31+
<xsl:copy>
32+
<xsl:apply-templates select="@*"/>
33+
<xsl:choose>
34+
<xsl:when test="eo:all-alphas(0, o[1])">
35+
<xsl:for-each select="o">
36+
<xsl:variable name="elem">
37+
<xsl:element name="o">
38+
<xsl:for-each select="@*[name()!='as']">
39+
<xsl:attribute name="{name()}" select="."/>
40+
</xsl:for-each>
41+
<xsl:apply-templates select="node()"/>
42+
</xsl:element>
43+
</xsl:variable>
44+
<xsl:apply-templates select="$elem"/>
45+
</xsl:for-each>
46+
</xsl:when>
47+
<xsl:otherwise>
48+
<xsl:apply-templates select="o"/>
49+
</xsl:otherwise>
50+
</xsl:choose>
51+
<xsl:apply-templates select="text()"/>
52+
</xsl:copy>
53+
</xsl:template>
54+
<xsl:template match="o[@base and starts-with(@base, '.') and count(o[@as])=count(o)-1]">
55+
<xsl:copy>
56+
<xsl:apply-templates select="@*"/>
57+
<xsl:apply-templates select="o[1]"/>
58+
<xsl:choose>
59+
<xsl:when test="eo:all-alphas(0, o[position()=2])">
60+
<xsl:for-each select="o[position()&gt;1]">
61+
<xsl:variable name="elem">
62+
<xsl:element name="o">
63+
<xsl:for-each select="@*[name()!='as']">
64+
<xsl:attribute name="{name()}" select="."/>
65+
</xsl:for-each>
66+
<xsl:apply-templates select="node()"/>
67+
</xsl:element>
68+
</xsl:variable>
69+
<xsl:apply-templates select="$elem"/>
70+
</xsl:for-each>
71+
</xsl:when>
72+
<xsl:otherwise>
73+
<xsl:apply-templates select="o[position()&gt;1]"/>
74+
</xsl:otherwise>
75+
</xsl:choose>
76+
<xsl:apply-templates select="text()"/>
77+
</xsl:copy>
78+
</xsl:template>
79+
<xsl:template match="node()|@*">
80+
<xsl:copy>
81+
<xsl:apply-templates select="node()|@*"/>
82+
</xsl:copy>
83+
</xsl:template>
84+
</xsl:stylesheet>

eo-parser/src/test/resources/org/eolang/parser/eo-packs/parse/add-as-attributes-inside-application.yaml renamed to eo-parser/src/test/resources/org/eolang/parser/eo-packs/parse/mandatory-as-attribute.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@
55
sheets:
66
- /org/eolang/parser/parse/wrap-method-calls.xsl
77
- /org/eolang/parser/parse/vars-float-up.xsl
8+
- /org/eolang/parser/parse/build-fqns.xsl
89
- /org/eolang/parser/parse/expand-qqs.xsl
910
- /org/eolang/parser/parse/expand-aliases.xsl
1011
- /org/eolang/parser/parse/resolve-aliases.xsl
1112
- /org/eolang/parser/parse/add-default-package.xsl
12-
- /org/eolang/parser/parse/add-as-attributes-inside-application.xsl
13+
- /org/eolang/parser/parse/roll-bases.xsl
14+
- /org/eolang/parser/parse/mandatory-as.xsl
1315
asserts:
1416
- /object[not(errors)]
1517
- /object[count(o)=1]
16-
- //o[@base='Φ.org.eolang.foo' and @name='φ' and o[@base='Φ.org.eolang.i' and @as='α0']]
17-
- //o[@base='Φ.org.eolang.foo' and @name='φ' and o[@base='Φ.org.eolang.spb' and @as='α1']]
18+
- //o[@base='Φ.org.eolang.foo' and @name='φ' and o[@base='ξ.i' and @as='α0']]
19+
- //o[@base='Φ.org.eolang.foo' and @name='φ' and o[@base='ξ.spb' and @as='α1']]
1820
- //o[@base='Φ.org.eolang.x' and @name='i' and o[@base='Φ.org.eolang.number' and @as='α0']]
1921
- //o[@base='Φ.org.eolang.y' and @name='spb' and o[@base='Φ.org.eolang.number' and @as='α0']]
2022
- //o[@base='Φ.org.eolang.y' and @name='spb' and o[@base='Φ.org.eolang.number' and @as='α1']]
2123
- //o[@base='Φ.org.eolang.bytes' and o[@as='α0']]
22-
- //o[@base='.is' and @name='f' and not(@as)]
24+
- //o[@base='Φ.org.eolang.this.is' and @name='f' and not(@as)]
25+
- //o[@base='.if' and @name='q']/o[1][@base='Φ.org.eolang.some.x' and not(@as)]/o[1][@as='α0' and @base='Φ.org.eolang.y']
26+
- //o[@base='.if' and @name='q']/o[2][@base='Φ.org.eolang.number' and @as='α0']
27+
- //o[@base='.if' and @name='q']/o[3][@base='Φ.org.eolang.number' and @as='α1']
2328
input: |
2429
# This is main.
2530
[] > main
2631
foo > @
2732
x 42 > i
2833
y 52 -1 > spb
2934
this.is "F" > f
35+
if. > q
36+
some.x y
37+
1
38+
2
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
# yamllint disable rule:line-length
5+
sheets:
6+
- /org/eolang/parser/parse/move-voids-up.xsl
7+
- /org/eolang/parser/parse/validate-before-stars.xsl
8+
- /org/eolang/parser/parse/resolve-before-stars.xsl
9+
- /org/eolang/parser/parse/wrap-method-calls.xsl
10+
- /org/eolang/parser/parse/const-to-dataized.xsl
11+
- /org/eolang/parser/parse/stars-to-tuples.xsl
12+
- /org/eolang/parser/parse/vars-float-up.xsl
13+
- /org/eolang/parser/parse/build-fqns.xsl
14+
- /org/eolang/parser/parse/expand-qqs.xsl
15+
- /org/eolang/parser/parse/expand-aliases.xsl
16+
- /org/eolang/parser/parse/resolve-aliases.xsl
17+
- /org/eolang/parser/parse/add-default-package.xsl
18+
- /org/eolang/parser/parse/roll-bases.xsl
19+
- /org/eolang/parser/parse/mandatory-as.xsl
20+
- /org/eolang/parser/print/unnecessary-as.xsl
21+
asserts:
22+
- /object[count(//o[@as])=0]
23+
input: |
24+
# No comments.
25+
[] > foo
26+
foo > @
27+
x 42 > i
28+
y 52 -1 > spb
29+
this.is "F" > f
30+
if. > q
31+
some.x y
32+
1
33+
2

0 commit comments

Comments
 (0)