From 86f467cee6d9551f5e4c9f2e16d6fa0c9bc232ce Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 18 Aug 2024 22:36:09 +0300 Subject: test(tazjin/german-string): add roundtrip proptests Change-Id: Iee392368252d5c6e96d879b213aee34a301d13d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12241 Reviewed-by: tazjin Autosubmit: tazjin Tested-by: BuildkiteCI --- users/tazjin/german-string/src/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/users/tazjin/german-string/src/lib.rs b/users/tazjin/german-string/src/lib.rs index ed2efd3872f1..7eb9eda4e88a 100644 --- a/users/tazjin/german-string/src/lib.rs +++ b/users/tazjin/german-string/src/lib.rs @@ -190,8 +190,28 @@ mod tests { ); } - // Test [`Eq`] implementation. proptest! { + #[test] + fn test_roundtrip_vec(input: Vec) { + let gs = GermanString::new_transient(input.as_slice()); + assert_eq!(input.len(), gs.len(), "length should match"); + + let out = gs.as_bytes().to_owned(); + assert_eq!(input, out, "roundtrip should yield same bytes"); + } + + #[test] + fn test_roundtrip_string(input: String) { + let gs = GermanString::new_transient(input.as_bytes()); + assert_eq!(input.len(), gs.len(), "length should match"); + + let out = String::from_utf8(gs.as_bytes().to_owned()) + .expect("string should be valid after roundtrip"); + + assert_eq!(input, out, "roundtrip should yield same string"); + } + + // Test [`Eq`] implementation. #[test] fn test_reflexivity(x: GermanString) { prop_assert!(x == x); -- cgit 1.4.1