42_minishell/libtf/dev/printf.c
2024-04-23 14:55:47 +02:00

105 lines
2.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/16 17:55:23 by mcolonna #+# #+# */
/* Updated: 2024/02/12 13:03:35 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "libtf.h"
#define TEST(...)\
test(printf(__VA_ARGS__)); \
test(tf_printf(__VA_ARGS__)); \
printf("---\n");
void title(const char *str)
{
fflush(stdout);
while (str[0] == '\t')
{
printf(" ");
str = str + 1;
}
printf("\e[3m %s \e[0m\n", str);
fflush(stdout);
}
void test(int r)
{
fflush(stdout);
printf(" (%d)\n", r);
fflush(stdout);
}
int main(void)
{
int p;
void* n = NULL;
title("Basic strings");
TEST("Hello world!");
TEST("he");
TEST("YEYEYEYEYEYEEY");
title("All conversions");
title("\t%c");
TEST("%c", '4');
TEST("%c", '#');
TEST("%c", '\0');
title("\t%s");
TEST("%s", "42");
TEST("%s", "");
TEST("%s", (char *)n);
title("\t%p");
TEST("%p", &p);
TEST("%p", n);
TEST("%p", n - 42);
title("\t%d");
TEST("%d", 42);
TEST("%d", 393820202);
TEST("%d", 0);
TEST("%d", -42);
TEST("%d", -3838383);
title("\t%i");
TEST("%i", 42);
TEST("%i", 393820202);
TEST("%i", 0);
TEST("%i", -42);
TEST("%i", -3838383);
title("\t%u");
TEST("%u", 42);
TEST("%u", 0);
TEST("%u", 3893838);
title("\t%x");
TEST("%x", 42);
TEST("%x", 0);
TEST("%x", 3893838);
title("\t%X");
TEST("%X", 42);
TEST("%X", 0);
TEST("%X", 3893838);
title("\t%%");
TEST("%%");
title("Combinations");
TEST("The %d %s!", 42, "School");
TEST("%d + %d + %d", 1, 1, 3);
TEST("%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
'T', 'h', 'e', ' ',
'4', '2', ' ',
'S', 'c', 'h', 'o', 'o', 'l', '!');
TEST("%c%c = %s = %d = %i", '4', '2', "42", 42, 42);
TEST("%p / %p", &p, n);
TEST("%i = %u = %d = %X = %x", 42, 42, 42, 42, 42);
TEST("%i = %d", -42, -42);
TEST("%d%% < %d%%", 99, 100);
TEST("%c %s %p %d %i %u %x %X %%", '4', "42", n + 42, 42, 42, 42, 42, 42);
TEST("%c %s %p %d %i %u %x %X %%", '\0', (char *)n, n, 0, 0, 0, 0, 0);
}