summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-06-14 08:18:59 +0200
committerDave Davenport <qball@gmpclient.org>2017-06-14 08:18:59 +0200
commit32f67ab5a5a55fa6e5dc37c28f8875e1e01c6219 (patch)
tree36b9af2e060962256ff38c893a0e54f6d7780bd7
parent8f035bf9195cc350ab903939d0da3894d7bf197c (diff)
Add list property test, allow empty lists.
-rw-r--r--lexer/theme-parser.y8
-rw-r--r--test/theme-parser-test.c34
2 files changed, 41 insertions, 1 deletions
diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y
index e5a2a7ac..687a20c8 100644
--- a/lexer/theme-parser.y
+++ b/lexer/theme-parser.y
@@ -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 {
diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c
index 6c78af68..24561728 100644
--- a/test/theme-parser-test.c
+++ b/test/theme-parser-test.c
@@ -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 )
{
@@ -1276,6 +1304,12 @@ static Suite * theme_parser_suite (void)
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);
tcase_add_test ( tc_prop_configuration, test_configuration);