Skip to content

Commit

Permalink
Migrate all remaining instances of assert_eq! to googletest-rust sans…
Browse files Browse the repository at this point in the history
… strings

PiperOrigin-RevId: 592022421
  • Loading branch information
honglooker authored and copybara-github committed Dec 18, 2023
1 parent cdcb6e7 commit 52ee619
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
13 changes: 7 additions & 6 deletions rust/proxied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use googletest::prelude::*;
use std::borrow::Cow;

#[derive(Debug, Default, PartialEq)]
Expand Down Expand Up @@ -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]
Expand All @@ -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> {
Expand Down Expand Up @@ -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"));
}
}
1 change: 1 addition & 0 deletions rust/test/cpp/interop/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rust_test(
],
deps = [
":test_utils",
"@crate_index//:googletest",
"//rust:protobuf_cpp",
"//rust/test:unittest_cc_rust_proto",
],
Expand Down
7 changes: 4 additions & 3 deletions rust/test/cpp/interop/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
}};
}

Expand Down
4 changes: 2 additions & 2 deletions rust/test/shared/accessors_proto3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
4 changes: 2 additions & 2 deletions rust/test/shared/accessors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
5 changes: 3 additions & 2 deletions rust/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use std::str::from_utf8_unchecked;
/// # Examples
///
/// ```
/// use googletest::prelude::*;
/// use utf8::Utf8Chunks;
///
/// // An invalid UTF-8 string
Expand All @@ -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> {
Expand Down

0 comments on commit 52ee619

Please sign in to comment.