Skip to content

Commit

Permalink
1. Improving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denisandroid committed Apr 7, 2024
1 parent 284041e commit a373fda
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 93 deletions.
60 changes: 60 additions & 0 deletions tests/logic.rs
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));
}
32 changes: 32 additions & 0 deletions tests/memsize.rs
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);
}
}
94 changes: 1 addition & 93 deletions tests/easy.rs → tests/syntax.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use std::sync::{Mutex, OnceLock};
use std::sync::OnceLock;
use drop_code::drop_code;

#[test]
Expand Down Expand Up @@ -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<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));
}

0 comments on commit a373fda

Please sign in to comment.