Properly handle str-slice() when $start-at is 0

This commit is contained in:
ConnorSkees 2020-02-15 08:32:46 -05:00
parent 35ed667f16
commit fab55c5105
2 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
let str_len = string.len();
let start = match arg!(args, 1, "start-at").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) => 1_usize,
Value::Dimension(n, Unit::None) => (BigInt::from(str_len + 1) + n.to_integer()).to_usize().unwrap(),
Value::Dimension(..) => todo!("$start: Expected ___ to have no units."),
_ => todo!("$start-at: ____ is not a number")

View File

@ -63,3 +63,8 @@ test!(
"a {\n color: str-slice(abcd, 2, -2);\n}\n",
"a {\n color: bc;\n}\n"
);
test!(
str_slice_start_0,
"a {\n color: str-slice(cde, 0);\n}\n",
"a {\n color: cde;\n}\n"
);