Remove Parse's Data associated type. Yay!

This removes the mysterious "()" argument from practically all the
.parse() and .parse_str() calls.

I thought the Data associated type was a really clever idea to deal
with Length's need for a direction.  But now it turns out that it's
possible to encode that in the length types.  In any case, it made the
parse() calls that didn't need extra data quite ugly.
parent 1c2d3b8f
Pipeline #52783 passed with stages
in 27 minutes and 21 seconds
......@@ -58,10 +58,9 @@ impl Angle {
// angle ::= number ("deg" | "grad" | "rad")?
//
impl Parse for Angle {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _: ()) -> Result<Angle, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<Angle, ValueErrorKind> {
let angle = {
let token = parser
.next()
......@@ -107,21 +106,18 @@ mod tests {
#[test]
fn parses_angle() {
assert_eq!(Angle::parse_str("0", ()), Ok(Angle::new(0.0)));
assert_eq!(Angle::parse_str("15", ()), Ok(Angle::from_degrees(15.0)));
assert_eq!(Angle::parse_str("0"), Ok(Angle::new(0.0)));
assert_eq!(Angle::parse_str("15"), Ok(Angle::from_degrees(15.0)));
assert_eq!(Angle::parse_str("180.5deg"), Ok(Angle::from_degrees(180.5)));
assert_eq!(Angle::parse_str("1rad"), Ok(Angle::new(1.0)));
assert_eq!(
Angle::parse_str("180.5deg", ()),
Ok(Angle::from_degrees(180.5))
);
assert_eq!(Angle::parse_str("1rad", ()), Ok(Angle::new(1.0)));
assert_eq!(
Angle::parse_str("-400grad", ()),
Angle::parse_str("-400grad"),
Ok(Angle::from_degrees(-360.0))
);
assert!(Angle::parse_str("", ()).is_err());
assert!(Angle::parse_str("foo", ()).is_err());
assert!(Angle::parse_str("300foo", ()).is_err());
assert!(Angle::parse_str("").is_err());
assert!(Angle::parse_str("foo").is_err());
assert!(Angle::parse_str("300foo").is_err());
}
fn test_bisection_angle(
......
......@@ -183,10 +183,9 @@ fn parse_fit_mode(s: &str) -> Result<FitMode, ValueErrorKind> {
}
impl Parse for AspectRatio {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _: ()) -> Result<AspectRatio, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<AspectRatio, ValueErrorKind> {
let defer = parser.try(|p| p.expect_ident_matching("defer")).is_ok();
let align_xy = parser.try(|p| {
......@@ -220,20 +219,20 @@ mod tests {
#[test]
fn parsing_invalid_strings_yields_error() {
assert!(AspectRatio::parse_str("", ()).is_err());
assert!(AspectRatio::parse_str("defer", ()).is_err());
assert!(AspectRatio::parse_str("defer foo", ()).is_err());
assert!(AspectRatio::parse_str("defer xmidymid", ()).is_err());
assert!(AspectRatio::parse_str("defer xMidYMid foo", ()).is_err());
assert!(AspectRatio::parse_str("xmidymid", ()).is_err());
assert!(AspectRatio::parse_str("xMidYMid foo", ()).is_err());
assert!(AspectRatio::parse_str("defer xMidYMid meet foo", ()).is_err());
assert!(AspectRatio::parse_str("").is_err());
assert!(AspectRatio::parse_str("defer").is_err());
assert!(AspectRatio::parse_str("defer foo").is_err());
assert!(AspectRatio::parse_str("defer xmidymid").is_err());
assert!(AspectRatio::parse_str("defer xMidYMid foo").is_err());
assert!(AspectRatio::parse_str("xmidymid").is_err());
assert!(AspectRatio::parse_str("xMidYMid foo").is_err());
assert!(AspectRatio::parse_str("defer xMidYMid meet foo").is_err());
}
#[test]
fn parses_valid_strings() {
assert_eq!(
AspectRatio::parse_str("defer none", ()),
AspectRatio::parse_str("defer none"),
Ok(AspectRatio {
defer: true,
align: None,
......@@ -241,7 +240,7 @@ mod tests {
);
assert_eq!(
AspectRatio::parse_str("xMidYMid", ()),
AspectRatio::parse_str("xMidYMid"),
Ok(AspectRatio {
defer: false,
align: Some(Align {
......@@ -253,7 +252,7 @@ mod tests {
);
assert_eq!(
AspectRatio::parse_str("defer xMidYMid", ()),
AspectRatio::parse_str("defer xMidYMid"),
Ok(AspectRatio {
defer: true,
align: Some(Align {
......@@ -265,7 +264,7 @@ mod tests {
);
assert_eq!(
AspectRatio::parse_str("defer xMinYMax", ()),
AspectRatio::parse_str("defer xMinYMax"),
Ok(AspectRatio {
defer: true,
align: Some(Align {
......@@ -277,7 +276,7 @@ mod tests {
);
assert_eq!(
AspectRatio::parse_str("defer xMaxYMid meet", ()),
AspectRatio::parse_str("defer xMaxYMid meet"),
Ok(AspectRatio {
defer: true,
align: Some(Align {
......@@ -289,7 +288,7 @@ mod tests {
);
assert_eq!(
AspectRatio::parse_str("defer xMinYMax slice", ()),
AspectRatio::parse_str("defer xMinYMax slice"),
Ok(AspectRatio {
defer: true,
align: Some(Align {
......@@ -310,75 +309,75 @@ mod tests {
#[test]
fn aligns() {
let foo = AspectRatio::parse_str("xMinYMin meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMinYMin meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMinYMin slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMinYMin slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, 0.0, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMinYMid meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMinYMid meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMinYMid slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMinYMid slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, -49.5, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMinYMax meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMinYMax meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMinYMax slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMinYMax slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, -99.0, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMidYMin meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMidYMin meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(4.95, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMidYMin slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMidYMin slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, 0.0, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMidYMid meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMidYMid meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(4.95, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMidYMid slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMidYMid slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, -49.5, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMidYMax meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMidYMax meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(4.95, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMidYMax slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMidYMax slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, -99.0, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMaxYMin meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMaxYMin meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(9.9, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMaxYMin slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMaxYMin slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, 0.0, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMaxYMid meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMaxYMid meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(9.9, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMaxYMid slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMaxYMid slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, -49.5, 10.0, 100.0));
let foo = AspectRatio::parse_str("xMaxYMax meet", ()).unwrap();
let foo = AspectRatio::parse_str("xMaxYMax meet").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(9.9, 0.0, 0.1, 1.0));
let foo = AspectRatio::parse_str("xMaxYMax slice", ()).unwrap();
let foo = AspectRatio::parse_str("xMaxYMax slice").unwrap();
let foo = foo.compute(1.0, 10.0, 0.0, 0.0, 10.0, 1.0);
assert_quadruples_equal(&foo, &(0.0, -99.0, 10.0, 100.0));
}
......
......@@ -81,7 +81,7 @@ impl NodeTrait for NodeClipPath {
fn set_atts(&self, _: &RsvgNode, pbag: &PropertyBag<'_>) -> NodeResult {
for (attr, value) in pbag.iter() {
match attr {
Attribute::ClipPathUnits => self.units.set(attr.parse(value, ())?),
Attribute::ClipPathUnits => self.units.set(attr.parse(value)?),
_ => (),
}
}
......
......@@ -9,26 +9,18 @@ use util::utf8_cstr;
pub use cssparser::Color;
impl Parse for cssparser::Color {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data,
) -> Result<cssparser::Color, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<cssparser::Color, ValueErrorKind> {
cssparser::Color::parse(parser)
.map_err(|_| ValueErrorKind::Parse(ParseError::new("invalid syntax for color")))
}
}
impl Parse for cssparser::RGBA {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data,
) -> Result<cssparser::RGBA, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<cssparser::RGBA, ValueErrorKind> {
match cssparser::Color::parse(parser) {
Ok(cssparser::Color::RGBA(rgba)) => Ok(rgba),
Ok(cssparser::Color::CurrentColor) => Err(ValueErrorKind::Value(
......@@ -115,7 +107,7 @@ pub extern "C" fn rsvg_css_parse_color(string: *const libc::c_char) -> ColorSpec
argb: 0,
}
} else {
ColorSpec::from(<Color as Parse>::parse_str(s, ()).map(|v| Some(v)))
ColorSpec::from(<Color as Parse>::parse_str(s).map(|v| Some(v)))
}
}
......
......@@ -13,10 +13,9 @@ pub enum CoordUnits {
}
impl Parse for CoordUnits {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _: ()) -> Result<CoordUnits, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<CoordUnits, ValueErrorKind> {
let loc = parser.current_source_location();
parser
......@@ -65,14 +64,12 @@ macro_rules! coord_units {
}
impl $crate::parsers::Parse for $name {
type Data = ();
type Err = $crate::error::ValueErrorKind;
fn parse(
parser: &mut ::cssparser::Parser<'_, '_>,
_: (),
) -> Result<Self, $crate::error::ValueErrorKind> {
Ok($name($crate::coord_units::CoordUnits::parse(parser, ())?))
Ok($name($crate::coord_units::CoordUnits::parse(parser)?))
}
}
};
......@@ -86,18 +83,18 @@ mod tests {
#[test]
fn parsing_invalid_strings_yields_error() {
assert!(MyUnits::parse_str("", ()).is_err());
assert!(MyUnits::parse_str("foo", ()).is_err());
assert!(MyUnits::parse_str("").is_err());
assert!(MyUnits::parse_str("foo").is_err());
}
#[test]
fn parses_paint_server_units() {
assert_eq!(
MyUnits::parse_str("userSpaceOnUse", ()),
MyUnits::parse_str("userSpaceOnUse"),
Ok(MyUnits(CoordUnits::UserSpaceOnUse))
);
assert_eq!(
MyUnits::parse_str("objectBoundingBox", ()),
MyUnits::parse_str("objectBoundingBox"),
Ok(MyUnits(CoordUnits::ObjectBoundingBox))
);
}
......
......@@ -8,7 +8,7 @@ use drawing_ctx::DrawingCtx;
use error::NodeError;
use node::{NodeResult, NodeTrait, RsvgNode};
use number_list::{NumberList, NumberListError, NumberListLength};
use parsers::{self, Parse, ParseError};
use parsers::{self, ParseError};
use property_bag::PropertyBag;
use surface_utils::{
iterators::Pixels,
......
......@@ -8,7 +8,7 @@ use drawing_ctx::DrawingCtx;
use error::NodeError;
use node::{NodeResult, NodeTrait, NodeType, RsvgNode};
use number_list::{NumberList, NumberListError, NumberListLength};
use parsers::{self, Parse, ParseError};
use parsers::{self, ParseError};
use property_bag::PropertyBag;
use surface_utils::{
iterators::Pixels,
......
......@@ -69,7 +69,7 @@ impl NodeTrait for Composite {
Attribute::In2 => {
self.in2.replace(Some(Input::parse(Attribute::In2, value)?));
}
Attribute::Operator => self.operator.set(attr.parse(value, ())?),
Attribute::Operator => self.operator.set(attr.parse(value)?),
Attribute::K1 => self.k1.set(
parsers::number(value).map_err(|err| NodeError::attribute_error(attr, err))?,
),
......@@ -231,10 +231,9 @@ impl Filter for Composite {
}
impl Parse for Operator {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _data: Self::Data) -> Result<Self, Self::Err> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, Self::Err> {
let loc = parser.current_source_location();
parser
......
......@@ -8,7 +8,7 @@ use drawing_ctx::DrawingCtx;
use error::NodeError;
use node::{NodeResult, NodeTrait, RsvgNode};
use number_list::{NumberList, NumberListError, NumberListLength};
use parsers::{self, Parse, ParseError};
use parsers::{self, ParseError};
use property_bag::PropertyBag;
use rect::IRect;
use surface_utils::{
......
......@@ -173,7 +173,7 @@ impl NodeTrait for Image {
for (attr, value) in pbag.iter() {
match attr {
Attribute::PreserveAspectRatio => self.aspect.set(attr.parse(value, ())?),
Attribute::PreserveAspectRatio => self.aspect.set(attr.parse(value)?),
// "path" is used by some older Adobe Illustrator versions
Attribute::XlinkHref | Attribute::Path => {
......
......@@ -161,26 +161,18 @@ impl NodeTrait for Primitive {
for (attr, value) in pbag.iter() {
match attr {
Attribute::X => self.x.set(Some(attr.parse_and_validate(
value,
(),
check_units_horizontal,
)?)),
Attribute::Y => self.y.set(Some(attr.parse_and_validate(
value,
(),
check_units_vertical,
)?)),
Attribute::Width => self.width.set(Some(attr.parse_and_validate(
value,
(),
check_units_horizontal_and_ensure_nonnegative,
)?)),
Attribute::Height => self.height.set(Some(attr.parse_and_validate(
value,
(),
check_units_vertical_and_ensure_nonnegative,
)?)),
Attribute::X => self.x.set(Some(
attr.parse_and_validate(value, check_units_horizontal)?,
)),
Attribute::Y => self
.y
.set(Some(attr.parse_and_validate(value, check_units_vertical)?)),
Attribute::Width => self.width.set(Some(
attr.parse_and_validate(value, check_units_horizontal_and_ensure_nonnegative)?,
)),
Attribute::Height => self.height.set(Some(
attr.parse_and_validate(value, check_units_vertical_and_ensure_nonnegative)?,
)),
Attribute::Result => *self.result.borrow_mut() = Some(value.to_string()),
_ => (),
}
......
......@@ -24,10 +24,10 @@ impl NodeFilter {
#[inline]
pub fn new() -> Self {
Self {
x: Cell::new(LengthHorizontal::parse_str("-10%", ()).unwrap()),
y: Cell::new(LengthVertical::parse_str("-10%", ()).unwrap()),
width: Cell::new(LengthHorizontal::parse_str("120%", ()).unwrap()),
height: Cell::new(LengthVertical::parse_str("120%", ()).unwrap()),
x: Cell::new(LengthHorizontal::parse_str("-10%").unwrap()),
y: Cell::new(LengthVertical::parse_str("-10%").unwrap()),
width: Cell::new(LengthHorizontal::parse_str("120%").unwrap()),
height: Cell::new(LengthVertical::parse_str("120%").unwrap()),
filterunits: Cell::new(CoordUnits::ObjectBoundingBox),
primitiveunits: Cell::new(CoordUnits::UserSpaceOnUse),
}
......@@ -39,7 +39,7 @@ impl NodeTrait for NodeFilter {
// Parse filterUnits first as it affects x, y, width, height checks.
for (attr, value) in pbag.iter() {
match attr {
Attribute::FilterUnits => self.filterunits.set(attr.parse(value, ())?),
Attribute::FilterUnits => self.filterunits.set(attr.parse(value)?),
_ => (),
}
}
......@@ -84,25 +84,19 @@ impl NodeTrait for NodeFilter {
// Parse the rest of the attributes.
for (attr, value) in pbag.iter() {
match attr {
Attribute::X => {
self.x
.set(attr.parse_and_validate(value, (), check_units_horizontal)?)
}
Attribute::Y => {
self.y
.set(attr.parse_and_validate(value, (), check_units_vertical)?)
}
Attribute::Width => self.width.set(attr.parse_and_validate(
value,
(),
check_units_horizontal_and_ensure_nonnegative,
)?),
Attribute::Height => self.height.set(attr.parse_and_validate(
value,
(),
check_units_vertical_and_ensure_nonnegative,
)?),
Attribute::PrimitiveUnits => self.primitiveunits.set(attr.parse(value, ())?),
Attribute::X => self
.x
.set(attr.parse_and_validate(value, check_units_horizontal)?),
Attribute::Y => self
.y
.set(attr.parse_and_validate(value, check_units_vertical)?),
Attribute::Width => self.width.set(
attr.parse_and_validate(value, check_units_horizontal_and_ensure_nonnegative)?,
),
Attribute::Height => self.height.set(
attr.parse_and_validate(value, check_units_vertical_and_ensure_nonnegative)?,
),
Attribute::PrimitiveUnits => self.primitiveunits.set(attr.parse(value)?),
_ => (),
}
}
......
......@@ -59,16 +59,12 @@ impl FontSizeSpec {
}
impl Parse for FontSizeSpec {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data,
) -> Result<FontSizeSpec, ::error::ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<FontSizeSpec, ::error::ValueErrorKind> {
let parser_state = parser.state();
LengthBoth::parse(parser, ())
LengthBoth::parse(parser)
.and_then(|s| Ok(FontSizeSpec::Value(s)))
.or_else(|e| {
parser.reset(&parser_state);
......@@ -120,13 +116,9 @@ pub enum FontWeightSpec {
}
impl Parse for FontWeightSpec {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data,
) -> Result<FontWeightSpec, ::error::ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<FontWeightSpec, ::error::ValueErrorKind> {
if let Ok(r) = parser.try(|p| {
p.expect_ident()
.map_err(|_| ())
......@@ -196,16 +188,12 @@ impl LetterSpacingSpec {
}
impl Parse for LetterSpacingSpec {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data,
) -> Result<LetterSpacingSpec, ::error::ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<LetterSpacingSpec, ::error::ValueErrorKind> {
let parser_state = parser.state();
LengthHorizontal::parse(parser, ())
LengthHorizontal::parse(parser)
.and_then(|s| Ok(LetterSpacingSpec::Value(s)))
.or_else(|e| {
parser.reset(&parser_state);
......@@ -235,13 +223,9 @@ impl Parse for LetterSpacingSpec {
pub struct SingleFontFamily(pub String);
impl Parse for SingleFontFamily {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data,
) -> Result<SingleFontFamily, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<SingleFontFamily, ValueErrorKind> {
parse_single_font_family(parser)
.map_err(|_| ValueErrorKind::from(ParseError::new("expected font family")))
}
......@@ -272,41 +256,41 @@ mod tests {
#[test]
fn detects_invalid_invalid_font_size() {
assert!(is_parse_error(&FontSizeSpec::parse_str("furlong", ())));
assert!(is_parse_error(&FontSizeSpec::parse_str("furlong")));
}
#[test]
fn parses_font_weight() {
assert_eq!(
<FontWeightSpec as Parse>::parse_str("normal", ()),
<FontWeightSpec as Parse>::parse_str("normal"),
Ok(FontWeightSpec::Normal)
);
assert_eq!(
<FontWeightSpec as Parse>::parse_str("bold", ()),
<FontWeightSpec as Parse>::parse_str("bold"),
Ok(FontWeightSpec::Bold)
);
assert_eq!(
<FontWeightSpec as Parse>::parse_str("100", ()),
<FontWeightSpec as Parse>::parse_str("100"),
Ok(FontWeightSpec::W100)
);
}
#[test]
fn detects_invalid_font_weight() {
assert!(<FontWeightSpec as Parse>::parse_str("", ()).is_err());
assert!(<FontWeightSpec as Parse>::parse_str("strange", ()).is_err());
assert!(<FontWeightSpec as Parse>::parse_str("314", ()).is_err());
assert!(<FontWeightSpec as Parse>::parse_str("3.14", ()).is_err());
assert!(<FontWeightSpec as Parse>::parse_str("").is_err());
assert!(<FontWeightSpec as Parse>::parse_str("strange").is_err());
assert!(<FontWeightSpec as Parse>::parse_str("314").is_err());
assert!(<FontWeightSpec as Parse>::parse_str("3.14").is_err());
}
#[test]
fn parses_letter_spacing() {
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("normal", ()),
<LetterSpacingSpec as Parse>::parse_str("normal"),
Ok(LetterSpacingSpec::Normal)
);
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("10em", ()),
<LetterSpacingSpec as Parse>::parse_str("10em"),
Ok(LetterSpacingSpec::Value(LengthHorizontal::new(
10.0,
LengthUnit::FontEm,
......@@ -317,14 +301,14 @@ mod tests {
#[test]
fn computes_letter_spacing() {
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("normal", ()).map(|s| s.compute()),
<LetterSpacingSpec as Parse>::parse_str("normal").map(|s| s.compute()),
Ok(LetterSpacingSpec::Value(LengthHorizontal::new(
0.0,
LengthUnit::Default,
)))
);
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("10em", ()).map(|s| s.compute()),
<LetterSpacingSpec as Parse>::parse_str("10em").map(|s| s.compute()),
Ok(LetterSpacingSpec::Value(LengthHorizontal::new(
10.0,
LengthUnit::FontEm,
......@@ -334,38 +318,38 @@ mod tests {
#[test]
fn detects_invalid_invalid_letter_spacing() {
assert!(is_parse_error(&LetterSpacingSpec::parse_str("furlong", ())));
assert!(is_parse_error(&LetterSpacingSpec::parse_str("furlong")));
}
#[test]
fn parses_font_family() {
assert_eq!(
<SingleFontFamily as Parse>::parse_str("'Hello world'", ()),
<SingleFontFamily as Parse>::parse_str("'Hello world'"),
Ok(SingleFontFamily("Hello world".to_owned()))
);
assert_eq!(
<SingleFontFamily as Parse>::parse_str("\"Hello world\"", ()),
<SingleFontFamily as Parse>::parse_str("\"Hello world\""),
Ok(SingleFontFamily("Hello world".to_owned()))
);
assert_eq!(
<SingleFontFamily as Parse>::parse_str(" Hello world ", ()),
<SingleFontFamily as Parse>::parse_str(" Hello world "),
Ok(SingleFontFamily("Hello world".to_owned()))
);
assert_eq!(
<SingleFontFamily as Parse>::parse_str("Plonk", ()),
<SingleFontFamily as Parse>::parse_str("Plonk"),
Ok(SingleFontFamily("Plonk".to_owned()))
);
}
#[test]
fn detects_invalid_font_family() {
assert!(<SingleFontFamily as Parse>::parse_str("", ()).is_err());
assert!(<SingleFontFamily as Parse>::parse_str("").is_err());
// assert!(<SingleFontFamily as Parse>::parse_str("''", ()).is_err());
// assert!(<SingleFontFamily as Parse>::parse_str("''").is_err());
assert!(<SingleFontFamily as Parse>::parse_str("42", ()).is_err());
assert!(<SingleFontFamily as Parse>::parse_str("42").is_err());
}
}
......@@ -36,10 +36,9 @@ pub enum SpreadMethod {
}
impl Parse for SpreadMethod {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _: ()) -> Result<SpreadMethod, ValueErrorKind> {
fn parse(parser: &mut Parser<'_, '_>) -> Result<SpreadMethod, ValueErrorKind> {
let loc = parser.current_source_location();
parser
......@@ -256,10 +255,10 @@ impl GradientVariant {
// https://www.w3.org/TR/SVG/pservers.html#LinearGradients
GradientVariant::Linear {
x1: Some(LengthHorizontal::parse_str("0%", ()).unwrap()),
y1: Some(LengthVertical::parse_str(