-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
284041e
commit a373fda
Showing
3 changed files
with
93 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
use std::sync::{Mutex, OnceLock}; | ||
use drop_code::drop_code; | ||
|
||
#[test] | ||
fn easy_use_emptyargs() { | ||
static TEST_CINTERNAL: Mutex<u8> = 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<usize> = OnceLock::new(); | ||
static OLD_B: OnceLock<usize> = 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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters