concat_bytes.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //! Test that the [`libthreema_macros::concat_fixed_bytes`] works as expected.
  2. #![expect(unused_crate_dependencies, reason = "False positive")]
  3. #![expect(clippy::min_ident_chars, reason = "Test variable names")]
  4. #![expect(clippy::tests_outside_test_module, reason = "trybuild tests work that way")]
  5. use libthreema_macros::concat_fixed_bytes;
  6. #[test]
  7. fn test_correct() {
  8. let a = [1_u8; 4];
  9. let b = [2_u8; 3];
  10. let c = [3_u8; 3];
  11. {
  12. #[expect(clippy::empty_structs_with_brackets, reason = "Concatenation of empty slices")]
  13. let result: [u8; 0] = concat_fixed_bytes!();
  14. assert_eq!(result, [] as [u8; 0]);
  15. }
  16. {
  17. let result: [u8; 4] = concat_fixed_bytes!(a);
  18. assert_eq!(result, [1, 1, 1, 1]);
  19. }
  20. {
  21. let result: [u8; 7] = concat_fixed_bytes!(a, b);
  22. assert_eq!(result, [1, 1, 1, 1, 2, 2, 2]);
  23. }
  24. {
  25. let result: [u8; 10] = concat_fixed_bytes!(a, b, c);
  26. assert_eq!(result, [1, 1, 1, 1, 2, 2, 2, 3, 3, 3]);
  27. }
  28. }
  29. #[test]
  30. fn compile_failures() {
  31. trybuild::TestCases::new().compile_fail("tests/fail/*.rs");
  32. }