Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3fb11b6
feat(#107): decode ascii to string
h1alexbel Jan 7, 2025
455bcd3
feat(#107): sprintf args
h1alexbel Jan 8, 2025
fcba685
feat(#107): nested-args
h1alexbel Jan 8, 2025
06cf2f5
feat(#107): cases
h1alexbel Jan 8, 2025
245c6fb
feat(#107): passes
h1alexbel Jan 8, 2025
0907ec0
feat(#107): more tests
h1alexbel Jan 8, 2025
16bfa10
feat(#107): tests
h1alexbel Jan 8, 2025
b258f13
feat(#107): wrong-sprintf-arguments, fqn
h1alexbel Jan 8, 2025
ba66bb5
feat(#107): clean for qulice
h1alexbel Jan 8, 2025
b9b4612
Merge branch 'master' into 107-sprintf
h1alexbel Jan 8, 2025
8f3af6c
chore: timeouts
h1alexbel Jan 8, 2025
35f38a5
chore: timeouts 2x
h1alexbel Jan 8, 2025
d3ed3d6
chore: default timeout puzzle
h1alexbel Jan 8, 2025
14404b0
chore: unused
h1alexbel Jan 8, 2025
7169d59
feat(#107): allows more formatters
h1alexbel Jan 9, 2025
303aef2
feat(#107): path to fqn
h1alexbel Jan 9, 2025
061ac56
chore: move to separate bug
h1alexbel Jan 9, 2025
1d2f6a6
feat(#107): trigger
h1alexbel Jan 9, 2025
b2bf44a
feat(#107): back
h1alexbel Jan 9, 2025
61ed732
feat(#107): sprintf-text
h1alexbel Jan 12, 2025
374f92c
feat(#107): empty tuple
h1alexbel Jan 15, 2025
ad82171
feat(#107): iterates all sprintfs
h1alexbel Jan 15, 2025
4f13f86
feat(#107): indents
h1alexbel Jan 17, 2025
2466b0a
Merge branch 'master' into 107-sprintf
h1alexbel Jan 17, 2025
97c111e
feat(#107): clean grammar
h1alexbel Jan 17, 2025
3a06fc0
feat(#107): allows percentage sign
h1alexbel Jan 19, 2025
bee758f
feat(#107): clean grammar
h1alexbel Jan 19, 2025
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
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:eo="https://www.eolang.org" version="2.0" id="wrong-sprintf-arguments">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:function name="eo:hex-to-placeholder" as="xs:integer">
<xsl:param name="hex" as="xs:string"/>
<xsl:variable name="hex-upper" select="upper-case($hex)"/>
<xsl:variable name="length" select="string-length($hex-upper)"/>
<xsl:variable name="decimal" select="sum(for $i in 1 to $length return (index-of(string-to-codepoints('0123456789ABCDEF'), string-to-codepoints(substring($hex-upper, $i, 1))) - 1) * xs:integer(math:pow(16, $length - $i)))"/>
<xsl:sequence select="$decimal"/>
</xsl:function>
<xsl:variable name="sprintf" select="//o[@base='.sprintf'][o[@base='.txt']/o[@base='QQ']]"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel QQ is a placeholder for Q.org.eolang, so it'll be //o[@base='.sprintf' and o[@base='.txt']/o[@base='.eolang']/o[@base='.org']/o[@base='Q']] or //o[@base='org.eolang.txt.sprintf']

<xsl:variable name="placeholder">
<xsl:for-each select="tokenize($sprintf, '-')">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel I don't really understand what you're tokenizing here, $sprintf is the element <o base='.sprintf>...`, or I'm wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon here, $sprintf will be a value from a text() node inside sprintf object:

<o base=".sprintf" line="4" pos="8">
  <o base=".txt" line="4" pos="4">
    <o base="QQ" line="4" pos="2"/>
  </o>
  <o base="string" line="5" pos="4">
    48-65-6C-6C-6F-2C-20-25-73-21-20-59-6F-75-72-20-61-63-63-6F-75-6E-74-20-69-73-20-25-64-2E
  </o>
  <o base="tuple" line="6" pos="4">
    <o base=".empty">
      <o base="tuple"/>
    </o>
    <o base="name" line="6" pos="6"/>
  </o>
</o>

48-65-6C-6C-6F-2C-20-25-73-21-20-59-6F-75-72-20-61-63-63-6F-75-6E-74-20-69-73-20-25-64-2E will be selected as $sprintf here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel what if the tuple (2nd argument of sprintf) would also contain a string or number?

sprintf
  "Hello, %s"
  * "Jeff"

In XMIR it would look like this:

<o base=".sprintf" line="4" pos="8">
  <o base=".txt" line="4" pos="4">
    <o base="QQ" line="4" pos="2"/>
  </o>
  <o base="string" line="5" pos="4">
    48-65-6C-6C-6F-2C-20-25-73-21-20-59-6F-75-72-20-61-63-63-6F-75-6E-74-20-69-73-20-25-64-2E
  </o>
  <o base="tuple" line="6" pos="4">
    <o base=".empty">
      <o base="tuple"/>
    </o>
    <o base="string" line="5" pos="4">
      48-65-6C-6C-6F
    </o>
  </o>
</o>

What will the result of $sprintf variable in such case?

<xsl:value-of select="codepoints-to-string(eo:hex-to-placeholder(.))"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="declared" select="count(matches($placeholder, '%s')) + count(matches($placeholder, '%d'))"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel sprintf supports more formatters than just %d and %s

<xsl:variable name="tupled" select="//o[@base='.sprintf']/o[@base='tuple']/o[not(@base='.empty')]"/>
<xsl:variable name="nested">
<xsl:for-each select="$tupled">
<xsl:call-template name="nested-args">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:template name="nested-args">
<xsl:param name="node"/>
<xsl:for-each select="$node/o[not(@base='tuple') and not(@base='.empty')]">
<xsl:value-of select="@base"/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:for-each select="$node/o[@base='tuple']">
<xsl:call-template name="nested-args">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:variable name="used" select="count($tupled[not(@base='tuple')]/@base) + count(tokenize(substring($nested, 1, string-length($nested) - 1), '\s+'))"/>
<xsl:template match="/">
<defects>
<xsl:if test="$sprintf != '' and $declared != $used">
<defect>
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno($sprintf/@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
</xsl:attribute>
<xsl:text>The sprintf object has wrong number of arguments: </xsl:text>
<xsl:value-of select="$declared"/>
<xsl:text> in the placeholder, but </xsl:text>
<xsl:value-of select="$used"/>
<xsl:text> are passed</xsl:text>
</defect>
</xsl:if>
</defects>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Wrong `QQ.txt.sprintf` Arguments

The `QQ.txt.sprintf` object must have a match between its placeholder variables
and passed arguments.

Incorrect:

```eo
# App.
[] > app
QQ.io.stdout > @
not.sprintf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel something went wrong here

"Hello, %s! Your account is %d."
* name
```

Correct:

```eo
# App.
[] > app
QQ.io.stdout > @
not.sprintf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel and here

"Hello, %s! Your account is %d."
* name acc
```
5 changes: 4 additions & 1 deletion src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

junit.jupiter.execution.timeout.test.method.default = 3s
# @todo #107:45min Configure default timeout for tests running on windows to 10s and 3s on other platforms.
# Currently, it fails with the 3s timeout on windows platform. Let's try to configure
# test default timeout exclusively for windows, and keep 3s for other platforms.
junit.jupiter.execution.timeout.test.method.default = 10s
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.
---
sheets:
- /org/eolang/lints/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App that uses sparse sprintf.
[] > app
QQ.io.stdout > @
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel something's wrong with indentation here

QQ.txt.sprintf
"Hello, %s! Your account is %d."
* name acc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.
---
sheets:
- /org/eolang/lints/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
input: |
# App.
[] > app
QQ.io.stdout > @
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel something's wrong with indentation here

QQ.txt.sprintf
"Hello, %s! Your account is %d."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel sprintf requires 2 mandatory argument, so if you want to provide empty tuple - just do add * as the second argument

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
---
sheets:
- /org/eolang/lints/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
input: |
# App.
[] > app
QQ.io.stdout > @
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h1alexbel something's wrong with indentation here

QQ.txt.sprintf
"Hello, %s! Your account is %d."
* name acc foo bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
---
sheets:
- /org/eolang/lints/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
input: |
# App.
[] > app
QQ.io.stdout > @
QQ.txt.sprintf
"Hello, %s! Your account is %d."
* name
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.
---
sheets:
- /org/eolang/lints/misc/wrong-sprintf-arguments.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > app
QQ.io.stdout > @
not.sprintf
"Hello, %s! Your account is %d."
* name
Loading