test: enhance Rust test snippet with trait and struct examples

This commit is contained in:
Paul Gauthier (aider) 2024-11-27 06:53:41 -08:00
parent 0faff91c72
commit 10877a99f1

View file

@ -520,8 +520,41 @@ if __name__ == "__main__":
),
"rust": (
"test.rs",
'fn main() {\n println!("Hello, World!");\n}\n',
"main", # Key symbol to check
"""// Define a trait
trait Greeting {
fn greet(&self) -> String;
}
// Define a struct
struct Person {
name: String,
age: u32,
}
// Implement the trait for Person
impl Greeting for Person {
fn greet(&self) -> String {
format!("Hello, {}! You are {} years old.", self.name, self.age)
}
}
// Implementation block for Person
impl Person {
fn new(name: String, age: u32) -> Self {
Person { name, age }
}
}
// Constants
const DEFAULT_NAME: &str = "World";
const MAX_AGE: u32 = 150;
fn main() {
let person = Person::new(DEFAULT_NAME.to_string(), 30);
println!("{}", person.greet());
}
""",
"Person", # Key symbol to check
),
"typescript": (
"test.ts",