Handle str-slice $end-at is 0
This commit is contained in:
parent
d082583917
commit
19d68c3c5d
@ -57,6 +57,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
};
|
};
|
||||||
let mut end = match arg!(args, 2, "end-at"=Value::Null).eval() {
|
let mut end = match arg!(args, 2, "end-at"=Value::Null).eval() {
|
||||||
Value::Dimension(n, Unit::None) if n.to_integer().is_positive() => n.to_integer().to_usize().unwrap(),
|
Value::Dimension(n, Unit::None) if n.to_integer().is_positive() => n.to_integer().to_usize().unwrap(),
|
||||||
|
Value::Dimension(n, Unit::None) if n == Number::from(0) => 0_usize,
|
||||||
Value::Dimension(n, Unit::None) if n < -Number::from(str_len) => 0_usize,
|
Value::Dimension(n, Unit::None) if n < -Number::from(str_len) => 0_usize,
|
||||||
Value::Dimension(n, Unit::None) => (BigInt::from(str_len + 1) + n.to_integer()).to_usize().unwrap(),
|
Value::Dimension(n, Unit::None) => (BigInt::from(str_len + 1) + n.to_integer()).to_usize().unwrap(),
|
||||||
Value::Dimension(..) => todo!("$end: Expected ___ to have no units."),
|
Value::Dimension(..) => todo!("$end: Expected ___ to have no units."),
|
||||||
|
@ -78,3 +78,8 @@ test!(
|
|||||||
"a {\n color: str-slice(\"cde\", 0, -100);\n}\n",
|
"a {\n color: str-slice(\"cde\", 0, -100);\n}\n",
|
||||||
"a {\n color: \"\";\n}\n"
|
"a {\n color: \"\";\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
str_slice_end_0,
|
||||||
|
"a {\n color: str-slice(\"cde\", 1, 0);\n}\n",
|
||||||
|
"a {\n color: \"\";\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user