]> Untitled Git - axy/ft/ft_printf.git/commitdiff
Tests and slight behaviour change
authorAxy <gilliardmarthey.axel@gmail.com>
Fri, 31 Oct 2025 22:10:39 +0000 (23:10 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Fri, 31 Oct 2025 22:10:39 +0000 (23:10 +0100)
ft_printf.c

index d22b9f91a76ccfd4d7243d4b6e60e1b76f5d311d..d743650c9fa1c8477a989523b8d0eb348519dd29 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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 <stdio.h>
+#include <limits.h>
 
-#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;
 }