Skip to content

Commit

Permalink
chore(test): Follow naming convention of type (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Aug 3, 2024
1 parent 3a16662 commit aff5eed
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions tonic/src/metadata/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,85 +830,85 @@ fn test_from_shared_base64_encodes() {

#[test]
fn test_value_eq_value() {
type BMV = BinaryMetadataValue;
type AMV = AsciiMetadataValue;
type Bmv = BinaryMetadataValue;
type Amv = AsciiMetadataValue;

assert_eq!(AMV::from_static("abc"), AMV::from_static("abc"));
assert_ne!(AMV::from_static("abc"), AMV::from_static("ABC"));
assert_eq!(Amv::from_static("abc"), Amv::from_static("abc"));
assert_ne!(Amv::from_static("abc"), Amv::from_static("ABC"));

assert_eq!(BMV::from_bytes(b"abc"), BMV::from_bytes(b"abc"));
assert_ne!(BMV::from_bytes(b"abc"), BMV::from_bytes(b"ABC"));
assert_eq!(Bmv::from_bytes(b"abc"), Bmv::from_bytes(b"abc"));
assert_ne!(Bmv::from_bytes(b"abc"), Bmv::from_bytes(b"ABC"));

// Padding is ignored.
assert_eq!(
BMV::from_static("SGVsbG8hIQ=="),
BMV::from_static("SGVsbG8hIQ")
Bmv::from_static("SGVsbG8hIQ=="),
Bmv::from_static("SGVsbG8hIQ")
);
// Invalid values are all just invalid from this point of view.
unsafe {
assert_eq!(
BMV::from_shared_unchecked(Bytes::from_static(b"..{}")),
BMV::from_shared_unchecked(Bytes::from_static(b"{}.."))
Bmv::from_shared_unchecked(Bytes::from_static(b"..{}")),
Bmv::from_shared_unchecked(Bytes::from_static(b"{}.."))
);
}
}

#[test]
fn test_value_eq_str() {
type BMV = BinaryMetadataValue;
type AMV = AsciiMetadataValue;
type Bmv = BinaryMetadataValue;
type Amv = AsciiMetadataValue;

assert_eq!(AMV::from_static("abc"), "abc");
assert_ne!(AMV::from_static("abc"), "ABC");
assert_eq!("abc", AMV::from_static("abc"));
assert_ne!("ABC", AMV::from_static("abc"));
assert_eq!(Amv::from_static("abc"), "abc");
assert_ne!(Amv::from_static("abc"), "ABC");
assert_eq!("abc", Amv::from_static("abc"));
assert_ne!("ABC", Amv::from_static("abc"));

assert_eq!(BMV::from_bytes(b"abc"), "abc");
assert_ne!(BMV::from_bytes(b"abc"), "ABC");
assert_eq!("abc", BMV::from_bytes(b"abc"));
assert_ne!("ABC", BMV::from_bytes(b"abc"));
assert_eq!(Bmv::from_bytes(b"abc"), "abc");
assert_ne!(Bmv::from_bytes(b"abc"), "ABC");
assert_eq!("abc", Bmv::from_bytes(b"abc"));
assert_ne!("ABC", Bmv::from_bytes(b"abc"));

// Padding is ignored.
assert_eq!(BMV::from_static("SGVsbG8hIQ=="), "Hello!!");
assert_eq!("Hello!!", BMV::from_static("SGVsbG8hIQ=="));
assert_eq!(Bmv::from_static("SGVsbG8hIQ=="), "Hello!!");
assert_eq!("Hello!!", Bmv::from_static("SGVsbG8hIQ=="));
}

#[test]
fn test_value_eq_bytes() {
type BMV = BinaryMetadataValue;
type AMV = AsciiMetadataValue;
type Bmv = BinaryMetadataValue;
type Amv = AsciiMetadataValue;

assert_eq!(AMV::from_static("abc"), "abc".as_bytes());
assert_ne!(AMV::from_static("abc"), "ABC".as_bytes());
assert_eq!(*"abc".as_bytes(), AMV::from_static("abc"));
assert_ne!(*"ABC".as_bytes(), AMV::from_static("abc"));
assert_eq!(Amv::from_static("abc"), "abc".as_bytes());
assert_ne!(Amv::from_static("abc"), "ABC".as_bytes());
assert_eq!(*"abc".as_bytes(), Amv::from_static("abc"));
assert_ne!(*"ABC".as_bytes(), Amv::from_static("abc"));

assert_eq!(*"abc".as_bytes(), BMV::from_bytes(b"abc"));
assert_ne!(*"ABC".as_bytes(), BMV::from_bytes(b"abc"));
assert_eq!(*"abc".as_bytes(), Bmv::from_bytes(b"abc"));
assert_ne!(*"ABC".as_bytes(), Bmv::from_bytes(b"abc"));

// Padding is ignored.
assert_eq!(BMV::from_static("SGVsbG8hIQ=="), "Hello!!".as_bytes());
assert_eq!(*"Hello!!".as_bytes(), BMV::from_static("SGVsbG8hIQ=="));
assert_eq!(Bmv::from_static("SGVsbG8hIQ=="), "Hello!!".as_bytes());
assert_eq!(*"Hello!!".as_bytes(), Bmv::from_static("SGVsbG8hIQ=="));
}

#[test]
fn test_ascii_value_hash() {
use std::collections::hash_map::DefaultHasher;
type AMV = AsciiMetadataValue;
type Amv = AsciiMetadataValue;

fn hash(value: AMV) -> u64 {
fn hash(value: Amv) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}

let value1 = AMV::from_static("abc");
let value2 = AMV::from_static("abc");
let value1 = Amv::from_static("abc");
let value2 = Amv::from_static("abc");
assert_eq!(value1, value2);
assert_eq!(hash(value1), hash(value2));

let value1 = AMV::from_static("abc");
let value2 = AMV::from_static("xyz");
let value1 = Amv::from_static("abc");
let value2 = Amv::from_static("xyz");

assert_ne!(value1, value2);
assert_ne!(hash(value1), hash(value2));
Expand All @@ -917,46 +917,46 @@ fn test_ascii_value_hash() {
#[test]
fn test_valid_binary_value_hash() {
use std::collections::hash_map::DefaultHasher;
type BMV = BinaryMetadataValue;
type Bmv = BinaryMetadataValue;

fn hash(value: BMV) -> u64 {
fn hash(value: Bmv) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}

let value1 = BMV::from_bytes(b"abc");
let value2 = BMV::from_bytes(b"abc");
let value1 = Bmv::from_bytes(b"abc");
let value2 = Bmv::from_bytes(b"abc");
assert_eq!(value1, value2);
assert_eq!(hash(value1), hash(value2));

let value1 = BMV::from_bytes(b"abc");
let value2 = BMV::from_bytes(b"xyz");
let value1 = Bmv::from_bytes(b"abc");
let value2 = Bmv::from_bytes(b"xyz");
assert_ne!(value1, value2);
assert_ne!(hash(value1), hash(value2));
}

#[test]
fn test_invalid_binary_value_hash() {
use std::collections::hash_map::DefaultHasher;
type BMV = BinaryMetadataValue;
type Bmv = BinaryMetadataValue;

fn hash(value: BMV) -> u64 {
fn hash(value: Bmv) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}

unsafe {
let value1 = BMV::from_shared_unchecked(Bytes::from_static(b"..{}"));
let value2 = BMV::from_shared_unchecked(Bytes::from_static(b"{}.."));
let value1 = Bmv::from_shared_unchecked(Bytes::from_static(b"..{}"));
let value2 = Bmv::from_shared_unchecked(Bytes::from_static(b"{}.."));
assert_eq!(value1, value2);
assert_eq!(hash(value1), hash(value2));
}

unsafe {
let valid = BMV::from_bytes(b"abc");
let invalid = BMV::from_shared_unchecked(Bytes::from_static(b"{}.."));
let valid = Bmv::from_bytes(b"abc");
let invalid = Bmv::from_shared_unchecked(Bytes::from_static(b"{}.."));
assert_ne!(valid, invalid);
assert_ne!(hash(valid), hash(invalid));
}
Expand Down

0 comments on commit aff5eed

Please sign in to comment.