Better class test
This commit is contained in:
@@ -8,12 +8,12 @@ pub class Animal<T> {
|
|||||||
self.name = "Rex".to_string();
|
self.name = "Rex".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void speak(*self) {
|
pub fn String speak(*self) {
|
||||||
println!("Unknown");
|
"Unknown".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void test_speak(*self) {
|
pub fn void test_speak(*self) {
|
||||||
self.speak();
|
assert_eq!(self.speak(), "Woof!");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void static_method() {}
|
pub fn void static_method() {}
|
||||||
@@ -24,10 +24,9 @@ pub class Mammal<T> : Animal<T> {
|
|||||||
super = Super::new();
|
super = Super::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn void args_test(*self, x i32, y *str) {}
|
pub fn void args_test(*self, x i32, y *str) {
|
||||||
|
assert_eq!(x, 10);
|
||||||
pub fn *'a str returning<'a>(*self) {
|
assert_eq!(y, "hello");
|
||||||
"Mammal"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,12 +35,14 @@ pub class Dog : Mammal<i32> {
|
|||||||
super = Super::new();
|
super = Super::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub override(Animal<i32>) fn void speak(*self) {
|
pub override(Animal<i32>) fn String speak(*self) {
|
||||||
println!("Woof!");
|
"Woof!".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub override fn *str returning(*self) {
|
impl std::fmt::Display {
|
||||||
"Dog"
|
fn Result<(), std::fmt::Error> fmt(*self, f *mut std::fmt::Formatter<'_>) {
|
||||||
|
write!(f, "🐾 {}", self.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,5 +53,5 @@ pub fn void run_tests() {
|
|||||||
|
|
||||||
dawg.test_speak();
|
dawg.test_speak();
|
||||||
|
|
||||||
println!("{}", dawg.returning());
|
assert_eq!(format!("{dawg}"), "🐾 Rex");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user