From 52ee6197339b71e209029a3ee0ae3166bb7a2fd4 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Mon, 18 Dec 2023 15:11:57 -0800 Subject: [PATCH] Migrate all remaining instances of assert_eq! to googletest-rust sans strings PiperOrigin-RevId: 592022421 --- rust/proxied.rs | 13 +++++++------ rust/test/cpp/interop/BUILD | 1 + rust/test/cpp/interop/main.rs | 7 ++++--- rust/test/shared/accessors_proto3_test.rs | 4 ++-- rust/test/shared/accessors_test.rs | 4 ++-- rust/utf8.rs | 5 +++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/rust/proxied.rs b/rust/proxied.rs index 2b839fa2fb5b..3d1031528e45 100644 --- a/rust/proxied.rs +++ b/rust/proxied.rs @@ -289,6 +289,7 @@ where #[cfg(test)] mod tests { use super::*; + use googletest::prelude::*; use std::borrow::Cow; #[derive(Debug, Default, PartialEq)] @@ -414,7 +415,7 @@ mod tests { let my_view = my_proxied.as_view(); - assert_eq!(my_view.val(), my_proxied.val); + assert_that!(my_view.val(), eq(&my_proxied.val)); } #[test] @@ -425,8 +426,8 @@ mod tests { my_mut.set("Hello indeed".to_string()); let val_after_set = my_mut.as_view().val().to_string(); - assert_eq!(my_proxied.val, val_after_set); - assert_eq!(my_proxied.val, "Hello indeed"); + assert_that!(my_proxied.val, eq(val_after_set)); + assert_that!(my_proxied.val, eq("Hello indeed")); } fn reborrow_mut_into_view<'msg>(x: Mut<'msg, MyProxied>) -> View<'msg, MyProxied> { @@ -557,12 +558,12 @@ mod tests { fn test_set() { let mut my_proxied = MyProxied::default(); my_proxied.as_mut().set("hello"); - assert_eq!(my_proxied.as_view().val(), "hello"); + assert_that!(my_proxied.as_view().val(), eq("hello")); my_proxied.as_mut().set(String::from("hello2")); - assert_eq!(my_proxied.as_view().val(), "hello2"); + assert_that!(my_proxied.as_view().val(), eq("hello2")); my_proxied.as_mut().set(Cow::Borrowed("hello3")); - assert_eq!(my_proxied.as_view().val(), "hello3"); + assert_that!(my_proxied.as_view().val(), eq("hello3")); } } diff --git a/rust/test/cpp/interop/BUILD b/rust/test/cpp/interop/BUILD index 1a4d88d640f9..bacd078cf0d3 100644 --- a/rust/test/cpp/interop/BUILD +++ b/rust/test/cpp/interop/BUILD @@ -21,6 +21,7 @@ rust_test( ], deps = [ ":test_utils", + "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_cc_rust_proto", ], diff --git a/rust/test/cpp/interop/main.rs b/rust/test/cpp/interop/main.rs index c95ceea03a56..f8c4a521f7b8 100644 --- a/rust/test/cpp/interop/main.rs +++ b/rust/test/cpp/interop/main.rs @@ -5,6 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +use googletest::prelude::*; use protobuf_cpp::__internal::PtrAndLen; use protobuf_cpp::__internal::RawMessage; use unittest_proto::proto2_unittest::TestAllExtensions; @@ -15,9 +16,9 @@ macro_rules! proto_assert_eq { let lhs = &$lhs; let rhs = &$rhs; - assert_eq!(lhs.optional_int64(), rhs.optional_int64()); - assert_eq!(lhs.optional_bytes(), rhs.optional_bytes()); - assert_eq!(lhs.optional_bool(), rhs.optional_bool()); + assert_that!(lhs.optional_int64(), eq(rhs.optional_int64())); + assert_that!(lhs.optional_bytes(), eq(rhs.optional_bytes())); + assert_that!(lhs.optional_bool(), eq(rhs.optional_bool())); }}; } diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index 48424433d1e4..4369ae290312 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -229,9 +229,9 @@ fn test_oneof_mut_accessors() { match msg.oneof_field_mut() { OneofUint32(mut v) => { - assert_eq!(v.get(), 7); + assert_that!(v.get(), eq(7)); v.set(8); - assert_eq!(v.get(), 8); + assert_that!(v.get(), eq(8)); } f => panic!("unexpected field_mut type! {:?}", f), } diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 9f7d75ff5326..15758a1f2436 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -713,9 +713,9 @@ fn test_oneof_mut_accessors() { match msg.oneof_field_mut() { OneofUint32(mut v) => { - assert_eq!(v.get(), 7); + assert_that!(v.get(), eq(7)); v.set(8); - assert_eq!(v.get(), 8); + assert_that!(v.get(), eq(8)); } f => panic!("unexpected field_mut type! {:?}", f), } diff --git a/rust/utf8.rs b/rust/utf8.rs index 56a1c20b93e0..a452e8f91626 100644 --- a/rust/utf8.rs +++ b/rust/utf8.rs @@ -31,6 +31,7 @@ use std::str::from_utf8_unchecked; /// # Examples /// /// ``` +/// use googletest::prelude::*; /// use utf8::Utf8Chunks; /// /// // An invalid UTF-8 string @@ -40,10 +41,10 @@ use std::str::from_utf8_unchecked; /// let chunk = Utf8Chunks::new(bytes).next().unwrap(); /// /// // The first three characters are valid UTF-8 -/// assert_eq!("foo", chunk.valid()); +/// assert_that!("foo", eq(chunk.valid())); /// /// // The fourth character is broken -/// assert_eq!(b"\xF1\x80", chunk.invalid()); +/// assert_that!(b"\xF1\x80", eq(chunk.invalid())); /// ``` #[derive(Clone, Debug, PartialEq, Eq)] pub struct Utf8Chunk<'a> {