Skip to content

Commit

Permalink
Copybara import of the project:
Browse files Browse the repository at this point in the history
--
4b67c374d49b00860a8f285aae2e064cc58a0dc7 by Bastien Jacot-Guillarmod <[email protected]>:

Make `ActualT` in `Matcher` a generic type parameter.

--
7e34d847f2cda5387e55ac436ded30cc6d07bcaa by Bastien Jacot-Guillarmod <[email protected]>:

Accept all `Copy` type for `ActualT` instead of only reference.

COPYBARA_INTEGRATE_REVIEW=google/googletest-rust#367 from google:copy_instead_of_ref 7e34d847f2cda5387e55ac436ded30cc6d07bcaa
FUTURE_COPYBARA_INTEGRATE_REVIEW=google/googletest-rust#367 from google:copy_instead_of_ref 7e34d847f2cda5387e55ac436ded30cc6d07bcaa
PiperOrigin-RevId: 618280400
  • Loading branch information
bjacotg authored and copybara-github committed Mar 23, 2024
1 parent 41aeb3c commit 9c42be3
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 87 deletions.
19 changes: 8 additions & 11 deletions rust/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,23 +527,23 @@ mod tests {
// compare with each other.
// googletest-rust matchers also do not currently implement Clone.
assert_that!(
map.as_view().iter().collect::<Vec<_>>(),
map.as_view(),
unordered_elements_are![
eq((3, ProtoStr::from_str("fizz"))),
eq((5, ProtoStr::from_str("buzz"))),
eq((15, ProtoStr::from_str("fizzbuzz")))
]
);
assert_that!(
map.as_view().into_iter().collect::<Vec<_>>(),
map.as_view(),
unordered_elements_are![
eq((3, ProtoStr::from_str("fizz"))),
eq((5, ProtoStr::from_str("buzz"))),
eq((15, ProtoStr::from_str("fizzbuzz")))
]
);
assert_that!(
map.as_mut().iter().collect::<Vec<_>>(),
map.as_mut(),
unordered_elements_are![
eq((3, ProtoStr::from_str("fizz"))),
eq((5, ProtoStr::from_str("buzz"))),
Expand All @@ -560,10 +560,7 @@ mod tests {
// insert should return false when the key is already present
assert!(!map_mut.insert(0, "buzz"));

assert_that!(
map.as_mut().iter().collect::<Vec<_>>(),
unordered_elements_are![eq((0, ProtoStr::from_str("buzz"))),]
);
assert_that!(map.as_mut(), unordered_elements_are![eq((0, ProtoStr::from_str("buzz"))),]);
}

#[test]
Expand All @@ -573,7 +570,7 @@ mod tests {
map_mut.extend([(0, "fizz"), (1, "buzz"), (2, "fizzbuzz")]);

assert_that!(
map.as_view().into_iter().collect::<Vec<_>>(),
map.as_view(),
unordered_elements_are![
eq((0, ProtoStr::from_str("fizz"))),
eq((1, ProtoStr::from_str("buzz"))),
Expand All @@ -589,7 +586,7 @@ mod tests {
map_mut.extend(&map_2);

assert_that!(
map.as_view().into_iter().collect::<Vec<_>>(),
map.as_view(),
unordered_elements_are![
eq((0, ProtoStr::from_str("fizz"))),
eq((1, ProtoStr::from_str("buzz"))),
Expand All @@ -606,7 +603,7 @@ mod tests {
map_mut.copy_from([(0, "fizz"), (1, "buzz"), (2, "fizzbuzz")]);

assert_that!(
map.as_view().into_iter().collect::<Vec<_>>(),
map.as_view(),
unordered_elements_are![
eq((0, ProtoStr::from_str("fizz"))),
eq((1, ProtoStr::from_str("buzz"))),
Expand All @@ -622,7 +619,7 @@ mod tests {
map_mut.copy_from(&map_2);

assert_that!(
map.as_view().into_iter().collect::<Vec<_>>(),
map.as_view(),
unordered_elements_are![
eq((2, ProtoStr::from_str("bing"))),
eq((3, ProtoStr::from_str("bong")))
Expand Down
4 changes: 2 additions & 2 deletions rust/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ mod tests {
let mut m2 = MyMessage::default();

let mut m1_a = m1.a_mut();
assert_that!(m1_a, matches_pattern!(Optional::Unset(_)));
assert_that!(m1_a, matches_pattern!(&Optional::Unset(_)));

assert_that!(m1_a.as_view().val(), eq(0));

Expand All @@ -642,7 +642,7 @@ mod tests {

m2_b.set(10);
assert_that!(m2_b.is_set(), eq(true));
assert_that!(m2_b, matches_pattern!(Optional::Set(_)));
assert_that!(m2_b, matches_pattern!(&Optional::Set(_)));
assert_that!(m2_b.as_view().val(), eq(10));

assert_that!(m1_a.or_default().as_view().val(), eq(0));
Expand Down
2 changes: 1 addition & 1 deletion rust/proxied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ mod tests {
my_mut.set("Hello indeed".to_string());

let val_after_set = my_mut.as_view().val().to_string();
assert_that!(my_proxied.val, eq(val_after_set));
assert_that!(my_proxied.val, eq(&val_after_set));
assert_that!(my_proxied.val, eq("Hello indeed"));
}

Expand Down
2 changes: 1 addition & 1 deletion rust/repeated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ mod tests {

)*
assert_that!(
r.iter().collect::<Vec<$t>>(), elements_are![$(eq($vals)),*]);
r, elements_are![$(eq($vals)),*]);
r.set(0, <$t as Default>::default());
assert_that!(r.get(0).expect("elem 0"), eq(<$t as Default>::default()));

Expand Down
51 changes: 24 additions & 27 deletions rust/test/shared/accessors_map_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ macro_rules! generate_map_primitives_tests {
let mut msg = TestMap::new();
assert_that!(msg.[< map_ $k_field _ $v_field >]().len(), eq(0));
assert_that!(
msg.[< map_ $k_field _ $v_field >]().iter().collect::<Vec<_>>(),
msg.[< map_ $k_field _ $v_field >](),
elements_are![]
);
assert_that!(
Expand All @@ -40,36 +40,36 @@ macro_rules! generate_map_primitives_tests {
assert_that!(msg.[< map_ $k_field _ $v_field _mut>]().insert(k, v), eq(false));
assert_that!(msg.[< map_ $k_field _ $v_field >]().len(), eq(1));
assert_that!(
msg.[< map_ $k_field _ $v_field >]().iter().collect::<Vec<_>>(),
msg.[< map_ $k_field _ $v_field >](),
elements_are![eq((k, v))]
);
assert_that!(
msg.[< map_ $k_field _ $v_field >]().keys().collect::<Vec<_>>(),
elements_are![eq(k)]
elements_are![eq(&k)]
);
assert_that!(
msg.[< map_ $k_field _ $v_field >]().values().collect::<Vec<_>>(),
elements_are![eq(v)]
elements_are![eq(&v)]
);

let k2: $k_type = $k_nonzero;
let v2: $v_type = $v_nonzero;
assert_that!(msg.[< map_ $k_field _ $v_field _mut>]().insert(k2, v2), eq(true));
assert_that!(msg.[< map_ $k_field _ $v_field >]().len(), eq(2));
assert_that!(msg.[< map_ $k_field _ $v_field >](), len(eq(2)));
assert_that!(
msg.[< map_ $k_field _ $v_field >]().iter().collect::<Vec<_>>(),
msg.[< map_ $k_field _ $v_field >](),
unordered_elements_are![
eq((k, v)),
eq((k2, v2)),
]
);
assert_that!(
msg.[< map_ $k_field _ $v_field >]().keys().collect::<Vec<_>>(),
unordered_elements_are![eq(k), eq(k2)]
unordered_elements_are![eq(&k), eq(&k2)]
);
assert_that!(
msg.[< map_ $k_field _ $v_field >]().values().collect::<Vec<_>>(),
unordered_elements_are![eq(v), eq(v2)]
unordered_elements_are![eq(&v), eq(&v2)]
);
}
)* }
Expand Down Expand Up @@ -104,11 +104,11 @@ fn collect_as_hashmap() {
let hashmap: HashMap<String, String> =
msg.map_string_string().iter().map(|(k, v)| (k.to_string(), v.to_string())).collect();
assert_that!(
hashmap.into_iter().collect::<Vec<_>>(),
hashmap,
unordered_elements_are![
eq(("hello".to_owned(), "world".to_owned())),
eq(("fizz".to_owned(), "buzz".to_owned())),
eq(("boo".to_owned(), "blah".to_owned())),
(eq("hello"), eq("world")),
(eq("fizz"), eq("buzz")),
(eq("boo"), eq("blah")),
]
);
}
Expand Down Expand Up @@ -141,10 +141,7 @@ fn test_bytes_and_string_copied() {
}

assert_that!(msg.map_string_string_mut().get("hello").unwrap(), eq("world"));
assert_that!(
msg.map_string_string().iter().collect::<Vec<_>>(),
unordered_elements_are![eq(("hello".into(), "world".into()))]
);
assert_that!(msg.map_string_string(), unordered_elements_are![(eq("hello"), eq("world"))]);
assert_that!(msg.map_int32_bytes_mut().get(1).unwrap(), eq(b"world"));
}

Expand Down Expand Up @@ -216,7 +213,7 @@ macro_rules! generate_map_with_msg_values_tests {
msg.[< map_ $k_field _all_types_mut >]().remove($k_nonzero),
eq(true),
"`remove` should return true when key was present.");
assert_that!(msg.[< map_ $k_field _all_types >]().len(), eq(0));
assert_that!(msg.[< map_ $k_field _all_types >](), empty());
assert_that!(
msg.[< map_ $k_field _all_types_mut >]().remove($k_nonzero),
eq(false),
Expand All @@ -229,13 +226,13 @@ macro_rules! generate_map_with_msg_values_tests {
// "`iter` should work when empty."
// );
assert_that!(
msg.[< map_ $k_field _all_types_mut >]().keys().collect::<Vec<_>>(),
elements_are![],
msg.[< map_ $k_field _all_types_mut >]().keys().count(),
eq(0),
"`iter` should work when empty."
);
assert_that!(
msg.[< map_ $k_field _all_types_mut >]().values().collect::<Vec<_>>(),
elements_are![],
msg.[< map_ $k_field _all_types_mut >]().values().count(),
eq(0),
"`iter` should work when empty."
);

Expand All @@ -251,10 +248,10 @@ macro_rules! generate_map_with_msg_values_tests {
// );
assert_that!(
msg.[< map_ $k_field _all_types >]().keys().collect::<Vec<_>>(),
unordered_elements_are![eq($k_nonzero)]
unordered_elements_are![eq(&$k_nonzero)]
);
assert_that!(
msg.[< map_ $k_field _all_types >]().values().collect::<Vec<_>>().len(),
msg.[< map_ $k_field _all_types >]().values().count(),
eq(1));


Expand All @@ -266,15 +263,15 @@ macro_rules! generate_map_with_msg_values_tests {
eq(true));

assert_that!(
msg.[< map_ $k_field _all_types >]().iter().collect::<Vec<_>>().len(),
eq(2)
msg.[< map_ $k_field _all_types >](),
len(eq(2))
);
assert_that!(
msg.[< map_ $k_field _all_types >]().keys().collect::<Vec<_>>(),
unordered_elements_are![eq($k_nonzero), eq($k_other)]
unordered_elements_are![eq(&$k_nonzero), eq(&$k_other)]
);
assert_that!(
msg.[< map_ $k_field _all_types >]().values().collect::<Vec<_>>().len(),
msg.[< map_ $k_field _all_types >]().values().count(),
eq(2)
);
}
Expand Down
33 changes: 15 additions & 18 deletions rust/test/shared/accessors_repeated_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ macro_rules! generate_repeated_numeric_test {
mutator.set(2, 0 as $t);

assert_that!(
mutator.iter().collect::<Vec<_>>(),
mutator,
elements_are![eq(2 as $t), eq(1 as $t), eq(0 as $t)]
);
assert_that!(
mutator.as_view().into_iter().collect::<Vec<_>>(),
mutator.as_view(),
elements_are![eq(2 as $t), eq(1 as $t), eq(0 as $t)]
);

for i in 0..mutator.len() {
mutator.set(i, 0 as $t);
}
assert_that!(
msg.[<repeated_ $field _mut >]().iter().collect::<Vec<_>>(),
msg.[<repeated_ $field _mut >](),
each(eq(0 as $t))
);
}
Expand All @@ -65,7 +65,7 @@ macro_rules! generate_repeated_numeric_test {

assert_that!(
mutator.iter().collect::<Vec<_>>(),
eq(mutator2.iter().collect::<Vec<_>>())
eq(&mutator2.iter().collect::<Vec<_>>())
);
}

Expand Down Expand Up @@ -124,16 +124,13 @@ fn test_repeated_bool_accessors() {
mutator.set(2, false);
assert_that!(mutator.get(2), some(eq(false)));

assert_that!(mutator.iter().collect::<Vec<_>>(), elements_are![eq(false), eq(true), eq(false)]);
assert_that!(
mutator.as_view().into_iter().collect::<Vec<_>>(),
elements_are![eq(false), eq(true), eq(false)]
);
assert_that!(mutator, elements_are![eq(false), eq(true), eq(false)]);
assert_that!(mutator.as_view(), elements_are![eq(false), eq(true), eq(false)]);

for i in 0..mutator.len() {
mutator.set(i, false);
}
assert_that!(msg.repeated_bool().iter().collect::<Vec<_>>(), each(eq(false)));
assert_that!(msg.repeated_bool(), each(eq(false)));
}

#[test]
Expand All @@ -160,18 +157,18 @@ fn test_repeated_enum_accessors() {
assert_that!(mutator.get(2), some(eq(NestedEnum::Foo)));

assert_that!(
mutator.iter().collect::<Vec<_>>(),
mutator,
elements_are![eq(NestedEnum::Bar), eq(NestedEnum::Baz), eq(NestedEnum::Foo)]
);
assert_that!(
mutator.as_view().into_iter().collect::<Vec<_>>(),
mutator.as_view(),
elements_are![eq(NestedEnum::Bar), eq(NestedEnum::Baz), eq(NestedEnum::Foo)]
);

for i in 0..mutator.len() {
mutator.set(i, NestedEnum::Foo);
}
assert_that!(msg.repeated_nested_enum().iter().collect::<Vec<_>>(), each(eq(NestedEnum::Foo)));
assert_that!(msg.repeated_nested_enum(), each(eq(NestedEnum::Foo)));
}

#[test]
Expand All @@ -185,7 +182,7 @@ fn test_repeated_bool_set() {
}
protobuf::MutProxy::set(&mut mutator, mutator2.as_view());

assert_that!(mutator.iter().collect::<Vec<_>>(), eq(mutator2.iter().collect::<Vec<_>>()));
assert_that!(&mutator.iter().collect::<Vec<_>>(), eq(&mutator2.iter().collect::<Vec<_>>()));
}

#[test]
Expand All @@ -209,8 +206,8 @@ fn test_repeated_message() {
assert_that!(msg.repeated_nested_message().get(0).unwrap().bb(), eq(2));

assert_that!(
msg.repeated_nested_message().iter().map(|m| m.bb()).collect::<Vec<_>>(),
eq(vec![2]),
msg.repeated_nested_message(),
elements_are![predicate(|m: protobuf::View<NestedMessage>| m.bb() == 2)],
);

drop(msg);
Expand Down Expand Up @@ -241,15 +238,15 @@ fn test_repeated_strings() {
assert_that!(msg.repeated_string().get(0).unwrap(), eq("set from Mut"));
assert_that!(msg.repeated_string().get(1).unwrap(), eq("set second str"));
assert_that!(
msg.repeated_string().iter().collect::<Vec<_>>(),
msg.repeated_string(),
elements_are![eq("set from Mut"), eq("set second str")]
);
older_msg.repeated_string_mut().copy_from(msg.repeated_string());
}

assert_that!(older_msg.repeated_string().len(), eq(2));
assert_that!(
older_msg.repeated_string().iter().collect::<Vec<_>>(),
older_msg.repeated_string(),
elements_are![eq("set from Mut"), eq("set second str")]
);

Expand Down
2 changes: 1 addition & 1 deletion rust/test/shared/accessors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn test_default_accessors() {
let msg = TestAllTypes::new();
assert_that!(
msg,
matches_pattern!(TestAllTypes{
matches_pattern!(&TestAllTypes{
default_int32(): eq(41),
default_int64(): eq(42),
default_uint32(): eq(43),
Expand Down
Loading

0 comments on commit 9c42be3

Please sign in to comment.