diff --git a/src/builtin/map.rs b/src/builtin/map.rs index 21e3b10..575dd8c 100644 --- a/src/builtin/map.rs +++ b/src/builtin/map.rs @@ -9,12 +9,12 @@ pub(crate) fn register(f: &mut HashMap) { "map-get".to_owned(), Box::new(|args, _| { max_args!(args, 2); + let key = arg!(args, 1, "key"); let map = match arg!(args, 0, "map") { Value::Map(m) => m, Value::List(v, ..) if v.is_empty() => SassMap::new(), v => return Err(format!("$map: {} is not a map.", v).into()), }; - let key = arg!(args, 1, "key"); Ok(map.get(key)?.unwrap_or(Value::Null).clone()) }), ); @@ -22,12 +22,12 @@ pub(crate) fn register(f: &mut HashMap) { "map-has-key".to_owned(), Box::new(|args, _| { max_args!(args, 2); + let key = arg!(args, 1, "key"); let map = match arg!(args, 0, "map") { Value::Map(m) => m, Value::List(v, ..) if v.is_empty() => SassMap::new(), v => return Err(format!("$map: {} is not a map.", v).into()), }; - let key = arg!(args, 1, "key"); Ok(Value::bool(map.get(key)?.is_some())) }), ); diff --git a/tests/map.rs b/tests/map.rs index f7b18bc..a5b112a 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -111,3 +111,13 @@ test!( "a {\n color: length((a: b, c: d, e: f));\n}\n", "a {\n color: 3;\n}\n" ); +error!( + map_get_one_arg, + "a {\n color: map-get(1);\n}\n", + "Error: Missing argument $key." +); +error!( + map_has_key_one_arg, + "a {\n color: map-has-key(1);\n}\n", + "Error: Missing argument $key." +);