Browse Source

tests: Add variant of assert_eq_fmt with the expected string literal

This will allow the test cases to include the expected value of the
string, which helps make clearer exactly what is being tested.
Nicholas Bishop 1 month ago
parent
commit
619eafc884
1 changed files with 6 additions and 0 deletions
  1. 6 0
      tests/tests.rs

+ 6 - 0
tests/tests.rs

@@ -46,6 +46,12 @@ macro_rules! assert_eq_fmt {
             *rust_fmt($format.as_ptr().cast(), $($p),*)
         );
     };
+    ($format:literal $(, $p:expr)* => $expected:literal) => {
+        let (bytes_written, s) = c_fmt!($format $(, $p)*);
+        assert_eq!(s, $expected);
+        assert_eq!((bytes_written, s), *rust_fmt($format.as_ptr().cast(), $($p),*));
+        assert_eq!(usize::try_from(bytes_written).unwrap(), $expected.len());
+    };
 }
 
 #[test]