Skip to content

Commit

Permalink
Add Map(none, none) test
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Jun 3, 2024
1 parent edee6ef commit 1617da0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions glide-core/src/client/value_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,45 @@ mod tests {
);
}

#[test]
fn test_convert_array_to_map_with_none() {
let redis_map = vec![
(
Value::BulkString(b"key1".to_vec()),
Value::BulkString(b"10.5".to_vec()),
),
(Value::Double(20.5), Value::Double(19.5)),
(Value::Double(18.5), Value::BulkString(b"30.2".to_vec())),
];

let converted_type = ExpectedReturnType::Map {
key_type: &None,
value_type: &None,
};
let converted_map =
convert_to_expected_type(Value::Map(redis_map), Some(converted_type)).unwrap();

let converted_map = if let Value::Map(map) = converted_map {
map
} else {
panic!("Expected a Map, but got {:?}", converted_map);
};

assert_eq!(converted_map.len(), 3);

let (key, value) = &converted_map[0];
assert_eq!(*key, Value::BulkString(b"key1".to_vec()));
assert_eq!(*value, Value::BulkString(b"10.5".to_vec()));

let (key, value) = &converted_map[1];
assert_eq!(*key, Value::Double(20.5));
assert_eq!(*value, Value::Double(19.5));

let (key, value) = &converted_map[2];
assert_eq!(*key, Value::Double(18.5));
assert_eq!(*value, Value::BulkString(b"30.2".to_vec()));
}

#[test]
fn test_convert_2d_array_to_map_using_expected_return_type_map() {
// in RESP2, we get an array of arrays value like this:
Expand Down

0 comments on commit 1617da0

Please sign in to comment.