Handle str-slice $end-at is 0

This commit is contained in:
ConnorSkees 2020-02-15 08:54:10 -05:00
parent d082583917
commit 19d68c3c5d
2 changed files with 6 additions and 0 deletions

View File

@ -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() {
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) => (BigInt::from(str_len + 1) + n.to_integer()).to_usize().unwrap(),
Value::Dimension(..) => todo!("$end: Expected ___ to have no units."),

View File

@ -78,3 +78,8 @@ test!(
"a {\n color: str-slice(\"cde\", 0, -100);\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"
);