@@ -63,6 +63,70 @@ static void t_string_list_split(const char *data, const char *delim, int maxspli
6363 string_list_clear (& list , 0 );
6464}
6565
66+ static void t_string_list_split_f (const char * data , const char * delim ,
67+ int maxsplit , unsigned flags , ...)
68+ {
69+ struct string_list expected_strings = STRING_LIST_INIT_DUP ;
70+ struct string_list list = STRING_LIST_INIT_DUP ;
71+ va_list ap ;
72+ int len ;
73+
74+ va_start (ap , flags );
75+ t_vcreate_string_list_dup (& expected_strings , 0 , ap );
76+ va_end (ap );
77+
78+ string_list_clear (& list , 0 );
79+ len = string_list_split_f (& list , data , delim , maxsplit , flags );
80+ cl_assert_equal_i (len , expected_strings .nr );
81+ t_string_list_equal (& list , & expected_strings );
82+
83+ string_list_clear (& expected_strings , 0 );
84+ string_list_clear (& list , 0 );
85+ }
86+
87+ void test_string_list__split_f (void )
88+ {
89+ t_string_list_split_f ("::foo:bar:baz:" , ":" , -1 , 0 ,
90+ "" , "" , "foo" , "bar" , "baz" , "" , NULL );
91+ t_string_list_split_f (" foo:bar : baz" , ":" , -1 , STRING_LIST_SPLIT_TRIM ,
92+ "foo" , "bar" , "baz" , NULL );
93+ t_string_list_split_f (" a b c " , " " , 1 , STRING_LIST_SPLIT_TRIM ,
94+ "a" , "b c" , NULL );
95+ }
96+
97+ static void t_string_list_split_in_place_f (const char * data_ , const char * delim ,
98+ int maxsplit , unsigned flags , ...)
99+ {
100+ struct string_list expected_strings = STRING_LIST_INIT_DUP ;
101+ struct string_list list = STRING_LIST_INIT_NODUP ;
102+ char * data = xstrdup (data_ );
103+ va_list ap ;
104+ int len ;
105+
106+ va_start (ap , flags );
107+ t_vcreate_string_list_dup (& expected_strings , 0 , ap );
108+ va_end (ap );
109+
110+ string_list_clear (& list , 0 );
111+ len = string_list_split_in_place_f (& list , data , delim , maxsplit , flags );
112+ cl_assert_equal_i (len , expected_strings .nr );
113+ t_string_list_equal (& list , & expected_strings );
114+
115+ free (data );
116+ string_list_clear (& expected_strings , 0 );
117+ string_list_clear (& list , 0 );
118+ }
119+
120+ void test_string_list__split_in_place_f (void )
121+ {
122+ t_string_list_split_in_place_f ("::foo:bar:baz:" , ":" , -1 , 0 ,
123+ "" , "" , "foo" , "bar" , "baz" , "" , NULL );
124+ t_string_list_split_in_place_f (" foo:bar : baz" , ":" , -1 , STRING_LIST_SPLIT_TRIM ,
125+ "foo" , "bar" , "baz" , NULL );
126+ t_string_list_split_in_place_f (" a b c " , " " , 1 , STRING_LIST_SPLIT_TRIM ,
127+ "a" , "b c" , NULL );
128+ }
129+
66130void test_string_list__split (void )
67131{
68132 t_string_list_split ("foo:bar:baz" , ":" , -1 , "foo" , "bar" , "baz" , NULL );
0 commit comments