From: Axy Date: Fri, 31 Oct 2025 22:10:39 +0000 (+0100) Subject: Tests and slight behaviour change X-Git-Tag: Testable~3 X-Git-Url: https://git.uwuaxy.net/?a=commitdiff_plain;h=c6f7cebae5b46d1fc487bf113a498e95f1b7d8e4;p=axy%2Fft%2Fft_printf.git Tests and slight behaviour change --- diff --git a/ft_printf.c b/ft_printf.c index d22b9f9..d743650 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,7 +6,7 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/10/29 14:24:47 by agilliar #+# #+# */ -/* Updated: 2025/10/31 17:45:11 by agilliar ### ########.fr */ +/* Updated: 2025/10/31 23:10:28 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -252,7 +252,9 @@ int ft_putformat_scalar(const t_format *format, t_step_arg arg, bool sim) sign = ft_putsign(format, arg, sim); if (sign == -1) return (-1); - prefix = ft_putprefix(format, sim); + prefix = 0; + if (ft_int_arg_abs(format, arg) != 0) + prefix = ft_putprefix(format, sim); if (prefix == -1) return (-1); core = ft_put_uintptr(ft_uintptr_format_new(format), @@ -469,11 +471,14 @@ int ft_printf(const char *s, ...) } #include +#include -#define TEST_PRINTF(...) {int r1 = printf(__VA_ARGS__); int r2 = ft_printf(__VA_ARGS__); if (r1 != r2) fprintf(stderr, "printf failed, r1: %i, r2: %i\n", r1, r2); } +#define TEST_PRINTF(...) {int r1 = printf(__VA_ARGS__); int r2 = ft_printf(__VA_ARGS__); if (r1 != r2) {fprintf(stderr, "printf failed, r1: %i, r2: %i\n", r1, r2); res = 1;}} int main(void) { + int res = 0; + const void *test_ptr = "test"; TEST_PRINTF("this %corks\n", 'w'); TEST_PRINTF("this %3corks\n", 'w'); TEST_PRINTF("this %s\n", "is awesome"); @@ -484,18 +489,52 @@ int main(void) TEST_PRINTF("this %1.6s\n", "is awesome"); TEST_PRINTF("this %.6s\n", NULL); TEST_PRINTF("this %p\n", NULL); - TEST_PRINTF("this %-20p a\n", "test"); - TEST_PRINTF("this %20p a\n", "test"); + TEST_PRINTF("this %0p\n", test_ptr); + TEST_PRINTF("this %-24p a\n", test_ptr); + TEST_PRINTF("this %24p a\n", test_ptr); TEST_PRINTF("this %i a\n", 12); TEST_PRINTF("this %d a\n", 12); - TEST_PRINTF("this %-10d a\n", 12); - TEST_PRINTF("this %-10.5d a\n", 12); - TEST_PRINTF("this % 10.5d a\n", 12); + TEST_PRINTF("this %i a\n", INT_MAX); + TEST_PRINTF("this %d a\n", INT_MIN); + TEST_PRINTF("this %.0i a\n", 0); + TEST_PRINTF("this %5.0d a\n", 0); + TEST_PRINTF("this %#-10i a\n", 12); + TEST_PRINTF("this %#-10.5d a\n", 12); + TEST_PRINTF("this % 10.5i a\n", 12); TEST_PRINTF("this % 10.5d a\n", -123); - TEST_PRINTF("this % .5d a\n", 12); + TEST_PRINTF("this % .5i a\n", 12); TEST_PRINTF("this %+10.5d a\n", 12); - TEST_PRINTF("this %+10.5d a\n", -123); + TEST_PRINTF("this %+10.5i a\n", -123); TEST_PRINTF("this %010.5d a\n", 12); - TEST_PRINTF("this %0-10.5d a\n", 12); - TEST_PRINTF("%s%p\n", "this ptr is: ", "heyo"); + TEST_PRINTF("this %0-10.5i a\n", 12); + TEST_PRINTF("this %020u a\n", UINT_MAX); + TEST_PRINTF("this %.0u a\n", 0); + TEST_PRINTF("this %-10.0u a\n", 15); + TEST_PRINTF("this %020x a\n", UINT_MAX); + TEST_PRINTF("this %.0x a\n", 0); + TEST_PRINTF("this %-10.0x a\n", 15); + TEST_PRINTF("this %020X a\n", UINT_MAX); + TEST_PRINTF("this %.0X a\n", 0); + TEST_PRINTF("this %-10.0X a\n", 15); + TEST_PRINTF("this %#020u a\n", UINT_MAX); + TEST_PRINTF("this %#.0u a\n", 0); + TEST_PRINTF("this %#-10.0u a\n", 15); + TEST_PRINTF("this %#020x a\n", UINT_MAX); + TEST_PRINTF("this %#.0x a\n", 0); + TEST_PRINTF("this %#-10.0x a\n", 15); + TEST_PRINTF("this %#020X a\n", UINT_MAX); + TEST_PRINTF("this %#.0X a\n", 0); + TEST_PRINTF("this %#-10.0X a\n", 15); + TEST_PRINTF("this %+#020u a\n", UINT_MAX); + TEST_PRINTF("this %+#.0u a\n", 0); + TEST_PRINTF("this %+#-10.0u a\n", 15); + TEST_PRINTF("this %+#020x a\n", UINT_MAX); + TEST_PRINTF("this %+#.0x a\n", 0); + TEST_PRINTF("this %+#-10.0x a\n", 15); + TEST_PRINTF("this %+#020X a\n", UINT_MAX); + TEST_PRINTF("this %+#.0X a\n", 0); + TEST_PRINTF("this %+#-10.0X a\n", 15); + TEST_PRINTF("%% hai %15s%05i\n", "this num is: ", 621); + + return res; }