Skip to content

Commit

Permalink
Merge branch 'master' into fix/#3569/xsd-attribute-name
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon authored Dec 8, 2024
2 parents d5ab000 + cd2e432 commit eddd175
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 24 deletions.
15 changes: 12 additions & 3 deletions eo-parser/src/main/resources/XMIR.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ SOFTWARE.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="∅|Q|QQ|[A-Z][^ \n\t\r]*|\.?(^|$|@|[a-z][^ \n\t\r]*)|[a-z][^ \n\t\r]*(\.[a-z][^ \n\t\r]*)*"/>
<xs:pattern value="∅|Q|QQ|[A-Z]\S*|\.?(^|$|@|[a-z]\S*)|[a-z]\S*(\.[a-z]\S*)*"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="locator">
Expand All @@ -110,7 +110,7 @@ SOFTWARE.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="Φ(\.(ρ|φ|α[0-9]+|[a-z][^ \n\r\t]*))*"/>
<xs:pattern value="Φ(\.(ρ|φ|α[0-9]+|[a-z]\S*))*"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="o" mixed="true">
Expand Down Expand Up @@ -170,10 +170,19 @@ SOFTWARE.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="star" type="empty"/>
<xs:attribute name="as" type="attribute-name"/>
<xs:attribute name="atom" type="fqn"/>
<xs:attribute name="loc" type="locator"/>
<!--
The following three are definitely temporary and should
be removed from XMIR. However, we can't remove them
now: they are created by the parser, then used by
the optimizer, and then removed. Since we check XML documents for
XSD compliance after the parsing phase, we can't remove them
now. We will remove them later, when we will have a separate
XSD for the parser output (maybe).
-->
<xs:attribute name="star" type="empty"/>
<xs:attribute name="method" type="empty"/>
<xs:attribute name="const" type="empty"/>
</xs:complexType>
Expand Down
38 changes: 38 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/EoSyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
*/
package org.eolang.parser;

import com.jcabi.log.Logger;
import com.jcabi.matchers.XhtmlMatchers;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Set;
import org.cactoos.io.InputOf;
import org.cactoos.io.ResourceOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.set.SetOf;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.xax.XtSticky;
Expand All @@ -42,6 +46,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.xml.sax.SAXParseException;

/**
* Test case for {@link EoSyntax}.
Expand Down Expand Up @@ -270,6 +275,39 @@ void checksTypoPacks(final String yaml) {
);
}

@ParameterizedTest
@ClasspathSource(value = "org/eolang/parser/xsd-mistakes/", glob = "**.yaml")
void checksXsdMistakes(final String yaml) throws Exception {
final Xtory story = new XtSticky(
new XtYaml(
yaml,
eo -> new EoSyntax(
"xsd-mistake",
new InputOf(String.format("%s\n", eo))
).parsed()
)
);
Assumptions.assumeTrue(story.map().get("skip") == null);
final XML xml = story.after();
final Set<String> errors = new SetOf<>(
new Mapped<>(
SAXParseException::toString,
xml.validate(
new XMLDocument(
new TextOf(new ResourceOf("XMIR.xsd")).asString()
)
)
)
);
MatcherAssert.assertThat(
Logger.format("correct number of errors found: %[list]s%n%s", errors, yaml),
errors,
Matchers.iterableWithSize(
Integer.parseInt(story.map().get("errors").toString())
)
);
}

@Test
void printsSyntaxWithComments() throws IOException {
final XML xml = new EoSyntax(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 2
document: |
<program name='foo'>
<objects>
<o name="foo" atom="Wrong Object Name"/>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 2
document: |
<program name='foo'>
<objects>
<o base="invalid FQN is here"/>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 2
document: |
<program name='foo'>
<objects>
<o name="foo" line="wrong-line-number"/>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 2
document: |
<program name='foo'>
<objects>
<o name="foo" loc="wrong-line-number"/>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 2
document: |
<program name='foo'>
<objects>
<o name="Invalid-Name"/>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 2
document: |
<program name='foo'>
<objects>
<o name="foo" pos="wrong-position-number"/>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---
errors: 1
document: |
<program>
<objects/>
</program>
6 changes: 6 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/malloc.eo
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
# Here the void attribute in the scope object is memory-block object which provides API to write
# and read data to the memory.
[] > malloc
# Allocates empty block in memory.
[scope] > empty
malloc.of > @
0
scope

# Allocates block in memory for given `object`. After allocation the provided object is dataized
# and the data are written into memory.
[object scope] > for
Expand Down
14 changes: 8 additions & 6 deletions eo-runtime/src/test/eo/org/eolang/malloc-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
[f]
malloc.of > second
1
[s] >>
f.put (f.as-number.plus 1) > @
f.put (f.as-number.plus 1) > [s] >>
seq > @
*
second
Expand Down Expand Up @@ -168,8 +167,7 @@
[b]
malloc.of > @
10
[m] >>
b.put (m.size.eq 10) > @
b.put (m.size.eq 10) > [m] >>

# This unit test is supposed to check the functionality of the corresponding object.
[] > malloc-writes-and-reads
Expand Down Expand Up @@ -229,8 +227,7 @@
0
malloc.of
0
[m]
m.size > @
m.size > [m]

# This unit test is supposed to check the functionality of the corresponding object.
[] > malloc-increases-block-size
Expand Down Expand Up @@ -263,3 +260,8 @@
malloc.of > @
1
m.resized -1 > [m]

# This unit test is supposed to check the functionality of the corresponding object.
[] > malloc-empty-is-empty
malloc.empty > @
m.size.eq 0 > [m]
Loading

0 comments on commit eddd175

Please sign in to comment.