@@ -13,6 +13,26 @@ static void t_vcreate_string_list_dup(struct string_list *list,
13
13
string_list_append (list , arg );
14
14
}
15
15
16
+ static void t_create_string_list_dup (struct string_list * list , int free_util , ...)
17
+ {
18
+ va_list ap ;
19
+
20
+ cl_assert (list -> strdup_strings );
21
+
22
+ string_list_clear (list , free_util );
23
+ va_start (ap , free_util );
24
+ t_vcreate_string_list_dup (list , free_util , ap );
25
+ va_end (ap );
26
+ }
27
+
28
+ static void t_string_list_clear (struct string_list * list , int free_util )
29
+ {
30
+ string_list_clear (list , free_util );
31
+ cl_assert_equal_p (list -> items , NULL );
32
+ cl_assert_equal_i (list -> nr , 0 );
33
+ cl_assert_equal_i (list -> alloc , 0 );
34
+ }
35
+
16
36
static void t_string_list_equal (struct string_list * list ,
17
37
struct string_list * expected_strings )
18
38
{
@@ -90,3 +110,56 @@ void test_string_list__split_in_place(void)
90
110
t_string_list_split_in_place ("foo:;:bar:;:" , ":;" , -1 ,
91
111
"foo" , "" , "" , "bar" , "" , "" , "" , NULL );
92
112
}
113
+
114
+ static int prefix_cb (struct string_list_item * item , void * cb_data )
115
+ {
116
+ const char * prefix = (const char * )cb_data ;
117
+ return starts_with (item -> string , prefix );
118
+ }
119
+
120
+ static void t_string_list_filter (struct string_list * list , ...)
121
+ {
122
+ struct string_list expected_strings = STRING_LIST_INIT_DUP ;
123
+ const char * prefix = "y" ;
124
+ va_list ap ;
125
+
126
+ va_start (ap , list );
127
+ t_vcreate_string_list_dup (& expected_strings , 0 , ap );
128
+ va_end (ap );
129
+
130
+ filter_string_list (list , 0 , prefix_cb , (void * )prefix );
131
+ t_string_list_equal (list , & expected_strings );
132
+
133
+ string_list_clear (& expected_strings , 0 );
134
+ }
135
+
136
+ void test_string_list__filter (void )
137
+ {
138
+ struct string_list list = STRING_LIST_INIT_DUP ;
139
+
140
+ t_create_string_list_dup (& list , 0 , NULL );
141
+ t_string_list_filter (& list , NULL );
142
+
143
+ t_create_string_list_dup (& list , 0 , "no" , NULL );
144
+ t_string_list_filter (& list , NULL );
145
+
146
+ t_create_string_list_dup (& list , 0 , "yes" , NULL );
147
+ t_string_list_filter (& list , "yes" , NULL );
148
+
149
+ t_create_string_list_dup (& list , 0 , "no" , "yes" , NULL );
150
+ t_string_list_filter (& list , "yes" , NULL );
151
+
152
+ t_create_string_list_dup (& list , 0 , "yes" , "no" , NULL );
153
+ t_string_list_filter (& list , "yes" , NULL );
154
+
155
+ t_create_string_list_dup (& list , 0 , "y1" , "y2" , NULL );
156
+ t_string_list_filter (& list , "y1" , "y2" , NULL );
157
+
158
+ t_create_string_list_dup (& list , 0 , "y2" , "y1" , NULL );
159
+ t_string_list_filter (& list , "y2" , "y1" , NULL );
160
+
161
+ t_create_string_list_dup (& list , 0 , "x1" , "x2" , NULL );
162
+ t_string_list_filter (& list , NULL );
163
+
164
+ t_string_list_clear (& list , 0 );
165
+ }
0 commit comments