add empty case to extend repeated and map tests, fix map methods that consumed self
PiperOrigin-RevId: 621158946
diff --git a/rust/map.rs b/rust/map.rs
index 4d80d1e..36eb390 100644
--- a/rust/map.rs
+++ b/rust/map.rs
@@ -273,11 +273,11 @@
K: Proxied + ?Sized + 'msg,
V: ProxiedInMapValue<K> + ?Sized + 'msg,
{
- pub fn len(self) -> usize {
+ pub fn len(&self) -> usize {
self.as_view().len()
}
- pub fn is_empty(self) -> bool {
+ pub fn is_empty(&self) -> bool {
self.len() == 0
}
@@ -570,6 +570,10 @@
fn test_extend() {
let mut map: Map<i32, ProtoStr> = Map::new();
let mut map_mut = map.as_mut();
+
+ map_mut.extend([(0, ""); 0]);
+ assert_that!(map_mut.len(), eq(0));
+
map_mut.extend([(0, "fizz"), (1, "buzz"), (2, "fizzbuzz")]);
assert_that!(
diff --git a/rust/repeated.rs b/rust/repeated.rs
index 03376fb..8c7c1cc 100644
--- a/rust/repeated.rs
+++ b/rust/repeated.rs
@@ -508,6 +508,10 @@
#[test]
fn test_repeated_extend() {
let mut r = Repeated::<i32>::new();
+
+ r.as_mut().extend([0; 0]);
+ assert_that!(r.as_mut().len(), eq(0));
+
r.as_mut().extend([0, 1]);
assert_that!(r.as_mut().iter().collect::<Vec<_>>(), elements_are![eq(0), eq(1)]);
let mut x = Repeated::<i32>::new();