-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_quotes.c
75 lines (65 loc) · 1.58 KB
/
test_quotes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <criterion/criterion.h>
#include <criterion/new/assert.h>
#include "expansion.h"
void setup(void)
{
extern char **environ;
init_environ(environ);
ft_setenv("var1", "value1");
ft_setenv("var2", "value2");
ft_setenv("var3", "value3");
}
void teardown(void)
{
free_environ();
}
Test(quotes, split_quotes, .init = setup, .fini = teardown,
.description = "Separates the string in quotes")
{
t_list *list;
char *expected;
char *string;
string = "var1'var2'\"var3\"";
list = split_quotes(string);
expected = list->content;
cr_assert(eq(str, "var1", expected));
list = list->next;
expected = list->content;
cr_assert(eq(str, "'var2'", expected));
list = list->next;
expected = list->content;
cr_assert(eq(str, "\"var3\"", expected));
ft_lstclear(&list, free);
}
Test(quotes, unquote, .init = setup, .fini = teardown,
.description = "Expand and remove quotes")
{
t_list *list;
char *result;
char *expected;
char *string;
string = "'sapien'\"pellentesque\"'habitant'";
list = split_quotes(string);
unquote(list);
result = concatenate(list);
expected = "sapienpellentesquehabitant";
cr_assert(eq(str, result, expected));
ft_lstclear(&list, free);
free(result);
}
Test(quotes, concatenate, .init = setup, .fini = teardown,
.description = "Concatenate quotes")
{
t_list *list;
char *result;
char *expected;
char *string;
string = "$var1'$var2'\"$var3\"''\"\"";
list = split_quotes(string);
parameter_expansion(list);
unquote(list);
result = concatenate(list);
expected = "value1$var2value3";
cr_assert(eq(str, result, expected));
ft_lstclear(&list, free);
}