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

strformat: doc example fails #14054

Closed
pb-cdunn opened this issue Apr 21, 2020 · 1 comment
Closed

strformat: doc example fails #14054

pb-cdunn opened this issue Apr 21, 2020 · 1 comment

Comments

@pb-cdunn
Copy link
Contributor

pb-cdunn commented Apr 21, 2020

This comes from straight from the docs for strformat:

doAssert fmt"{123.456:>9.0f}" == " 123."

Example

import strformat

proc main() =
    doAssert fmt"{123.456:>9.0f}" == "     123."
main()

Current Output

Error: unhandled exception: foo.nim(4, 14) `fmt"{123.456:>9.0f}" == "     123."`  [AssertionError]

Expected Output

It should pass.

How I found this:

    stats.to_table(st) was Assembly statistics
       120  sum
         40 mean
        40  median
...
    expected_table was Assembly statistics
       120  sum
        40. mean
...
proc to_table*(st: Stats): string =
    result = strformat.fmt"""Assembly statistics
{st.sum:>10}  sum
{math.round(st.mean):>11.0f} mean
{st.median:>10}  median
...

Possible Solution

Not sure, but this came up before:

Additional Information

  • It was working in version 1.0.0, and earlier.
$ nim -v
Nim Compiler Version 1.2.0 [Linux: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
@pb-cdunn
Copy link
Contributor Author

Btw, I don't have an opinion on whether the dot should be there. Updating the docs would be fine with me. But if you want to maintain backward compatibility, maybe we need a different character to match Python/JS behavior. Maybe a ! instead of ..

@Araq Araq closed this as completed in cc60cae Apr 30, 2020
narimiran pushed a commit that referenced this issue May 6, 2020
* fixes #14054

* make tests green again

* more tests are green

* maybe now

(cherry picked from commit cc60cae)
EchoPouet pushed a commit to EchoPouet/Nim that referenced this issue Jun 13, 2020
* fixes nim-lang#14054

* make tests green again

* more tests are green

* maybe now
cdunn2001 pushed a commit to bio-nim/pb-falconc that referenced this issue Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants