-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "the-unit-type" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dev-dependencies] | ||
syntest = { path = "../../crates/syntest" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
In Rust, the unit type `()` is a type that has exactly one value, also written as `()`. It is used to indicate the absence of a meaningful value and is often seen in functions that do not return a value. | ||
|
||
In this challenge, you will implement a function that prints a message and returns the unit type. | ||
|
||
## Your task | ||
|
||
You need to implement the function `print_message() -> ()` that prints `"Hello, Rust!"` to the console and returns the unit type. | ||
|
||
## Requirements | ||
|
||
- The `print_message` function should print `"Hello, Rust!"` to the console. | ||
- The function should return the unit type `()`. | ||
|
||
## Example | ||
|
||
```rust | ||
let result = print_message(); | ||
assert_eq!(result, ()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn print_message() -> () { | ||
println!("Hello, Rust!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn print_message() -> () { | ||
// TODO: Implement the function here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use syntest::Syntest; | ||
use the_unit_type::*; | ||
|
||
#[test] | ||
fn test_compiles() { | ||
print_message(); | ||
} | ||
|
||
#[test] | ||
fn test_prints() { | ||
let syntest = Syntest::new("print_message", "src/lib.rs"); | ||
|
||
let macros = syntest.mac.macros(); | ||
|
||
assert!(!macros.is_empty(), "You should use the `println!` macro"); | ||
assert_eq!(macros.len(), 1, "You should only print one message"); | ||
|
||
let macro_name = ¯os[0].name; | ||
|
||
assert_eq!(macro_name, "println", "You should use the `println!` macro"); | ||
|
||
for token in macros[0].tokens.iter() { | ||
let token = token.to_lowercase(); | ||
|
||
assert_eq!( | ||
(token.contains("hello"), token.contains("rust")), | ||
(true, true), | ||
"You should print `Hello, Rust!`" | ||
) | ||
} | ||
} | ||
} |