2026-01-08 15:58:24 +01:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
#include <criterion/new/assert.h>
|
2026-01-08 17:03:52 +01:00
|
|
|
#include <stddef.h>
|
2026-01-08 15:58:24 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2026-01-08 17:03:52 +01:00
|
|
|
#include <sys/types.h>
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
#include "io_backend/io_backend.h"
|
2026-01-17 19:11:55 +01:00
|
|
|
#include "lexer/lexer.h"
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
TestSuite(peek_token);
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
Test(peek_token, basic_empty)
|
2026-01-08 15:58:24 +01:00
|
|
|
{
|
2026-01-17 17:53:37 +01:00
|
|
|
// simulates input
|
|
|
|
|
char command[] = "";
|
2026-01-17 19:11:55 +01:00
|
|
|
struct iob_context context = { IOB_MODE_CMD, command };
|
2026-01-17 17:53:37 +01:00
|
|
|
iob_init(&context);
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-23 20:31:49 +01:00
|
|
|
struct lexer_context ctx = { .end_previous_token = NULL,
|
|
|
|
|
.remaining_chars = 0,
|
|
|
|
|
.only_digits = false,
|
|
|
|
|
.previous_token = NULL,
|
|
|
|
|
.current_token = NULL };
|
|
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
// test
|
2026-01-23 20:31:49 +01:00
|
|
|
struct token *tok = peek_token(&ctx);
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
// expected
|
|
|
|
|
enum token_type type_expected = TOKEN_EOF;
|
|
|
|
|
char *string_expected = NULL;
|
|
|
|
|
|
2026-01-23 20:31:49 +01:00
|
|
|
cr_assert(tok->data == string_expected);
|
2026-01-17 17:53:37 +01:00
|
|
|
cr_assert(type_expected == tok->type);
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
free_token(&tok);
|
2026-01-08 15:58:24 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
Test(peek_token, basic_word)
|
2026-01-08 15:58:24 +01:00
|
|
|
{
|
2026-01-17 17:53:37 +01:00
|
|
|
// simulates input
|
|
|
|
|
char command[] = "hello";
|
2026-01-17 19:11:55 +01:00
|
|
|
struct iob_context context = { IOB_MODE_CMD, command };
|
2026-01-17 17:53:37 +01:00
|
|
|
iob_init(&context);
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-23 20:31:49 +01:00
|
|
|
struct lexer_context ctx = { .end_previous_token = NULL,
|
|
|
|
|
.remaining_chars = 0,
|
|
|
|
|
.only_digits = false,
|
|
|
|
|
.previous_token = NULL,
|
|
|
|
|
.current_token = NULL };
|
|
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
// test
|
2026-01-23 20:31:49 +01:00
|
|
|
struct token *tok = peek_token(&ctx);
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
// expected
|
|
|
|
|
enum token_type type_expected = TOKEN_WORD;
|
|
|
|
|
char string_expected[] = "hello";
|
2026-01-08 15:58:24 +01:00
|
|
|
|
2026-01-17 17:53:37 +01:00
|
|
|
cr_assert(eq(str, string_expected, tok->data));
|
|
|
|
|
cr_assert(type_expected == tok->type);
|
|
|
|
|
free_token(&tok);
|
2026-01-23 20:31:49 +01:00
|
|
|
}
|