-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hello-world: simplify to unconditional "Hello, World!" (#255)
The introductory exercise should require as little Rust knowledge as necessary. We'd like to introduce `cargo test` here since it will be used for all exercises, but introducing Option is too much. We add a stub in case it is not clear how to return a string. That way, the student only has to change the string provided. exercism/problem-specifications#520
- Loading branch information
1 parent
5bea345
commit 3275c18
Showing
4 changed files
with
9 additions
and
20 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
"slug": "hello-world", | ||
"difficulty": 1, | ||
"topics": [ | ||
"Some/None", | ||
"println!" | ||
] | ||
}, | ||
|
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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
pub fn hello(name: Option<&str>) -> String { | ||
match name { | ||
Some(n) => format!("Hello, {}!", n), | ||
None => "Hello, World!".to_string(), | ||
} | ||
pub fn hello() -> &'static str { | ||
"Hello, World!" | ||
} |
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,5 @@ | ||
// The &'static here means the return type has a static lifetime. | ||
// This is a Rust feature that you don't need to worry about now. | ||
pub fn hello() -> &'static str { | ||
"Goodbye, World!" | ||
} |
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 |
---|---|---|
@@ -1,18 +1,6 @@ | ||
extern crate hello_world; | ||
|
||
#[test] | ||
fn test_no_name() { | ||
assert_eq!("Hello, World!", hello_world::hello(None)); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_sample_name() { | ||
assert_eq!("Hello, Alice!", hello_world::hello(Some("Alice"))); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_other_same_name() { | ||
assert_eq!("Hello, Bob!", hello_world::hello(Some("Bob"))); | ||
fn test_hello_world() { | ||
assert_eq!("Hello, World!", hello_world::hello()); | ||
} |