about summary refs log tree commit diff
path: root/users/tazjin/german-string/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2024-08-18T19·36+0300
committerclbot <clbot@tvl.fyi>2024-08-19T13·19+0000
commit86f467cee6d9551f5e4c9f2e16d6fa0c9bc232ce (patch)
tree43d2a315e527acec77a69a34a31a1c22dbd5e1b3 /users/tazjin/german-string/src/lib.rs
parent64a085cf52bbb04effe2846b4a780e37d4ff8408 (diff)
test(tazjin/german-string): add roundtrip proptests r/8531
Change-Id: Iee392368252d5c6e96d879b213aee34a301d13d6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12241
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/german-string/src/lib.rs')
-rw-r--r--users/tazjin/german-string/src/lib.rs22
1 files changed, 21 insertions, 1 deletions
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,9 +190,29 @@ mod tests {
         );
     }
 
-    // Test [`Eq`] implementation.
     proptest! {
         #[test]
+        fn test_roundtrip_vec(input: Vec<u8>) {
+            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);
         }