Updated tests and fixed grammar

This commit is contained in:
2026-06-23 03:44:54 +02:00
parent 2ae4ca510d
commit 2f6303ba30
14 changed files with 135 additions and 134 deletions
+8 -8
View File
@@ -1,41 +1,41 @@
pub module trait_test;
trait Speak {
fn String speak(*self);
String speak(&self);
}
trait Greet : Speak {
fn String greet(*self);
String greet(&self);
}
struct Dog {
name String,
String name,
}
impl Speak for Dog {
fn String speak(*self) {
String speak(&self) {
"woof".to_string()
}
}
impl Greet for Dog {
fn String greet(*self) {
String greet(&self) {
"hello".to_string()
}
}
pub fn void test_trait_impl() {
pub void test_trait_impl() {
let d = Dog { name: "Rex".to_string() };
assert_eq!(d.speak(), "woof");
}
pub fn void test_trait_with_requirement() {
pub void test_trait_with_requirement() {
let d = Dog { name: "Buddy".to_string() };
assert_eq!(d.speak(), "woof");
assert_eq!(d.greet(), "hello");
}
pub fn void run_tests() {
pub void run_tests() {
test_trait_impl();
test_trait_with_requirement();
}