From cba2b1277195fb0fe8a45b1d81cce31001cd2faf Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 2 Apr 2020 15:22:18 -0400 Subject: [PATCH] handle maps in nth() --- src/builtin/list.rs | 1 + src/value/map.rs | 8 ++++++++ tests/list.rs | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/builtin/list.rs b/src/builtin/list.rs index eba69ed..5e52a45 100644 --- a/src/builtin/list.rs +++ b/src/builtin/list.rs @@ -26,6 +26,7 @@ pub(crate) fn register(f: &mut HashMap) { max_args!(args, 2); let list = match arg!(args, 0, "list") { Value::List(v, ..) => v, + Value::Map(m) => m.entries(), v => vec![v], }; let n = match arg!(args, 1, "n") { diff --git a/src/value/map.rs b/src/value/map.rs index 3614d67..c2e9d78 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -2,6 +2,7 @@ use std::slice::Iter; use std::vec::IntoIter; use super::Value; +use crate::common::{Brackets, ListSeparator}; use crate::error::SassResult; #[derive(Debug, Clone, PartialEq, Eq)] @@ -48,6 +49,13 @@ impl SassMap { self.0.into_iter().map(|(.., v)| v).collect() } + pub fn entries(self) -> Vec { + self.0 + .into_iter() + .map(|(k, v)| Value::List(vec![k, v], ListSeparator::Space, Brackets::None)) + .collect() + } + pub fn insert(&mut self, key: Value, value: Value) { for &mut (ref k, ref mut v) in &mut self.0 { if k == &key { diff --git a/tests/list.rs b/tests/list.rs index ba4d591..a5ae21f 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -38,6 +38,11 @@ test!( "a {\n color: nth(foo, 1);\n}\n", "a {\n color: foo;\n}\n" ); +test!( + nth_map, + "a {\n color: nth((c: d, e: f, g: h), 2);\n}\n", + "a {\n color: e f;\n}\n" +); test!( list_separator_space_separated, "a {\n color: list-separator(a b c);\n}\n",