Add a format parameter to the Decimal type#715
Add a format parameter to the Decimal type#715saggi-dw wants to merge 1 commit intocosmocode:masterfrom
Conversation
|
LGTM. Can you fix the code sniffer issue and squash your commits? |
|
I hope that was all correct. My first question: What is squashing? 🙈 |
|
Great. One more thing: can you please extend the unit tests to cover your new setting? See https://github.com/cosmocode/dokuwiki-plugin-struct/blob/master/_test/types/DecimalTest.php |
|
OK, test failed: I will fix that. |
|
The commit message is now total crap. Unfortunately, I have no idea whether it can still be changed... |
You can do a |
_test/types/DecimalTest.php
Outdated
| ['362525200', '3.625e+8' , '-1', '.', ' ', true, '', '', false, '%.3e'], | ||
| ['362525200', '3.625E+8' , '-1', '.', ' ', true, '', '', false, '%.3E'], | ||
| ['1', '1' , '-1', '.', ' ', true, '', '', false, '%u'], | ||
| ['-1', '18446744073709551615' , '-1', '.', ' ', true, '', '', false, '%u'], |
There was a problem hiding this comment.
can you also add tests for where the format string is wrong and thus ignored?
There was a problem hiding this comment.
You are right. The - should be in the regex as a character and not as a range. By extending the test I realized that. Thank you!
There was a problem hiding this comment.
This last test looks interesting. I think it is dependent on the platform and would fail on a 32bit system
There was a problem hiding this comment.
Of course you're right again!
32bit:
php > printf('%u','-1');
4294967295
I will remove the last line of the test and adjust the penultimate one. It should only be checked whether %u is recognized.
a0656b3 to
da0a1c3
Compare
refine regex and extend test remove test of negative value for %u adjust test for %u fix %s -> %u
A user on DokuWiki Forum need a special format for numbers.
https://forum.dokuwiki.org/d/22218-how-to-force-leading-zeroes-when-using-a-bureacuracy-form-with-struct
This add a new config parameter for the Decimal type:
formatIf format is set and valid all other formatting parameters(
roundto, decpoint, thousands, trimzeros, engineering) are ignored.format must be a valid format for sprintf and accepts the following number formats:
bdeEfFu