Implement ident addition
This commit is contained in:
parent
6bc96aeff4
commit
ffff80109b
@ -454,7 +454,7 @@ impl<'a> StyleSheetParser<'a> {
|
||||
match expr {
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(s)),
|
||||
#[allow(clippy::redundant_closure)]
|
||||
Expr::Styles(s) => stmts.extend(s.into_iter().map(|s| Stmt::Style(s))),
|
||||
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)),
|
||||
Expr::MixinDecl(name, mixin) => {
|
||||
scope.mixins.insert(name, *mixin);
|
||||
}
|
||||
|
33
src/value.rs
33
src/value.rs
@ -95,7 +95,33 @@ impl Add for Value {
|
||||
// Self::Color(..) => todo!(),
|
||||
// Self::BinaryOp(..) => todo!(),
|
||||
// Self::Paren(..) => todo!(),
|
||||
// Self::Ident(..) => todo!(),
|
||||
Self::Ident(s1, quotes1) => match other {
|
||||
Self::Ident(s2, quotes2) => {
|
||||
let quotes = match (quotes1, quotes2) {
|
||||
(QuoteKind::Double, _)
|
||||
| (QuoteKind::Single, _)
|
||||
| (_, QuoteKind::Double)
|
||||
| (_, QuoteKind::Single) => QuoteKind::Double,
|
||||
_ => QuoteKind::None,
|
||||
};
|
||||
Value::Ident(format!("{}{}", s1, s2), quotes)
|
||||
}
|
||||
Self::Important | Self::True | Self::False | Self::Dimension(..) => {
|
||||
let quotes = match quotes1 {
|
||||
QuoteKind::Double | QuoteKind::Single => QuoteKind::Double,
|
||||
QuoteKind::None => QuoteKind::None,
|
||||
};
|
||||
Value::Ident(format!("{}{}", s1, other), quotes)
|
||||
}
|
||||
Self::Null => {
|
||||
let quotes = match quotes1 {
|
||||
QuoteKind::Double | QuoteKind::Single => QuoteKind::Double,
|
||||
QuoteKind::None => QuoteKind::None,
|
||||
};
|
||||
Value::Ident(s1, quotes)
|
||||
}
|
||||
_ => todo!(),
|
||||
},
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
@ -115,7 +141,10 @@ impl Display for Value {
|
||||
.join(sep.as_str())
|
||||
),
|
||||
Self::Color(c) => write!(f, "{}", c),
|
||||
Self::BinaryOp(lhs, op, rhs) => write!(f, "{}{}{}", lhs, op, rhs),
|
||||
Self::BinaryOp(lhs, op, rhs) => match op {
|
||||
Op::Plus => write!(f, "{}", *lhs.clone() + *rhs.clone()),
|
||||
_ => write!(f, "{}{}{}", lhs, op, rhs),
|
||||
},
|
||||
Self::Paren(val) => write!(f, "{}", val),
|
||||
Self::Ident(val, kind) => write!(f, "{}{}{}", kind.as_str(), val, kind.as_str()),
|
||||
Self::True => write!(f, "true"),
|
||||
|
115
tests/values.rs
115
tests/values.rs
@ -49,3 +49,118 @@ test!(
|
||||
"a {\n color: 1 (red blue);\n}\n",
|
||||
"a {\n color: 1 red blue;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_idents,
|
||||
"a {\n color: red + blue;\n}\n",
|
||||
"a {\n color: redblue;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_quoted_idents,
|
||||
"a {\n color: \"red\" + \"blue\";\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_sgl_quoted_idents,
|
||||
"a {\n color: 'red' + 'blue';\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_and_un_quoted_idents,
|
||||
"a {\n color: \"red\" + blue;\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_sgl_and_un_quoted_idents,
|
||||
"a {\n color: 'red' + blue;\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_un_and_dbl_quoted_idents,
|
||||
"a {\n color: red + \"blue\";\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_un_and_sgl_quoted_idents,
|
||||
"a {\n color: red + 'blue';\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_sgl_and_dbl_quoted_idents,
|
||||
"a {\n color: 'red' + \"blue\";\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_and_sgl_quoted_idents,
|
||||
"a {\n color: \"red\" + 'blue';\n}\n",
|
||||
"a {\n color: \"redblue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_ident_true,
|
||||
"a {\n color: red + true;\n}\n",
|
||||
"a {\n color: redtrue;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_quoted_ident_true,
|
||||
"a {\n color: \"red\" + true;\n}\n",
|
||||
"a {\n color: \"redtrue\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_ident_false,
|
||||
"a {\n color: red + false;\n}\n",
|
||||
"a {\n color: redfalse;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_quoted_ident_false,
|
||||
"a {\n color: \"red\" + false;\n}\n",
|
||||
"a {\n color: \"redfalse\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_ident_important,
|
||||
"a {\n color: red + !important;\n}\n",
|
||||
"a {\n color: red!important;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_ident_null,
|
||||
"a {\n color: red + null;\n}\n",
|
||||
"a {\n color: red;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_quoted_ident_null,
|
||||
"a {\n color: \"red\" + null;\n}\n",
|
||||
"a {\n color: \"red\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_sgl_quoted_ident_null,
|
||||
"a {\n color: 'red' + null;\n}\n",
|
||||
"a {\n color: \"red\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_ident_number,
|
||||
"a {\n color: red + 1;\n}\n",
|
||||
"a {\n color: red1;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_quoted_ident_number,
|
||||
"a {\n color: \"red\" + 1;\n}\n",
|
||||
"a {\n color: \"red1\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_sgl_quoted_ident_number,
|
||||
"a {\n color: 'red' + 1;\n}\n",
|
||||
"a {\n color: \"red1\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_ident_dimension,
|
||||
"a {\n color: red + 1px;\n}\n",
|
||||
"a {\n color: red1px;\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_dbl_quoted_ident_dimension,
|
||||
"a {\n color: \"red\" + 1px;\n}\n",
|
||||
"a {\n color: \"red1px\";\n}\n"
|
||||
);
|
||||
test!(
|
||||
adds_sgl_quoted_ident_dimension,
|
||||
"a {\n color: 'red' + 1px;\n}\n",
|
||||
"a {\n color: \"red1px\";\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user