Fix css parser tests

Parsing a shorthand background property was running into unexpected
errors when trying position values where there were none. To fix this,
introduce a try_parse variant of the position parse function that
silently returns NULL.
This commit is contained in:
Matthias Clasen 2012-10-16 06:00:40 -04:00
parent f9dae1d526
commit 4e09e180e4
3 changed files with 23 additions and 7 deletions

View File

@ -173,8 +173,8 @@ _gtk_css_position_value_new (GtkCssValue *x,
return result;
}
GtkCssValue *
_gtk_css_position_value_parse (GtkCssParser *parser)
static GtkCssValue *
position_value_parse (GtkCssParser *parser, gboolean try)
{
static const struct {
const char *name;
@ -225,7 +225,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
}
else
{
_gtk_css_parser_error (parser, "Unrecognized position value");
if (!try)
_gtk_css_parser_error (parser, "Unrecognized position value");
return NULL;
}
}
@ -245,7 +246,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
{
if (missing != &y)
{
_gtk_css_parser_error (parser, "Invalid combination of values");
if (!try)
_gtk_css_parser_error (parser, "Invalid combination of values");
_gtk_css_value_unref (y);
return NULL;
}
@ -269,7 +271,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
if ((names[first].horizontal && !names[second].vertical) ||
(!names[first].horizontal && !names[second].horizontal))
{
_gtk_css_parser_error (parser, "Invalid combination of values");
if (!try)
_gtk_css_parser_error (parser, "Invalid combination of values");
_gtk_css_value_unref (x);
_gtk_css_value_unref (y);
return NULL;
@ -279,6 +282,18 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
return _gtk_css_position_value_new (x, y);
}
GtkCssValue *
_gtk_css_position_value_parse (GtkCssParser *parser)
{
return position_value_parse (parser, FALSE);
}
GtkCssValue *
_gtk_css_position_value_try_parse (GtkCssParser *parser)
{
return position_value_parse (parser, TRUE);
}
double
_gtk_css_position_value_get_x (const GtkCssValue *position,
double one_hundred_percent)

View File

@ -26,8 +26,9 @@
G_BEGIN_DECLS
GtkCssValue * _gtk_css_position_value_new (GtkCssValue *x,
GtkCssValue *y);
GtkCssValue *y);
GtkCssValue * _gtk_css_position_value_parse (GtkCssParser *parser);
GtkCssValue * _gtk_css_position_value_try_parse (GtkCssParser *parser);
double _gtk_css_position_value_get_x (const GtkCssValue *position,
double one_hundred_percent);

View File

@ -484,7 +484,7 @@ parse_one_background (GtkCssShorthandProperty *shorthand,
values[0] = _gtk_css_image_value_new (image);
}
else if (values[1] == NULL &&
(value = _gtk_css_position_value_parse (parser)))
(value = _gtk_css_position_value_try_parse (parser)))
{
values[1] = value;
value = NULL;