diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-04-26 22:45:14 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-04-26 22:45:14 +0200 |
commit | 484aa35716d3fb627245834cb15b106e88a4bda6 (patch) | |
tree | e74dfee0566db98f0ca78a922604de462593abc5 | |
parent | d79423f2cfe1db48300d1d3aee7d82f83ffa9f05 (diff) |
[Lexer] Fix color parsing.
-rw-r--r-- | lexer/theme-lexer.l | 12 | ||||
-rw-r--r-- | test/theme-parser-test.c | 129 |
2 files changed, 135 insertions, 6 deletions
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index c6a7795f..ccd08976 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -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; } diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 1846a57c..d9ce8132 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -350,6 +350,135 @@ int main ( int argc, char ** argv ) } { 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"); TASSERT ( error == 0 ); TASSERT ( rofi_theme != NULL ); |