56 lines
1.1 KiB
C
56 lines
1.1 KiB
C
#include <criterion/criterion.h>
|
|
#include <criterion/new/assert.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "lexer/lexer.h"
|
|
|
|
TestSuite(token_creation);
|
|
|
|
Test(token_creation, basic)
|
|
{
|
|
char input[] = "Hello World";
|
|
|
|
char actual[] = new_token(input, 5);
|
|
char expected[] = "Hello";
|
|
cr_expect(eq(str, actual, expected));
|
|
free(actual);
|
|
}
|
|
|
|
Test(token_creation, nul)
|
|
{
|
|
char input[] = NULL;
|
|
|
|
char actual[] = new_token(input, 5);
|
|
cr_expect(actual == NULL);
|
|
}
|
|
|
|
Test(token_creation, too_large)
|
|
{
|
|
char input[] = "Hel";
|
|
|
|
char actual[] = new_token(input, 5);
|
|
cr_expect(actual == NULL);
|
|
}
|
|
|
|
Test(token_creation, empty)
|
|
{
|
|
char input[] = "";
|
|
|
|
char actual[] = new_token(input, 5);
|
|
cr_expect(actual == NULL);
|
|
}
|
|
|
|
Test(token_creation, basic_long)
|
|
{
|
|
char input[] = "Hello World! This project is a mini shell, I love BIG G.";
|
|
|
|
char actual[] = new_token(input, 42);
|
|
char expected[] = calloc(42 + 1, sizeof(char));
|
|
strncpy(input, expected, 42);
|
|
cr_expect(eq(str, actual, expected));
|
|
free(actual);
|
|
free(expected);
|
|
}
|