main.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //! 需要测试的时候可以在这里写测试代码,
  2. //! 然后在当前目录执行 `cargo expand --bin unified-init-expand`
  3. //! 就可以看到把proc macro展开后的代码了
  4. #![no_std]
  5. fn main() {
  6. todo!()
  7. }
  8. #[cfg(target_os = "none")]
  9. #[panic_handler]
  10. #[no_mangle]
  11. pub fn panic(_info: &core::panic::PanicInfo) -> ! {
  12. loop {}
  13. }
  14. #[cfg(test)]
  15. mod tests {
  16. use system_error::SystemError;
  17. use unified_init::define_unified_initializer_slice;
  18. use unified_init_macros::unified_init;
  19. use super::*;
  20. #[test]
  21. fn no_element() {
  22. define_unified_initializer_slice!(TEST_0);
  23. assert_eq!(TEST_0.len(), 0);
  24. }
  25. #[test]
  26. fn no_element_ne() {
  27. define_unified_initializer_slice!(TEST_0_NE);
  28. #[unified_init(TEST_0_NE)]
  29. fn x() -> Result<(), SystemError> {
  30. todo!()
  31. }
  32. assert_ne!(TEST_0_NE.len(), 0);
  33. }
  34. #[test]
  35. fn one_element() {
  36. define_unified_initializer_slice!(TEST_1);
  37. #[unified_init(TEST_1)]
  38. fn x() -> Result<(), SystemError> {
  39. todo!()
  40. }
  41. assert_eq!(TEST_1.len(), 1);
  42. }
  43. #[test]
  44. fn two_elements() {
  45. define_unified_initializer_slice!(TEST_2);
  46. #[unified_init(TEST_2)]
  47. fn x() -> Result<(), SystemError> {
  48. todo!()
  49. }
  50. #[unified_init(TEST_2)]
  51. fn y() -> Result<(), SystemError> {
  52. todo!()
  53. }
  54. assert_eq!(TEST_2.len(), 2);
  55. }
  56. }