86 lines
2.3 KiB
C
86 lines
2.3 KiB
C
#include "libtf.h"
|
|
#include <stdio.h>
|
|
|
|
void err(t_const_string msg)
|
|
{
|
|
printf("error: %s\n", msg);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
t_memclass mc = mem_newclass(&err);
|
|
|
|
printf("Must spell 'Hello world!':\n");
|
|
t_const_string str = "Hello world!";
|
|
t_stream streaaam;
|
|
streamstr_init(&streaaam, str);
|
|
t_stream *stream = &streaaam;
|
|
while(stream_read(stream))
|
|
{
|
|
printf("read: %c\n", stream_read(stream));
|
|
printf("pop: %c\n", stream_pop(stream));
|
|
}
|
|
printf("\nChar\tw or 2?\tDigit?\tUpper?\tLower?\tAlpha?\tAlphanum?\n");
|
|
const char chars[] = {'a','w','W','2','d','{','\0'};
|
|
for (int i = 0; i < 7; i++)
|
|
printf("%c\t%i\t%i\t%i\t%i\t%i\t%i\n",
|
|
chars[i],
|
|
char_isin(chars[i], "w2"),
|
|
char_isdigit(chars[i]),
|
|
char_isupper(chars[i]),
|
|
char_islower(chars[i]),
|
|
char_isalpha(chars[i]),
|
|
char_isalphanum(chars[i])
|
|
);
|
|
|
|
printf("\nMust say nothing:\n");
|
|
stream = streamstr_alloc(&err, mc, " 98 2 ,,. 655yolo");
|
|
stream_skip(stream, " .,");
|
|
if (stream_readuint(&err, stream) != 98)
|
|
err("damn 1");
|
|
stream_skip(stream, " .,");
|
|
if (stream_readuint(&err, stream) != 2)
|
|
err("damn 2");
|
|
stream_skip(stream, " .,");
|
|
if (stream_readuint(&err, stream) != 655)
|
|
err("damn");
|
|
printf("\nMust get 2 value errors:\n");
|
|
stream_readuint(&err, stream);
|
|
stream = streamstr_alloc(&err, mc, "2878979367836578265278276537");
|
|
stream_readuint(&err, stream);
|
|
|
|
printf("\nstr to int:\n");
|
|
printf("'%s' = %i\n", "23", str_touint(&err, "23"));
|
|
printf("'%s' = %i\n", "0", str_touint(&err, "0"));
|
|
printf("bad value = ");
|
|
str_touint(&err, "-42");
|
|
printf("bad value = ");
|
|
str_touint(&err, " 17");
|
|
printf("bad value = ");
|
|
str_touint(&err, "17 ");
|
|
printf("bad value = ");
|
|
str_touint(&err, "");
|
|
printf("bad value = ");
|
|
str_touint(&err, "17b");
|
|
printf("bad value = ");
|
|
str_touint(&err, "b17");
|
|
printf("bad value = ");
|
|
str_touint(&err, "+42");
|
|
printf("'%s' = %i\n", "23", str_toint(&err, "23"));
|
|
printf("'%s' = %i\n", "0", str_toint(&err, "0"));
|
|
printf("'%s' = %i\n", "-42", str_toint(&err, "-42"));
|
|
printf("bad value = ");
|
|
str_toint(&err, " 17");
|
|
printf("bad value = ");
|
|
str_toint(&err, "17 ");
|
|
printf("bad value = ");
|
|
str_toint(&err, "");
|
|
printf("bad value = ");
|
|
str_toint(&err, "17b");
|
|
printf("bad value = ");
|
|
str_toint(&err, "b17");
|
|
printf("'%s' = %i\n", "+42", str_toint(&err, "+42"));
|
|
|
|
printf("\nMust have no leak with valgrind.\n");
|
|
mem_freeall(mc);
|
|
}
|