tests: add a test_ prefix to all files that contain actual tests

This will make it easier to differentiate with utility files, as the next change
will add sevral
This commit is contained in:
Khaïs COLIN 2025-03-11 16:05:10 +01:00
parent bc5be67bf6
commit f5ae3a5d8d
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
8 changed files with 7 additions and 7 deletions

116
tests/test_quote_removal.c Normal file
View file

@ -0,0 +1,116 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quote_removal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/28 13:46:56 by khais #+# #+# */
/* Updated: 2025/03/07 11:24:30 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "../src/parser/wordlist/wordlist.h"
#include "../src/parser/wordsplit/wordsplit.h"
#include "../src/parser/remove_quotes/remove_quotes.h"
#include "testutil.h"
#include <assert.h>
static t_worddesc *create_single_word(char *str)
{
t_wordlist *words = minishell_wordsplit(str);
assert(wordlist_get(words, 0) != NULL);
assert(wordlist_get(words, 1) == NULL);
t_worddesc *word = wordlist_pop(&words);
return (word);
}
static void test_quote_removal_no_quotes_single_word(void)
{
t_worddesc *word = create_single_word("word");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("word", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_null(void)
{
t_worddesc *word = NULL;
t_worddesc *got_word = remove_quotes(word);
assert(got_word == NULL);
}
static void test_quote_removal_single_quotes(void)
{
t_worddesc *word = create_single_word("'word'");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("word", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_double_quotes(void)
{
t_worddesc *word = create_single_word("\"word\"");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("word", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_mixed_single_in_double(void)
{
t_worddesc *word = create_single_word("\"'word'\"");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("'word'", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_mixed_double_in_single(void)
{
t_worddesc *word = create_single_word("'\"word\"'");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("\"word\"", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_middle_of_word(void)
{
t_worddesc *word = create_single_word("var='VALUE'here");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("var=VALUEhere", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_nested_middle_of_word(void)
{
t_worddesc *word = create_single_word("var=\"'VALUE'here\"");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("var='VALUE'here", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
int main(void) {
test_quote_removal_no_quotes_single_word();
test_quote_removal_null();
test_quote_removal_single_quotes();
test_quote_removal_double_quotes();
test_quote_removal_mixed_single_in_double();
test_quote_removal_mixed_double_in_single();
test_quote_removal_middle_of_word();
test_quote_removal_nested_middle_of_word();
return (0);
}