From a373fda782fbc6f33146796a9ef2559c19566715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=9A=D0=BE=D1=82=D0=BB?= =?UTF-8?q?=D1=8F=D1=80=D0=BE=D0=B2?= Date: Mon, 8 Apr 2024 01:40:23 +0300 Subject: [PATCH] 1. Improving tests --- tests/logic.rs | 60 +++++++++++++++++++++++ tests/memsize.rs | 32 ++++++++++++ tests/{easy.rs => syntax.rs} | 94 +----------------------------------- 3 files changed, 93 insertions(+), 93 deletions(-) create mode 100644 tests/logic.rs create mode 100644 tests/memsize.rs rename tests/{easy.rs => syntax.rs} (56%) diff --git a/tests/logic.rs b/tests/logic.rs new file mode 100644 index 0000000..652dd7d --- /dev/null +++ b/tests/logic.rs @@ -0,0 +1,60 @@ + +use std::sync::{Mutex, OnceLock}; +use drop_code::drop_code; + +#[test] +fn easy_use_emptyargs() { + static TEST_CINTERNAL: Mutex = Mutex::new(0); + + fn __tinternal(a: usize, b: usize) -> bool { + drop_code! { + let mut lock = TEST_CINTERNAL.lock().unwrap(); + *lock += 1; + } + if a == b { + // autorun drop code + return true; + } + + // autorun drop code + false + } + + assert_eq!(*TEST_CINTERNAL.lock().unwrap(), 0); + let rin = __tinternal(1, 1); + assert_eq!(rin, true); + assert_eq!(*TEST_CINTERNAL.lock().unwrap(), 1); +} + + +#[test] +fn easy_use_twoargs() { + static OLD_A: OnceLock = OnceLock::new(); + static OLD_B: OnceLock = OnceLock::new(); + + fn __tinternal(a: usize, b: usize) -> bool { + drop_code!((a: usize, b: usize) { + OLD_A.set(*a).unwrap(); + OLD_B.set(*b).unwrap(); + }); + if a == b { + // autorun drop code + return true; + } + + if a == 1 { + // autorun drop code + return true; + } + + // autorun drop code + false + } + + assert_eq!(OLD_A.get(), None); + assert_eq!(OLD_B.get(), None); + let rin = __tinternal(1, 1); + assert_eq!(rin, true); + assert_eq!(OLD_A.get(), Some(&1)); + assert_eq!(OLD_B.get(), Some(&1)); +} diff --git a/tests/memsize.rs b/tests/memsize.rs new file mode 100644 index 0000000..82c7c48 --- /dev/null +++ b/tests/memsize.rs @@ -0,0 +1,32 @@ + +use drop_code::drop_code; + +#[test] +fn test_drop_code() { + { + let test = "test"; + let test2 = "test2"; + drop_code!(#[inline(always)]: () { + //println!("{}", test); + + println!("End0"); + }); + + drop_code! { + println!("End1"); + } + + drop_code! { + println!("End2"); + } + drop_code! ((test) { + println!("End3, size_of_val: {}", std::mem::size_of_val(&test)); + }); + drop_code! ((test, test2) { + println!("End4, size_of_val: {}", std::mem::size_of_val(&test)); + }); + + println!("@{}", test); + println!("@@{}", test); + } +} diff --git a/tests/easy.rs b/tests/syntax.rs similarity index 56% rename from tests/easy.rs rename to tests/syntax.rs index f026140..c5d5563 100644 --- a/tests/easy.rs +++ b/tests/syntax.rs @@ -1,5 +1,5 @@ -use std::sync::{Mutex, OnceLock}; +use std::sync::OnceLock; use drop_code::drop_code; #[test] @@ -96,95 +96,3 @@ fn auto_test_syntax() { }); } } - -#[test] -fn test_one_block() { - -} - -#[test] -fn test_drop_code() { - { - let test = "test"; - let test2 = "test2"; - drop_code!(#[inline(always)]: () { - //println!("{}", test); - - println!("End0"); - }); - - drop_code! { - println!("End1"); - } - - drop_code! { - println!("End2"); - } - drop_code! ((test) { - println!("End3, size_of_val: {}", std::mem::size_of_val(&test)); - }); - drop_code! ((test, test2) { - println!("End4, size_of_val: {}", std::mem::size_of_val(&test)); - }); - - println!("@{}", test); - println!("@@{}", test); - } -} - -#[test] -fn easy_use_emptyargs() { - static TEST_CINTERNAL: Mutex = Mutex::new(0); - - fn __tinternal(a: usize, b: usize) -> bool { - drop_code! { - let mut lock = TEST_CINTERNAL.lock().unwrap(); - *lock += 1; - } - if a == b { - // autorun drop code - return true; - } - - // autorun drop code - false - } - - assert_eq!(*TEST_CINTERNAL.lock().unwrap(), 0); - let rin = __tinternal(1, 1); - assert_eq!(rin, true); - assert_eq!(*TEST_CINTERNAL.lock().unwrap(), 1); -} - - -#[test] -fn easy_use_twoargs() { - static OLD_A: OnceLock = OnceLock::new(); - static OLD_B: OnceLock = OnceLock::new(); - - fn __tinternal(a: usize, b: usize) -> bool { - drop_code!((a: usize, b: usize) { - OLD_A.set(*a).unwrap(); - OLD_B.set(*b).unwrap(); - }); - if a == b { - // autorun drop code - return true; - } - - if a == 1 { - // autorun drop code - return true; - } - - // autorun drop code - false - } - - assert_eq!(OLD_A.get(), None); - assert_eq!(OLD_B.get(), None); - let rin = __tinternal(1, 1); - assert_eq!(rin, true); - assert_eq!(OLD_A.get(), Some(&1)); - assert_eq!(OLD_B.get(), Some(&1)); -}