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

[Lexer] Fix color parsing.

This commit is contained in:
Dave Davenport 2017-04-26 22:45:14 +02:00
parent d79423f2cf
commit 484aa35716
2 changed files with 135 additions and 6 deletions

View file

@ -433,17 +433,17 @@ if ( queue == NULL ){
}
<PROPERTIES>rgba\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3},[01](\.{NUMBER}+)?\) {
char *endptr = &yytext[5];
yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10);
yylval->colorval.green= g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval->colorval.blue= g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10)/255.0;
yylval->colorval.green= g_ascii_strtoull ( endptr+1, &endptr, 10)/255.0;
yylval->colorval.blue= g_ascii_strtoull ( endptr+1, &endptr, 10)/255.0;
yylval->colorval.alpha= g_ascii_strtod ( endptr+1, NULL);
return T_COLOR;
}
<PROPERTIES>rgb\({NUMBER}{1,3},{NUMBER}{1,3},{NUMBER}{1,3}\) {
char *endptr = &yytext[4];
yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10);
yylval->colorval.green = g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval->colorval.blue = g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval->colorval.red = g_ascii_strtoull ( endptr, &endptr, 10)/255.0;
yylval->colorval.green = g_ascii_strtoull ( endptr+1, &endptr, 10)/255.0;
yylval->colorval.blue = g_ascii_strtoull ( endptr+1, &endptr, 10)/255.0;
yylval->colorval.alpha = 1.0;
return T_COLOR;
}

View file

@ -348,6 +348,135 @@ int main ( int argc, char ** argv )
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
{
rofi_theme = NULL;
error = 0;
rofi_theme_parse_string ( "* { red: #FF0000; green: #00FF00; blue: #0000FF; }");
TASSERT ( error == 0 );
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "red", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.red == 1 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "green", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 1 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "blue", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 1 );
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
{
rofi_theme = NULL;
error = 0;
rofi_theme_parse_string ( "* { red: #33FF0000; green: #2200FF00; blue: #110000FF; }");
TASSERT ( error == 0 );
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "red", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 0.2 );
TASSERT ( p->value.color.red == 1 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "green", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 1/7.5 );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 1 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "blue", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 1/15.0 );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 1 );
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
{
rofi_theme = NULL;
error = 0;
rofi_theme_parse_string ( "* { red: rgb(255,0,0); green: rgb(0,255,0); blue: rgb(0,0,255); }");
TASSERT ( error == 0 );
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "red", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.red == 1 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "green", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 1 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "blue", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 1 );
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
{
rofi_theme = NULL;
error = 0;
rofi_theme_parse_string ( "* { red: rgba(255,0,0,0.3); green: rgba(0,255,0,0.2); blue: rgba(0,0,255,0.7); }");
TASSERT ( error == 0 );
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "red", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 0.3 );
TASSERT ( p->value.color.red == 1 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "green", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 0.2 );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 1 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "blue", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 0.7 );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 1 );
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
{
rofi_theme = NULL;
error = 0;
rofi_theme_parse_string ( "* { red: argb:33FF0000; green: argb:2200FF00; blue: argb:110000FF; }");
TASSERT ( error == 0 );
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "red", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 0.2 );
TASSERT ( p->value.color.red == 1 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "green", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 1/7.5 );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 1 );
TASSERT ( p->value.color.blue == 0 );
p = rofi_theme_find_property ( twid, P_COLOR, "blue", FALSE );
TASSERT ( p != NULL );
TASSERT ( p->value.color.alpha == 1/15.0 );
TASSERT ( p->value.color.red == 0 );
TASSERT ( p->value.color.green == 0 );
TASSERT ( p->value.color.blue == 1 );
rofi_theme_free ( rofi_theme );
rofi_theme = NULL;
}
{
rofi_theme = NULL;
rofi_theme_parse_file ("/dev/null");