Updated class tests
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
pub module class_test;
|
pub module class_test;
|
||||||
|
|
||||||
|
pub enum AnimalType {
|
||||||
|
Mammal;
|
||||||
|
}
|
||||||
|
|
||||||
pub class Animal
|
pub class Animal
|
||||||
{
|
{
|
||||||
pub String name;
|
pub String name;
|
||||||
@@ -9,6 +13,10 @@ pub class Animal
|
|||||||
self.name = "Rex".to_string();
|
self.name = "Rex".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub virtual AnimalType get_animal_type(&self) {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
|
||||||
pub virtual String speak(&self)
|
pub virtual String speak(&self)
|
||||||
{
|
{
|
||||||
"Unknown".to_string()
|
"Unknown".to_string()
|
||||||
@@ -31,6 +39,11 @@ pub class Mammal : Animal
|
|||||||
super = Super::new();
|
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)
|
pub void args_test(&self, i32 x, str& y)
|
||||||
{
|
{
|
||||||
assert_eq!(x, 10);
|
assert_eq!(x, 10);
|
||||||
@@ -124,6 +137,7 @@ pub void run_tests()
|
|||||||
let dawg = Dog::new();
|
let dawg = Dog::new();
|
||||||
dawg.args_test(10, "hello");
|
dawg.args_test(10, "hello");
|
||||||
dawg.test_speak();
|
dawg.test_speak();
|
||||||
|
dawg.get_animal_type();
|
||||||
assert_eq!(format!("{dawg}"), "🐾 Rex");
|
assert_eq!(format!("{dawg}"), "🐾 Rex");
|
||||||
test_class_no_inheritance();
|
test_class_no_inheritance();
|
||||||
test_class_field_default();
|
test_class_field_default();
|
||||||
|
|||||||
Reference in New Issue
Block a user