feat(tests): mini testsuite for token creation
This commit is contained in:
parent
92c0b5ba96
commit
e7784b8df1
1 changed files with 61 additions and 0 deletions
61
tests/unit/lexer/lexer_tests.c
Normal file
61
tests/unit/lexer/lexer_tests.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include <criterion/criterion.h>
|
||||
#include <criterion/new/assert.h>
|
||||
#include <criterion/redirect.h>
|
||||
#include <stdio.h>
|
||||
#include <string.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);
|
||||
char *expected = NULL;
|
||||
cr_expect(eq(str, actual, expected));
|
||||
free(actual);
|
||||
}
|
||||
|
||||
Test(token_creation, too_large)
|
||||
{
|
||||
char *input = "Hel";
|
||||
|
||||
char *actual = new_token(input, 5);
|
||||
char *expected = NULL;
|
||||
cr_expect(eq(str, actual, expected));
|
||||
free(actual);
|
||||
}
|
||||
|
||||
Test(token_creation, empty)
|
||||
{
|
||||
char *input = "";
|
||||
|
||||
char *actual = new_token(input, 5);
|
||||
char *expected = NULL;
|
||||
cr_expect(eq(str, actual, expected));
|
||||
free(actual);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue