Added items

This commit is contained in:
2026-06-16 13:15:01 +02:00
parent fa6765cdd9
commit e4fbab190c
8 changed files with 366 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
pub module struct_test;
struct Point {
x i32,
y i32,
}
pub fn void test_struct_create_access() {
let p = Point { x: 10, y: 20 };
assert_eq!(p.x, 10);
assert_eq!(p.y, 20);
}
pub fn void test_struct_mut_field() {
let mut p = Point { x: 1, y: 2 };
p.x = 100;
assert_eq!(p.x, 100);
}
pub fn void test_struct_destructure() {
let p = Point { x: 3, y: 4 };
let Point { x, y } = p;
assert_eq!(x, 3);
assert_eq!(y, 4);
}
struct Line {
start Point,
end Point,
}
pub fn void test_struct_nested() {
let l = Line {
start: Point { x: 0, y: 0 },
end: Point { x: 5, y: 10 },
};
assert_eq!(l.start.x, 0);
assert_eq!(l.end.y, 10);
}
pub fn void run_tests() {
test_struct_create_access();
test_struct_mut_field();
test_struct_destructure();
test_struct_nested();
}