-
Notifications
You must be signed in to change notification settings - Fork 36
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
Added some number formatting capability #1
Conversation
All original tests now pass, plus new tests involving string formatting.
Thanks for the pull request, Ted. This functionality will make a nice addition. :) I'll review the changes now for style issues; I probably won't have time to review the pull request in depth until the weekend. |
@@ -7,6 +7,16 @@ When `format` is invoked on a string, placeholders within the string are | |||
replaced with values determined by the arguments provided. A placeholder | |||
is a sequence of characters beginning with `{` and ending with `}`. | |||
|
|||
## About this Fork | |||
dchamber's original version implemented nested variable interpolation, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be davidchambers's
(according to the Chicago Manual of Style). :D
David, Thank you for reviewing my work, and bearing with my on style issues as this is my first adventure in Coffeescript. I've pushed two commits to my master that address your comments and make a few other changes for tidiness, consistency, and style. Tests still pass. |
Thanks, Ted. I look forward to familiarizing myself with this "mini-language" and reviewing these changes in earnest. |
|
||
it "correctly formats floats", -> | ||
'{:0}'.format(1.2345).should.equal '1.2345' | ||
'{:03.2f}'.format(1.2345).should.equal '001.23' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python (2.7.2) behaves differently:
>>> '{:03.2f}'.format(1.2345)
'1.23'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. It helps to actually test against the python behavior. Fixed and added some additional tests.
Were you able to find comprehensive string formatting tests in Python's source code? I had a look, but the test cases I found in various files are not comprehensive, even collectively. |
More comprehensive tests based on actual Python behavior
The tests in cpython relevant to the string.format() method seem to live here: They don't appear to be comprehensive enough to cover the numerical format spec "mini-language". |
Hi, davidchambers.
I added some functionality to string-format that allows you to specify number sign, float precision, and field padding.
Your tests pass and I added a few of my own. Any interest in merging this?
It now has the regexp-fu to parse everything in the python string format mini-language, although it doesn't implement absolutely everything yet. I implemented what I needed for the project I was working on. Perhaps someone else or a future me will be motivated to finish the job.
If you do decide to merge, you will want to change the part in the readme about this being a fork.
Cheers,
Ted Scharff