Skip to content

Commit

Permalink
#1 inject tau
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 30, 2021
1 parent 1bca74b commit f970f8e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/polystat/far/Reverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public Collection<String> errors(final String locator) throws IOException {
new Xsline(obj, new OutputTo(baos), new Spy.Verbose(), new ListOf<>())
.with(Reverses.xsl("expected.xsl").with("expected", "\\perp"))
.with(Reverses.xsl("reverses.xsl"))
.with(Reverses.xsl("inject-tau-numbers.xsl"))
.with(
Reverses.xsl("calculate.xsl").with(
(href, base) -> new StreamSource(
Expand Down
40 changes: 40 additions & 0 deletions src/main/resources/org/polystat/far/inject-tau-numbers.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<!--
The MIT License (MIT)
Copyright (c) 2020-2021 Polystat.org
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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="inject-tau-numbers" version="2.0">
<xsl:strip-space elements="*"/>
<xsl:template match="r[not(@tau)]">
<xsl:copy>
<xsl:attribute name="tau">
<xsl:value-of select="count(./preceding::*) + count(ancestor::*) + 1"/>
</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
1 change: 0 additions & 1 deletion src/main/resources/org/polystat/far/reverses.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ SOFTWARE.
<xsl:element name="r">
<xsl:attribute name="f" select="$o/@base"/>
<xsl:attribute name="pos" select="position()"/>
<xsl:attribute name="tau" select="$o/@line"/>
<xsl:copy-of select="$result"/>
</xsl:element>
</xsl:variable>
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/polystat/far/ReversesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public void findsReversesInSimpleXml() throws Exception {
final Path temp = Files.createTempDirectory("temp");
final Reverses reverses = new Reverses(new XMIR(sources, temp));
final Collection<String> bugs = reverses.errors("\\Phi.foo");
MatcherAssert.assertThat(bugs, Matchers.not(Matchers.emptyIterable()));
MatcherAssert.assertThat(
bugs,
Matchers.iterableWithSize(Matchers.not(Matchers.greaterThan(3)))
);
Logger.debug(this, "Bugs found: %s", bugs);
}

Expand Down
9 changes: 2 additions & 7 deletions src/test/resources/org/polystat/tests/div-by-zero.eo
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

[a b] > foo
add. > @
div. a b
div.
div. b a
a
b
div.
div.
b
a
a

0 comments on commit f970f8e

Please sign in to comment.