Skip to main content

hello_sayer/
lib.rs

1pub fn generate_hello_message() -> &'static str {
2    "Hello world!"
3}
4
5pub fn say_hello() {
6    println!("{}", generate_hello_message())
7}
8
9pub fn say_hello_string(hello_string: &str) {
10    println!("{}", hello_string)
11}
12
13pub fn say_hello_handler(hello_handler: fn() -> &'static str) {
14    println!("{}", hello_handler())
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn does_generate_hello_message_return_hello_world() {
23        let result = generate_hello_message();
24        assert_eq!(result, "Hello world!");
25    }
26
27    #[test]
28    fn does_say_hello_not_fail() {
29        say_hello()
30    }
31
32    #[test]
33    fn does_say_hello_string_not_fail() {
34        let string = generate_hello_message();
35        say_hello_string(string)
36    }
37
38    #[test]
39    fn does_say_hello_handler_not_fail() {
40        say_hello_handler(generate_hello_message)
41    }
42}