1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Add list property test, allow empty lists.

This commit is contained in:
Dave Davenport 2017-06-14 08:18:59 +02:00
parent 8f035bf919
commit 32f67ab5a5
2 changed files with 41 additions and 1 deletions

View file

@ -240,6 +240,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%type <ival> t_property_highlight_style
%type <ival> t_property_line_style
%type <list> t_property_element_list
%type <list> t_property_element_list_optional
%type <ival> t_property_orientation
%start t_entry_list
@ -372,7 +373,7 @@ t_property
$$->name = $1;
$$->value.color = $3;
}
| t_property_name T_PSEP T_LIST_OPEN t_property_element_list T_LIST_CLOSE T_PCLOSE {
| t_property_name T_PSEP T_LIST_OPEN t_property_element_list_optional T_LIST_CLOSE T_PCLOSE {
$$ = rofi_theme_property_create ( P_LIST );
$$->name = $1;
$$->value.list = $4;
@ -385,6 +386,11 @@ t_property
;
/** List of elements */
t_property_element_list_optional
: %empty { $$ = NULL; }
| t_property_element_list { $$ = $1; }
;
t_property_element_list
: T_ELEMENT { $$ = g_list_append ( NULL, $1); }
| t_property_element_list T_COMMA T_ELEMENT {

View file

@ -1078,6 +1078,34 @@ START_TEST ( test_properties_orientation_case )
}
END_TEST
START_TEST ( test_properties_list )
{
widget wid;
wid.name = "blaat";
wid.state = NULL;
rofi_theme_parse_string ( "#blaat { liste: []; list1: [ one ]; list2: [ one, two ];}");
GList *list = rofi_theme_get_list ( &wid, "liste", NULL );
ck_assert_ptr_null ( list );
list = rofi_theme_get_list ( &wid, "list1", NULL );
ck_assert_ptr_nonnull ( list );
ck_assert_str_eq ( (char *)list->data, "one" );
g_list_free_full ( list, (GDestroyNotify)g_free);
list = rofi_theme_get_list ( &wid, "list2", NULL );
ck_assert_ptr_nonnull ( list );
ck_assert_int_eq ( g_list_length ( list ), 2 );
ck_assert_str_eq ( (char *)list->data, "one" );
ck_assert_str_eq ( (char *)list->next->data, "two" );
g_list_free_full ( list, (GDestroyNotify)g_free);
list = rofi_theme_get_list ( &wid, "blaat", "aap,noot,mies");
ck_assert_ptr_nonnull ( list );
ck_assert_int_eq ( g_list_length ( list ), 3 );
ck_assert_str_eq ( (char *)list->data, "aap" );
ck_assert_str_eq ( (char *)list->next->data, "noot" );
ck_assert_str_eq ( (char *)list->next->next->data, "mies" );
g_list_free_full ( list, (GDestroyNotify)g_free);
}
END_TEST
START_TEST ( test_configuration )
{
@ -1275,6 +1303,12 @@ static Suite * theme_parser_suite (void)
tcase_add_test ( tc_prop_orientation, test_properties_orientation_case );
suite_add_tcase(s, tc_prop_orientation );
}
{
TCase *tc_prop_list = tcase_create("Propertieslist");
tcase_add_checked_fixture(tc_prop_list, theme_parser_setup, theme_parser_teardown);
tcase_add_test ( tc_prop_list, test_properties_list);
suite_add_tcase(s, tc_prop_list );
}
{
TCase *tc_prop_configuration = tcase_create("Configuration");
tcase_add_checked_fixture(tc_prop_configuration, theme_parser_setup, theme_parser_teardown);