Fix spurious test failures

The accepted child element types are stored in a hash map, so sort them
as part of the error message.
This commit is contained in:
Simon Hausmann 2020-07-07 18:21:59 +02:00
parent 89a05245f9
commit f03ba40d50
2 changed files with 6 additions and 5 deletions

View file

@ -6,7 +6,7 @@ TestCase := Rectangle {
LineTo { x: 100; y: 0; }
LineTo { x: 100; y: 0; }
Rectangle {}
// ^error{Rectangle is not allowed within Path. Only LineTo ArcTo are valid children}
// ^error{Rectangle is not allowed within Path. Only ArcTo LineTo are valid children}
}
LineTo { x: 100; y: 0; }

View file

@ -117,14 +117,15 @@ impl Type {
return Ok(child_type.clone());
}
if builtin.disallow_global_types_as_child_elements {
let mut valid_children: Vec<_> =
builtin.additional_accepted_child_types.keys().cloned().collect();
valid_children.sort();
return Err(format!(
"{} is not allowed within {}. Only {} are valid children",
name,
builtin.class_name,
builtin
.additional_accepted_child_types
.keys()
.fold(String::new(), |children, ty| children + ty + " ")
valid_children.join(" ")
));
}
}