1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00
Commit graph

67 commits

Author SHA1 Message Date
Dorian Peron
6e23d4e979 tests: patch tests to simplify imports 2025-07-01 03:36:46 +02:00
Teemu Pätsi
cf7255f085
printf: Test formatting hex with padding 2025-06-15 00:36:38 +03:00
Justin Tracey
27487be267
printf: use non-zero indexes 2025-04-28 14:06:12 -04:00
Joseph Jon Booker
7f98d98472 printf: Add indexing to format strings 2025-04-24 22:11:49 -05:00
Sylvestre Ledru
af577e7a14
printf: support for extract chars
Should fix tests/printf/printf-mb.sh
2025-04-18 00:39:13 -04:00
Sylvestre Ledru
e5980d4d2a
printf: simplify and dedup some tests 2025-04-18 00:38:57 -04:00
Sylvestre Ledru
8ff0db1db9
printf: Improve support for printing multi-byte values of characters 2025-04-18 00:38:48 -04:00
Nicolas Boichat
fce9f79618 tests: printf: Add more cases around 0, missing digits, etc. 2025-04-15 20:59:35 +02:00
Joseph Jon Booker
9f1e7a2075 printf: Add integration test for %q '' 2025-04-12 21:44:06 -05:00
Joseph Jon Booker
7df22051ea printf: Ignore thousand seperator flag 2025-04-11 23:17:50 -05:00
Joseph Jon Booker
ef7a8c300e printf: add error handling to escaped unicode characters 2025-04-11 23:17:50 -05:00
Sylvestre Ledru
a89fc48388
Merge pull request #7656 from eduardorittner/main
printf: make negative values wrap around with unsigned/hex format
2025-04-10 06:48:50 -04:00
eduardorittner
36ef5010e3 printf: make negative values wrap around with unsigned/hex format
To convert from negative to unsigned with overflow, we get the two's complement
representation of the absolute (unsigned) value.
2025-04-06 18:58:56 -03:00
Joseph Jon Booker
6061b67601 printf: add tests for different octal lengths 2025-04-05 02:02:33 -05:00
Joseph Jon Booker
95e5396c4c printf: Consistently handle negative widths/precision
Also allows character constants with " instead of ', and for
interpolated values with %b to use \0XXX notation for octal bytes
2025-04-05 02:02:31 -05:00
Nicolas Boichat
8cf4da0b19 uucore: format: Fix hexadecimal default format print
The default hex format, on x86(-64) prints 15 digits after the
decimal point, _but_ also trims trailing zeros, so it's not just
a simple default precision and a little bit of extra handling is
required.

Also add a bunch of tests.

Fixes #7364.
2025-04-01 15:04:47 +02:00
Nicolas Boichat
1e104b7ef9 uucore: format: num_parser: Add value to Overflow error
When parsing integers, we should still return the min/max value
of the type (depending on the type), and wrap that in the error.

We need to refactor the map function to handle this case better,
and add an extract function to get the value out of an error
(if any).

This fixes the integer part of #7508.
2025-04-01 11:20:17 +02:00
Nicolas Boichat
b5a658528b uucore: format: Use ExtendedBigDecimal in argument code
Provides arbitrary precision for float parsing in printf.

Also add a printf test for that.
2025-03-31 10:04:08 +02:00
Sylvestre Ledru
a0179ea239 uutests: adjust the tests to use them 2025-03-28 21:40:31 +01:00
Dan Robertson
1a0bc30f17 printf: trim leading whitespace when parsing numeric values
Trim leading whitespace from numeric input to printf.
2025-03-24 16:27:58 +00:00
Nicolas Boichat
25c492ee19 uucore: format: Pad non-finite numbers with spaces, not zeros
`printf "%05.2f" inf` should print `  inf`, not `00inf`.

Add a test to cover that case, too.
2025-03-22 21:13:18 +01:00
Nicolas Boichat
0c0d119413 test: printf: Add a test for scientific printing of negative number
This was broken before the last few commits.
2025-03-14 12:42:00 +01:00
Nicolas Boichat
92a291b71d test: printf: Add nan, inf, negative zero
Add a few end-to-end tests for printf of unusual floats (nan,
infinity, negative zero).
2025-03-14 12:42:00 +01:00
Dorian Peron
cd1e764581 test(printf): Add test for escaped octal then newline 2025-03-10 16:25:02 +01:00
Daniel Hofstetter
df4dfea852 tests: replace run() with succeeds() or fails() 2025-03-09 16:53:56 +01:00
Sylvestre Ledru
18cb7dcf9e Use the new function fails_with_code
Done with
```
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs
$ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs
...
```
2025-03-01 17:26:20 +01:00
Sylvestre Ledru
717a6921fc
Merge pull request #7246 from RenjiSann/printf-negative-asterisk
printf: negative asterisk param changes alignment
2025-02-02 23:13:56 +01:00
Jeffrey Finkelstein
db280b6e9f printf: error on missing hexadecial escape value
Change `printf` to correctly terminate with an error message when an
escape sequence starts with `\x` but doesn't include a literal
hexadecimal value after. For example, before this commit,

    printf '\x'

would output `\x`, but after this commit, it terminates with an error
message,

    printf: missing hexadecimal number in escape

Fixes #7097
2025-02-02 11:07:31 -05:00
Dorian Peron
707e346b84 printf: negative asterisk param changes alignement 2025-01-31 16:50:26 +01:00
Dorian Peron
ae6cb8fed3 printf: show warning message in case of excess arguments 2025-01-29 14:01:35 +01:00
Alexander Shirokov
4c330d43ba
uucore:format:fix floating-point rounding
This change resolves issues with exponent calculation and usage,
ensuring more accurate formatting:

- Exponent for negative values can differ from 0
- Switching to decimal mode now follows the P > X ≥ −4 rule
2024-12-31 13:19:43 +01:00
kf zheng
a77848fb83
printf: Fix extra padding (#6548) 2024-07-13 10:19:01 +02:00
kf zheng
e6b6b2761b
printf: Check precision before writing into stdout (#6511)
* Add a new error type InvalidPrecision

* check if the precision is valid before writing to stdout when it is signedInt, unsigned, or float

* add tests for invalid precision check

* add tests for invalid precision check

* fix possible cross-platform issue that code failing to pass on some tests

* uucore/format: inline var in format string

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2024-07-01 15:15:32 +02:00
Ben Wiederhake
289346a4ba printf+tests: remove unused spell-checker:disable 2024-04-30 18:28:20 +02:00
Dorian Péron
58ee0ce427 tests/printf: Verify the correct error behavior of printf when provided with '%0c' or '%0s' 2024-03-01 00:02:31 +01:00
Dorian Péron
42cde767d2 printf: Change get_char and write_padded to handle bytes instead of chars 2024-02-29 00:59:08 +01:00
Dorian Péron
5d74a6e002 tests/printf: Fix char_as_byte test, add char and string padding tests 2024-02-29 00:43:47 +01:00
Terts Diepraam
3126e5f8a1 printf: fix padding and prefixes for unsigned ints 2024-02-09 13:28:18 +01:00
Terts Diepraam
4dae902429 printf: pad octal numbers with zeros on the left 2024-02-09 13:28:18 +01:00
Sylvestre Ledru
4557821adf
Merge branch 'main' into fix-printf-hex-alternate-zero 2024-01-15 10:41:09 +01:00
Sudhakar Verma
2aa8a3502f printf : no infinite loop 2024-01-12 16:08:47 +05:30
Sylvestre Ledru
edb77b8d59
Merge pull request #5827 from samueltardieu/issue-5826
printf: %c prints the first byte of its argument
2024-01-12 00:25:32 +01:00
Samuel Tardieu
47e908bc6c printf: output of double-quote should not be escaped
This is obtained by escaping the sequence `\"` as `"`.
2024-01-10 19:17:42 +01:00
Samuel Tardieu
7d32e49fb9 printf: %c prints the first byte of its argument 2024-01-10 18:19:56 +01:00
Marras Antoine
3b884966ac printf: added failing tests on alternative hex form 2024-01-10 16:55:03 +01:00
Samuel Tardieu
a85a792c88 format: use the new number parser and fix the error messages
The error messages are more compliant with GNU coreutils.
Also, floating hexadecimal numbers are now supported in
`printf`.
2024-01-10 14:34:43 +01:00
Samuel Tardieu
5dfeca9ff2 format: %c prints the first character of a string 2024-01-09 00:13:54 +01:00
Terts Diepraam
0822511fdc test/printf: ignoring rounding up to 2
This is a limitation of the current implementation, which should ultimately use "long double" precision instead of f64.
2023-11-21 16:49:20 +01:00
Terts Diepraam
6d2698b802 Merge branch 'main' into printf-rewrite 2023-11-20 13:53:11 +01:00
Terts Diepraam
ce18e0ab97 printf: ignore hexadecimal floats test
This can be un-ignored when it is implemented
2023-11-17 14:47:41 +01:00