diff --git a/float-pigment-css/src/parser/property_value/calc.rs b/float-pigment-css/src/parser/property_value/calc.rs index 0b3bca0..5c2df76 100644 --- a/float-pigment-css/src/parser/property_value/calc.rs +++ b/float-pigment-css/src/parser/property_value/calc.rs @@ -38,7 +38,7 @@ impl CalcExpr { CalcExpr::Angle(angle) => !matches!(angle.as_ref(), Angle::Calc(_)), CalcExpr::Number(num) => !matches!(num.as_ref(), Number::Calc(_)), CalcExpr::Length(length) => !matches!( - length.as_ref(), + length, Length::Expr(_) | Length::Auto | Length::Undefined ), _ => false, @@ -69,7 +69,7 @@ impl CalcExpr { } else { length.to_f32() / rhs }; - let ret = match length.as_ref() { + let ret = match length { Length::Px(_) => Length::Px(v), Length::Em(_) => Length::Em(v), Length::Rpx(_) => Length::Rpx(v), @@ -81,7 +81,7 @@ impl CalcExpr { Length::Vmin(_) => Length::Vmin(v), _ => unreachable!(), }; - CalcExpr::Length(Box::new(ret)) + CalcExpr::Length(ret) } CalcExpr::Number(num) => { let ret = if mul { @@ -176,10 +176,7 @@ impl ComputeCalcExpr { _ => None, } } - CalcExpr::Length(l) => match l.as_ref() { - Length::Ratio(ratio) => Some(Angle::from_ratio(*ratio)), - _ => None, - }, + CalcExpr::Length(Length::Ratio(ratio)) => Some(Angle::from_ratio(*ratio)), _ => None, } } @@ -250,7 +247,7 @@ impl LengthUnit { impl ComputeCalcExpr { pub(crate) fn try_compute(expr: &CalcExpr) -> Option { match expr { - CalcExpr::Length(l) => Some(*l.clone()), + CalcExpr::Length(l) => Some(l.clone()), CalcExpr::Angle(_) | CalcExpr::Number(_) => None, CalcExpr::Plus(l, r) | CalcExpr::Sub(l, r) => { let l = Self::try_compute(l)?; @@ -334,17 +331,11 @@ pub(crate) enum ExpectValueType { fn combine_calc_expr(operator: Operator, lhs: CalcExpr, rhs: CalcExpr) -> CalcExpr { // Unwrap nested `Length::Expr(Calc(...))` to flatten the expression tree. let final_lhs = match lhs { - CalcExpr::Length(length_expr) => match *length_expr { - Length::Expr(LengthExpr::Calc(calc_expr)) => calc_expr, - other => Box::new(CalcExpr::Length(Box::new(other))), - }, + CalcExpr::Length(length_expr) => length_expr.into_calc_expr(), other => Box::new(other), }; let final_rhs = match rhs { - CalcExpr::Length(length_expr) => match *length_expr { - Length::Expr(LengthExpr::Calc(calc_expr)) => calc_expr, - other => Box::new(CalcExpr::Length(Box::new(other))), - }, + CalcExpr::Length(length_expr) => length_expr.into_calc_expr(), other => Box::new(other), }; match operator { @@ -501,7 +492,7 @@ fn parse_calc_value<'a, 't: 'a, 'i: 't>( if expect_type == ExpectValueType::NumberAndLength || expect_type == ExpectValueType::AngleAndLength { - return Ok(CalcExpr::Length(Box::new(length))); + return Ok(CalcExpr::Length(length)); } } // match angle diff --git a/float-pigment-css/src/parser/property_value/mod.rs b/float-pigment-css/src/parser/property_value/mod.rs index afc82c9..53decad 100644 --- a/float-pigment-css/src/parser/property_value/mod.rs +++ b/float-pigment-css/src/parser/property_value/mod.rs @@ -223,10 +223,10 @@ fn parse_length_inner<'a, 't: 'a, 'i: 't>( env_default_value(parser, properties, st) }) })?; - return Ok(Length::Expr(LengthExpr::Env( + return Ok(Length::Expr(Box::new(LengthExpr::Env( name.into(), Box::new(default_value.unwrap_or(Length::Undefined)), - ))); + )))); } "calc" => { return parse_calc_inner(parser, properties, st, ExpectValueType::NumberAndLength) @@ -234,7 +234,7 @@ fn parse_length_inner<'a, 't: 'a, 'i: 't>( if let Some(r) = ComputeCalcExpr::::try_compute(&ret) { return r; } - Length::Expr(LengthExpr::Calc(Box::new(ret))) + Length::Expr(Box::new(LengthExpr::Calc(Box::new(ret)))) }); } _ => {} @@ -401,7 +401,7 @@ pub(crate) fn percentage<'a, 't: 'a, 'i: 't>( if let Some(r) = ComputeCalcExpr::::try_compute(&ret) { return r; } - Length::Expr(LengthExpr::Calc(Box::new(ret))) + Length::Expr(Box::new(LengthExpr::Calc(Box::new(ret)))) }); } } diff --git a/float-pigment-css/src/sheet/borrow_resource.rs b/float-pigment-css/src/sheet/borrow_resource.rs index 2ceac08..f6130a1 100644 --- a/float-pigment-css/src/sheet/borrow_resource.rs +++ b/float-pigment-css/src/sheet/borrow_resource.rs @@ -10,6 +10,7 @@ use super::{borrow::Array, str_store::*}; #[repr(C)] #[derive(Debug, Serialize, Deserialize)] +#[allow(dead_code)] pub(crate) enum StyleSheetImportIndex { None, V1(StyleSheetImportIndexV1), @@ -17,6 +18,7 @@ pub(crate) enum StyleSheetImportIndex { #[repr(C)] #[derive(Debug)] +#[allow(dead_code)] pub(crate) struct StyleSheetImportIndexV1 { buf: StrBuffer, deps: Array<(StrRef, Array)>, diff --git a/float-pigment-css/src/typing.rs b/float-pigment-css/src/typing.rs index 1b5b126..d926925 100644 --- a/float-pigment-css/src/typing.rs +++ b/float-pigment-css/src/typing.rs @@ -41,7 +41,7 @@ pub enum ImportantBitSet { #[cfg_attr(debug_assertions, derive(CompatibilityEnumCheck))] pub enum CalcExpr { /// A length, e.g. `2px`. - Length(Box), + Length(Length), /// A number, e.g. `0.1`. Number(Box), /// An angle, e.g. `45deg`. @@ -58,7 +58,7 @@ pub enum CalcExpr { impl Default for CalcExpr { fn default() -> Self { - Self::Length(Box::new(Length::Undefined)) + Self::Length(Length::Undefined) } } @@ -150,7 +150,7 @@ pub enum Length { Rpx(f32), Em(f32), Ratio(f32), - Expr(LengthExpr), + Expr(Box), Vmin(f32), Vmax(f32), } @@ -188,6 +188,25 @@ impl Length { } } + /// Create a new `Length` from a `CalcExpr`. + pub fn new_calc_expr(calc_expr: Box) -> Self { + Self::Expr(Box::new(LengthExpr::Calc(calc_expr))) + } + + /// Convert to `Box`. + /// + /// If the length is already a `CalcExpr`, it will be returned directly. + /// Otherwise, it will be wrapped into a new `CalcExpr`. + pub fn into_calc_expr(self) -> Box { + match self { + Length::Expr(x) => match *x { + LengthExpr::Calc(x) => x, + x => Box::new(CalcExpr::Length(Length::Expr(Box::new(x)))), + }, + x => Box::new(CalcExpr::Length(x)), + } + } + /// Resolve the length value to `f32`. /// /// The `relative_length` is used to calculate `...%` length. @@ -214,7 +233,7 @@ impl Length { } } Length::Ratio(x) => relative_length * *x, - Length::Expr(x) => match x { + Length::Expr(x) => match &**x { LengthExpr::Invalid => None?, LengthExpr::Env(name, default_value) => match name.as_str() { "safe-area-inset-left" => media_query_status.env.safe_area_inset_left.to_f32(), @@ -268,7 +287,7 @@ impl Length { ) -> Option { let r = match self { Length::Undefined | Length::Auto => None?, - Length::Expr(x) => match x { + Length::Expr(x) => match &**x { LengthExpr::Invalid => None?, LengthExpr::Env(name, default_value) => match name.as_str() { "safe-area-inset-left" => media_query_status.env.safe_area_inset_left, diff --git a/float-pigment-css/src/typing_stringify.rs b/float-pigment-css/src/typing_stringify.rs index 68be2e1..1a17262 100644 --- a/float-pigment-css/src/typing_stringify.rs +++ b/float-pigment-css/src/typing_stringify.rs @@ -273,7 +273,7 @@ impl fmt::Display for Length { &tmp } Length::Expr(expr) => { - match expr { + match &**expr { LengthExpr::Calc(calc_expr) => { tmp = calc_expr.to_string(); &tmp diff --git a/float-pigment-css/tests/calc.rs b/float-pigment-css/tests/calc.rs index e80c9c6..b3e4548 100644 --- a/float-pigment-css/tests/calc.rs +++ b/float-pigment-css/tests/calc.rs @@ -53,22 +53,22 @@ pub fn calc() { // margin_left, // "margin-left", // "calc(10px + 20vh + 30px)", - // Length::Expr(LengthExpr::Calc(CalcExpr::Plus( - // Box::new(CalcExpr::Length(Box::new(Length::Px(40.)))), - // Box::new(CalcExpr::Length(Box::new(Length::Vh(20.)))) + // Length::new_calc_expr(CalcExpr::Plus( + // Box::new(CalcExpr::Length(Length::Px(40.)))), + // Box::new(CalcExpr::Length(Length::Vh(20.)))) // ))) // ); test_parse_property!( margin_left, "margin-left", "calc(10rpx + (20vh + 30px))", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Rpx(10.)))), + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Rpx(10.))), Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Vh(20.)))), - Box::new(CalcExpr::Length(Box::new(Length::Px(30.)))) + Box::new(CalcExpr::Length(Length::Vh(20.))), + Box::new(CalcExpr::Length(Length::Px(30.))) )) - )))) + ))) ); test_parse_property!( transform, @@ -175,16 +175,16 @@ pub fn calc_ch_ex_lang() { left, "left", "calc(1vh + 5vw + 10px + 1rem)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( + Length::new_calc_expr(Box::new(CalcExpr::Plus( Box::new(CalcExpr::Plus( Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Vh(1.)))), - Box::new(CalcExpr::Length(Box::new(Length::Vw(5.)))) + Box::new(CalcExpr::Length(Length::Vh(1.))), + Box::new(CalcExpr::Length(Length::Vw(5.))) )), - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))) + Box::new(CalcExpr::Length(Length::Px(10.))) )), - Box::new(CalcExpr::Length(Box::new(Length::Rem(1.)))) - )))) + Box::new(CalcExpr::Length(Length::Rem(1.))) + ))) ); // FIXME @@ -192,9 +192,9 @@ pub fn calc_ch_ex_lang() { // font_size, // "font-size", // "calc(17px + 0.5 * (1rem - 16px))", - // Length::Expr(LengthExpr::Calc(CalcExpr::Plus( - // Box::new(CalcExpr::Length(Box::new(Length::Px(9.)))), - // Box::new(CalcExpr::Length(Box::new(Length::Rem(0.5)))) + // Length::new_calc_expr(CalcExpr::Plus( + // Box::new(CalcExpr::Length(Length::Px(9.)))), + // Box::new(CalcExpr::Length(Length::Rem(0.5)))) // ))) // ); } @@ -207,20 +207,20 @@ pub fn calc_height_block_1() { height, "height", "calc(25px + 50%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(25.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(25.))), + Box::new(CalcExpr::Length(Length::Ratio(0.5))), + ))) ); test_parse_property!( height, "height", "calc(150% / 2 - 30px)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.75)))), - Box::new(CalcExpr::Length(Box::new(Length::Px(30.)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Ratio(0.75))), + Box::new(CalcExpr::Length(Length::Px(30.))), + ))) ); // FIXME @@ -235,10 +235,10 @@ pub fn calc_height_block_1() { height, "height", "calc(40px - 10%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Px(40.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.1)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Px(40.))), + Box::new(CalcExpr::Length(Length::Ratio(0.1))), + ))) ); } @@ -255,13 +255,13 @@ pub fn calc_in_calc() { height, "height", "calc(calc(10px + 10%) + 10px)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( + Length::new_calc_expr(Box::new(CalcExpr::Plus( Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.1)))) + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.1))) )), - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))) - )))) + Box::new(CalcExpr::Length(Length::Px(10.))) + ))) ); } @@ -271,55 +271,55 @@ pub fn calc_margin_block_1() { margin_top, "margin", "calc(10px + 1%) 0 0 0", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.01)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.01))), + ))) ); test_parse_property!( margin_right, "margin", "0 calc(10px + 1%) 0 0", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.01)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.01))), + ))) ); test_parse_property!( margin_bottom, "margin", "0 0 calc(10px + 1%) 0", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.01)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.01))), + ))) ); test_parse_property!( margin_left, "margin", "0 0 0 calc(10px + 1%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.01)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.01))), + ))) ); test_parse_property!( margin_left, "margin", "calc(10px + 1%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.01)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.01))), + ))) ); test_parse_property!( margin_bottom, "margin", "calc(10px + 1%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(10.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.01)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(10.))), + Box::new(CalcExpr::Length(Length::Ratio(0.01))), + ))) ); } @@ -331,19 +331,19 @@ pub fn calc_max_height_block_1() { max_height, "max-height", "calc(25px + 50%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Px(25.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Px(25.))), + Box::new(CalcExpr::Length(Length::Ratio(0.5))), + ))) ); test_parse_property!( max_height, "max-height", "calc(150% / 2 - 30px)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.75)))), - Box::new(CalcExpr::Length(Box::new(Length::Px(30.)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Ratio(0.75))), + Box::new(CalcExpr::Length(Length::Px(30.))), + ))) ); // FIXME // test_parse_property!( @@ -356,10 +356,10 @@ pub fn calc_max_height_block_1() { max_height, "max-height", "calc(40px - 10%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Px(40.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.1)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Px(40.))), + Box::new(CalcExpr::Length(Length::Ratio(0.1))), + ))) ); } @@ -369,10 +369,10 @@ pub fn calc_max_width_block_1() { max_width, "max-width", "calc(50% - 3px)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - Box::new(CalcExpr::Length(Box::new(Length::Px(3.)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Ratio(0.5))), + Box::new(CalcExpr::Length(Length::Px(3.))), + ))) ); // FIXME @@ -380,9 +380,9 @@ pub fn calc_max_width_block_1() { // max_width, // "max-width", // "calc(25% - 3px + 25%)", - // Length::Expr(LengthExpr::Calc(CalcExpr::Sub( - // Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - // Box::new(CalcExpr::Length(Box::new(Length::Px(3.)))), + // Length::new_calc_expr(CalcExpr::Sub( + // Box::new(CalcExpr::Length(Length::Ratio(0.5))), + // Box::new(CalcExpr::Length(Length::Px(3.))), // ))) // ); @@ -391,9 +391,9 @@ pub fn calc_max_width_block_1() { // max_width, // "max-width", // "calc(25% - 3px + 12.5% * 2)", - // Length::Expr(LengthExpr::Calc(CalcExpr::Sub( - // Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - // Box::new(CalcExpr::Length(Box::new(Length::Px(3.)))), + // Length::new_calc_expr(CalcExpr::Sub( + // Box::new(CalcExpr::Length(Length::Ratio(0.5))), + // Box::new(CalcExpr::Length(Length::Px(3.))), // ))) // ); @@ -402,9 +402,9 @@ pub fn calc_max_width_block_1() { // max_width, // "max-width", // "calc(25% - 3px + 12.5%*2)", - // Length::Expr(LengthExpr::Calc(CalcExpr::Sub( - // Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - // Box::new(CalcExpr::Length(Box::new(Length::Px(3.)))), + // Length::new_calc_expr(CalcExpr::Sub( + // Box::new(CalcExpr::Length(Length::Ratio(0.5))), + // Box::new(CalcExpr::Length(Length::Px(3.))), // ))) // ); @@ -413,9 +413,9 @@ pub fn calc_max_width_block_1() { // max_width, // "max-width", // "calc(25% - 3px + 2*12.5%)", - // Length::Expr(LengthExpr::Calc(CalcExpr::Sub( - // Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - // Box::new(CalcExpr::Length(Box::new(Length::Px(3.)))), + // Length::new_calc_expr(CalcExpr::Sub( + // Box::new(CalcExpr::Length(Length::Ratio(0.5))), + // Box::new(CalcExpr::Length(Length::Px(3.))), // ))) // ); @@ -424,9 +424,9 @@ pub fn calc_max_width_block_1() { // max_width, // "max-width", // "calc(25% - 3px + 2 * 12.5%)", - // Length::Expr(LengthExpr::Calc(CalcExpr::Sub( - // Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - // Box::new(CalcExpr::Length(Box::new(Length::Px(3.)))), + // Length::new_calc_expr(CalcExpr::Sub( + // Box::new(CalcExpr::Length(Length::Ratio(0.5))), + // Box::new(CalcExpr::Length(Length::Px(3.))), // ))) // ); @@ -446,19 +446,19 @@ pub fn calc_offset_absolute_left_1() { left, "left", "calc(-25px - 50%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Px(-25.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.5)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Px(-25.))), + Box::new(CalcExpr::Length(Length::Ratio(0.5))), + ))) ); test_parse_property!( left, "left", "calc(-150% / 2 - 30px)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Ratio(-0.75)))), - Box::new(CalcExpr::Length(Box::new(Length::Px(30.)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Ratio(-0.75))), + Box::new(CalcExpr::Length(Length::Px(30.))), + ))) ); // FIXME // test_parse_property!( @@ -471,10 +471,10 @@ pub fn calc_offset_absolute_left_1() { left, "left", "calc(-40px - 10%)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Sub( - Box::new(CalcExpr::Length(Box::new(Length::Px(-40.)))), - Box::new(CalcExpr::Length(Box::new(Length::Ratio(0.1)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Sub( + Box::new(CalcExpr::Length(Length::Px(-40.))), + Box::new(CalcExpr::Length(Length::Ratio(0.1))), + ))) ); } @@ -486,10 +486,10 @@ pub fn calc_rem_lang() { left, "left", "calc(1rem + 1em)", - Length::Expr(LengthExpr::Calc(Box::new(CalcExpr::Plus( - Box::new(CalcExpr::Length(Box::new(Length::Rem(1.)))), - Box::new(CalcExpr::Length(Box::new(Length::Em(1.)))), - )))) + Length::new_calc_expr(Box::new(CalcExpr::Plus( + Box::new(CalcExpr::Length(Length::Rem(1.))), + Box::new(CalcExpr::Length(Length::Em(1.))), + ))) ); } diff --git a/float-pigment-css/tests/env.rs b/float-pigment-css/tests/env.rs index d76bbe9..5daed16 100644 --- a/float-pigment-css/tests/env.rs +++ b/float-pigment-css/tests/env.rs @@ -23,19 +23,19 @@ pub fn env() { margin_left, "margin-left", "env(safe-area-inset-bottom, 10px)", - Length::Expr(LengthExpr::Env( + Length::Expr(Box::new(LengthExpr::Env( "safe-area-inset-bottom".into(), Box::new(Length::Px(10.)) - )) + ))) ); test_parse_property!( margin_left, "margin-left", "env(safe-area-inset-bottom, 10p)", - Length::Expr(LengthExpr::Env( + Length::Expr(Box::new(LengthExpr::Env( "safe-area-inset-bottom".into(), Box::new(Length::Px(0.)) - )) + ))) ); }