From fab55c510553667f8810cb9e812e85b42620e20a Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 15 Feb 2020 08:32:46 -0500 Subject: [PATCH] Properly handle `str-slice()` when $start-at is 0 --- src/builtin/string.rs | 1 + tests/strings.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/builtin/string.rs b/src/builtin/string.rs index d9f6c17..034f6c7 100644 --- a/src/builtin/string.rs +++ b/src/builtin/string.rs @@ -49,6 +49,7 @@ pub(crate) fn register(f: &mut BTreeMap) { 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") diff --git a/tests/strings.rs b/tests/strings.rs index 00f6872..e27b01b 100644 --- a/tests/strings.rs +++ b/tests/strings.rs @@ -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" +);