use borrowscope_macro::trace_borrow;
#[trace_borrow]
fn simple_function() {
let x = 5;
assert_eq!(x, 5);
}
#[test]
fn test_simple_function() {
simple_function();
}
#[trace_borrow]
fn function_with_params(a: i32, b: i32) -> i32 {
a + b
}
#[test]
fn test_function_with_params() {
let result = function_with_params(2, 3);
assert_eq!(result, 5);
}
#[trace_borrow]
fn function_with_return() -> String {
String::from("hello")
}
#[test]
fn test_function_with_return() {
let result = function_with_return();
assert_eq!(result, "hello");
}
#[trace_borrow]
fn generic_function<T: Clone>(value: T) -> T {
value.clone()
}
#[test]
fn test_generic_function() {
let result = generic_function(42);
assert_eq!(result, 42);
let string_result = generic_function(String::from("test"));
assert_eq!(string_result, "test");
}
#[trace_borrow]
fn function_with_lifetime(s: &str) -> &str {
s
}
#[test]
fn test_function_with_lifetime() {
let result = function_with_lifetime("test");
assert_eq!(result, "test");
}
#[trace_borrow]
fn function_with_borrows() {
let x = String::from("hello");
let r1 = &x;
let r2 = &x;
assert_eq!(r1, r2);
assert_eq!(r1.len(), 5);
}
#[test]
fn test_function_with_borrows() {
function_with_borrows();
}
#[trace_borrow]
fn function_with_mut_borrow() {
let mut x = 5;
let r = &mut x;
*r += 1;
assert_eq!(x, 6);
}
#[test]
fn test_function_with_mut_borrow() {
function_with_mut_borrow();
}
#[trace_borrow]
fn function_with_control_flow(condition: bool) -> i32 {
if condition {
10
} else {
20
}
}
#[test]
fn test_function_with_control_flow() {
assert_eq!(function_with_control_flow(true), 10);
assert_eq!(function_with_control_flow(false), 20);
}
#[trace_borrow]
fn function_with_loop() -> i32 {
let mut sum = 0;
for i in 0..5 {
sum += i;
}
sum
}
#[test]
fn test_function_with_loop() {
assert_eq!(function_with_loop(), 10);
}
#[allow(clippy::let_and_return)]
#[trace_borrow]
fn function_with_move() -> String {
let s = String::from("moved");
s
}
#[test]
fn test_function_with_move() {
let result = function_with_move();
assert_eq!(result, "moved");
}