Updated class tests

This commit is contained in:
2026-07-09 06:51:36 +02:00
parent df8e67fd4f
commit aacc08b983
+14
View File
@@ -1,5 +1,9 @@
pub module class_test;
pub enum AnimalType {
Mammal;
}
pub class Animal
{
pub String name;
@@ -9,6 +13,10 @@ pub class Animal
self.name = "Rex".to_string();
}
pub virtual AnimalType get_animal_type(&self) {
panic!()
}
pub virtual String speak(&self)
{
"Unknown".to_string()
@@ -31,6 +39,11 @@ pub class Mammal : Animal
super = Super::new();
}
// override without a target assumes current super
pub AnimalType get_animal_type(&self) override {
AnimalType::Mammal
}
pub void args_test(&self, i32 x, str& y)
{
assert_eq!(x, 10);
@@ -124,6 +137,7 @@ pub void run_tests()
let dawg = Dog::new();
dawg.args_test(10, "hello");
dawg.test_speak();
dawg.get_animal_type();
assert_eq!(format!("{dawg}"), "🐾 Rex");
test_class_no_inheritance();
test_class_field_default();