Skip to content

Commit 36ad856

Browse files
phip1611nicholasbishop
authored andcommitted
strings: add more tests for eq_str_until_nul()
1 parent 70d4011 commit 36ad856

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

uefi/src/data_types/owned_strs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ mod tests {
190190
);
191191
}
192192

193-
/// Tests the trait implementation of trait [EqStrUntilNul].
193+
/// Tests the trait implementation of trait [`EqStrUntilNul]` for [`CString16`].
194+
///
195+
/// This tests that `String` and `str` from the standard library can be
196+
/// checked for equality against a [`CString16`]. It checks both directions,
197+
/// i.e., the equality is reflexive.
194198
#[test]
195199
fn test_cstring16_eq_std_str() {
196200
let input = CString16::try_from("test").unwrap();
197201

198-
// test various comparisons with different order (left, right)
199202
assert!(input.eq_str_until_nul("test")); // requires ?Sized constraint
200203
assert!(input.eq_str_until_nul(&"test"));
201204
assert!(input.eq_str_until_nul(&String::from("test")));

uefi/src/data_types/strs.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,41 @@ mod tests {
578578
const S: &CStr16 = cstr16!("ABC");
579579
assert_eq!(S.to_u16_slice_with_nul(), [65, 66, 67, 0]);
580580
}
581+
582+
/// Tests the trait implementation of trait [`EqStrUntilNul]` for [`CStr8`].
583+
///
584+
/// This tests that `String` and `str` from the standard library can be
585+
/// checked for equality against a [`CStr8`]. It checks both directions,
586+
/// i.e., the equality is reflexive.
587+
#[test]
588+
fn test_cstr8_eq_std_str() {
589+
let input: &CStr8 = cstr8!("test");
590+
591+
// test various comparisons with different order (left, right)
592+
assert!(input.eq_str_until_nul("test")); // requires ?Sized constraint
593+
assert!(input.eq_str_until_nul(&"test"));
594+
assert!(input.eq_str_until_nul(&String::from("test")));
595+
596+
// now other direction
597+
assert!(String::from("test").eq_str_until_nul(input));
598+
assert!("test".eq_str_until_nul(input));
599+
}
600+
601+
/// Tests the trait implementation of trait [`EqStrUntilNul]` for [`CStr16`].
602+
///
603+
/// This tests that `String` and `str` from the standard library can be
604+
/// checked for equality against a [`CStr16`]. It checks both directions,
605+
/// i.e., the equality is reflexive.
606+
#[test]
607+
fn test_cstr16_eq_std_str() {
608+
let input: &CStr16 = cstr16!("test");
609+
610+
assert!(input.eq_str_until_nul("test")); // requires ?Sized constraint
611+
assert!(input.eq_str_until_nul(&"test"));
612+
assert!(input.eq_str_until_nul(&String::from("test")));
613+
614+
// now other direction
615+
assert!(String::from("test").eq_str_until_nul(input));
616+
assert!("test".eq_str_until_nul(input));
617+
}
581618
}

0 commit comments

Comments
 (0)