RsvgLength::check_nonnegative(): New method

parent 55dae39a
......@@ -190,6 +190,14 @@ impl RsvgLength {
Ok (length)
}
pub fn check_nonnegative (&self) -> Result <RsvgLength, AttributeError> {
if self.length >= 0.0 {
Ok (*self)
} else {
Err (AttributeError::Value ("value must be non-negative".to_string ()))
}
}
pub fn normalize (&self, draw_ctx: *const RsvgDrawingCtx) -> f64 {
match self.unit {
LengthUnit::Default => {
......@@ -425,4 +433,10 @@ mod tests {
// to move this test to that type later.
assert! (is_parse_error (&RsvgLength::parse ("furlong", LengthDir::Both)));
}
#[test]
fn check_nonnegative_works () {
assert! (RsvgLength::parse ("0", LengthDir::Both).and_then (|l| l.check_nonnegative ()).is_ok ());
assert! (RsvgLength::parse ("-10", LengthDir::Both).and_then (|l| l.check_nonnegative ()).is_err ());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment