Migrate all remaining instances of assert_eq! to googletest-rust sans strings

PiperOrigin-RevId: 592022421
pull/15097/head
Hong Shin 1 year ago committed by Copybara-Service
parent cdcb6e7b56
commit 52ee619733
  1. 13
      rust/proxied.rs
  2. 1
      rust/test/cpp/interop/BUILD
  3. 7
      rust/test/cpp/interop/main.rs
  4. 4
      rust/test/shared/accessors_proto3_test.rs
  5. 4
      rust/test/shared/accessors_test.rs
  6. 5
      rust/utf8.rs

@ -289,6 +289,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use googletest::prelude::*;
use std::borrow::Cow; use std::borrow::Cow;
#[derive(Debug, Default, PartialEq)] #[derive(Debug, Default, PartialEq)]
@ -414,7 +415,7 @@ mod tests {
let my_view = my_proxied.as_view(); 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] #[test]
@ -425,8 +426,8 @@ mod tests {
my_mut.set("Hello indeed".to_string()); my_mut.set("Hello indeed".to_string());
let val_after_set = my_mut.as_view().val().to_string(); let val_after_set = my_mut.as_view().val().to_string();
assert_eq!(my_proxied.val, val_after_set); assert_that!(my_proxied.val, eq(val_after_set));
assert_eq!(my_proxied.val, "Hello indeed"); assert_that!(my_proxied.val, eq("Hello indeed"));
} }
fn reborrow_mut_into_view<'msg>(x: Mut<'msg, MyProxied>) -> View<'msg, MyProxied> { fn reborrow_mut_into_view<'msg>(x: Mut<'msg, MyProxied>) -> View<'msg, MyProxied> {
@ -557,12 +558,12 @@ mod tests {
fn test_set() { fn test_set() {
let mut my_proxied = MyProxied::default(); let mut my_proxied = MyProxied::default();
my_proxied.as_mut().set("hello"); 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")); 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")); 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"));
} }
} }

@ -21,6 +21,7 @@ rust_test(
], ],
deps = [ deps = [
":test_utils", ":test_utils",
"@crate_index//:googletest",
"//rust:protobuf_cpp", "//rust:protobuf_cpp",
"//rust/test:unittest_cc_rust_proto", "//rust/test:unittest_cc_rust_proto",
], ],

@ -5,6 +5,7 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd // https://developers.google.com/open-source/licenses/bsd
use googletest::prelude::*;
use protobuf_cpp::__internal::PtrAndLen; use protobuf_cpp::__internal::PtrAndLen;
use protobuf_cpp::__internal::RawMessage; use protobuf_cpp::__internal::RawMessage;
use unittest_proto::proto2_unittest::TestAllExtensions; use unittest_proto::proto2_unittest::TestAllExtensions;
@ -15,9 +16,9 @@ macro_rules! proto_assert_eq {
let lhs = &$lhs; let lhs = &$lhs;
let rhs = &$rhs; let rhs = &$rhs;
assert_eq!(lhs.optional_int64(), rhs.optional_int64()); assert_that!(lhs.optional_int64(), eq(rhs.optional_int64()));
assert_eq!(lhs.optional_bytes(), rhs.optional_bytes()); assert_that!(lhs.optional_bytes(), eq(rhs.optional_bytes()));
assert_eq!(lhs.optional_bool(), rhs.optional_bool()); assert_that!(lhs.optional_bool(), eq(rhs.optional_bool()));
}}; }};
} }

@ -229,9 +229,9 @@ fn test_oneof_mut_accessors() {
match msg.oneof_field_mut() { match msg.oneof_field_mut() {
OneofUint32(mut v) => { OneofUint32(mut v) => {
assert_eq!(v.get(), 7); assert_that!(v.get(), eq(7));
v.set(8); v.set(8);
assert_eq!(v.get(), 8); assert_that!(v.get(), eq(8));
} }
f => panic!("unexpected field_mut type! {:?}", f), f => panic!("unexpected field_mut type! {:?}", f),
} }

@ -713,9 +713,9 @@ fn test_oneof_mut_accessors() {
match msg.oneof_field_mut() { match msg.oneof_field_mut() {
OneofUint32(mut v) => { OneofUint32(mut v) => {
assert_eq!(v.get(), 7); assert_that!(v.get(), eq(7));
v.set(8); v.set(8);
assert_eq!(v.get(), 8); assert_that!(v.get(), eq(8));
} }
f => panic!("unexpected field_mut type! {:?}", f), f => panic!("unexpected field_mut type! {:?}", f),
} }

@ -31,6 +31,7 @@ use std::str::from_utf8_unchecked;
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use googletest::prelude::*;
/// use utf8::Utf8Chunks; /// use utf8::Utf8Chunks;
/// ///
/// // An invalid UTF-8 string /// // An invalid UTF-8 string
@ -40,10 +41,10 @@ use std::str::from_utf8_unchecked;
/// let chunk = Utf8Chunks::new(bytes).next().unwrap(); /// let chunk = Utf8Chunks::new(bytes).next().unwrap();
/// ///
/// // The first three characters are valid UTF-8 /// // The first three characters are valid UTF-8
/// assert_eq!("foo", chunk.valid()); /// assert_that!("foo", eq(chunk.valid()));
/// ///
/// // The fourth character is broken /// // 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)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Utf8Chunk<'a> { pub struct Utf8Chunk<'a> {

Loading…
Cancel
Save