Files
mist/mist-test/src/items/class_test.mist
T
2026-06-05 12:56:14 +02:00

57 lines
1022 B
Plaintext

pub class Counter {
pub i32 count;
pub constructor(i32 start) {
self.count = start;
}
pub void increment(self mut*) {
self.count++;
}
pub i32 get(self*) {
self.count
}
}
pub void test_class_create() {
let c = Counter::new(0);
assert_eq!(c.get(), 0);
}
pub void test_class_method() {
let mut c = Counter::new(5);
c.increment();
assert_eq!(c.get(), 6);
}
pub void test_class_field_access() {
let c = Counter::new(42);
assert_eq!(c.count, 42);
}
class NamedCounter : Counter {
pub String name;
pub constructor(i32 start, String name) {
self.name = name;
}
pub String get_name(self*) {
self.name.clone()
}
}
pub void test_class_inherit() {
let nc = NamedCounter::new(10, "test".to_string());
assert_eq!(nc.get_name(), "test");
assert_eq!(nc.count, 10);
}
pub void run_tests() {
test_class_create();
test_class_method();
test_class_field_access();
test_class_inherit();
}