Repository: clarkmcc/cel-rust (language: rust)

Issue:
`.map` doesn't work properly on `Value::Map`
In CEL, you can map your [`Map` to a `List` of your keys](https://github.com/google/cel-spec/blob/master/tests/simple/testdata/macros.textproto#L209-L213) for instance as so: `{"Key": "Value"}.map(k, k) == ["Key"]` 
But the interpreter bails out on this: 
```
Cel expression couldn't be evaluated: UnexpectedType { got: "map", want: "list" }
```

While this should eval to `true`, which it does using the golang's interpreter



Discussion / hints:

Fix patch:
diff --git a/interpreter/src/functions.rs b/interpreter/src/functions.rs
index b04e365..bd85997 100644
--- a/interpreter/src/functions.rs
+++ b/interpreter/src/functions.rs
@@ -314,6 +314,16 @@ pub fn map(
             }
             Value::List(Arc::new(values))
         }
+        Value::Map(map) => {
+            let mut values = Vec::with_capacity(map.map.len());
+            let mut ptx = ftx.ptx.new_inner_scope();
+            for (key, _) in map.map.iter() {
+                ptx.add_variable_from_value(ident.clone(), key.clone());
+                let value = ptx.resolve(&expr)?;
+                values.push(value);
+            }
+            Value::List(Arc::new(values))
+        }
         _ => return Err(this.error_expected_type(ValueType::List)),
     }
     .into()
@@ -613,6 +623,10 @@ mod tests {
                 "nested map",
                 "[[1, 2], [2, 3]].map(x, x.map(x, x * 2)) == [[2, 4], [4, 6]]",
             ),
+            (
+                "map to list",
+                r#"{'John': 'smart'}.map(key, key) == ['John']"#,
+            ),
         ]
         .iter()
         .for_each(assert_script);


Test patch: