2025-02-28 13:51:16 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
2025-03-11 15:59:59 +01:00
|
|
|
/* test_quote_removal.c :+: :+: :+: */
|
2025-02-28 13:51:16 +01:00
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2025/02/28 13:46:56 by khais #+# #+# */
|
2025-03-11 15:59:59 +01:00
|
|
|
/* Updated: 2025/03/11 16:31:50 by khais ### ########.fr */
|
2025-02-28 13:51:16 +01:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "../src/parser/remove_quotes/remove_quotes.h"
|
|
|
|
|
#include "testutil.h"
|
|
|
|
|
#include <assert.h>
|
2025-03-11 15:59:59 +01:00
|
|
|
#include <stdlib.h>
|
2025-02-28 13:51:16 +01:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-07 11:08:35 +01:00
|
|
|
static void test_quote_removal_null(void)
|
|
|
|
|
{
|
|
|
|
|
t_worddesc *word = NULL;
|
|
|
|
|
t_worddesc *got_word = remove_quotes(word);
|
|
|
|
|
assert(got_word == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 14:09:56 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 14:13:50 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-07 11:23:04 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-28 13:51:16 +01:00
|
|
|
int main(void) {
|
|
|
|
|
test_quote_removal_no_quotes_single_word();
|
2025-03-07 11:08:35 +01:00
|
|
|
test_quote_removal_null();
|
2025-02-28 14:09:56 +01:00
|
|
|
test_quote_removal_single_quotes();
|
|
|
|
|
test_quote_removal_double_quotes();
|
2025-02-28 14:13:50 +01:00
|
|
|
test_quote_removal_mixed_single_in_double();
|
|
|
|
|
test_quote_removal_mixed_double_in_single();
|
2025-03-07 11:23:04 +01:00
|
|
|
test_quote_removal_middle_of_word();
|
|
|
|
|
test_quote_removal_nested_middle_of_word();
|
2025-02-28 13:51:16 +01:00
|
|
|
return (0);
|
|
|
|
|
}
|