Skip to content

Commit

Permalink
hello-world: simplify to unconditional "Hello, World!" (#255)
Browse files Browse the repository at this point in the history
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
petertseng authored Feb 20, 2017
1 parent 5bea345 commit 3275c18
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"slug": "hello-world",
"difficulty": 1,
"topics": [
"Some/None",
"println!"
]
},
Expand Down
7 changes: 2 additions & 5 deletions exercises/hello-world/example.rs
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!"
}
5 changes: 5 additions & 0 deletions exercises/hello-world/src/lib.rs
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!"
}
16 changes: 2 additions & 14 deletions exercises/hello-world/tests/hello-world.rs
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());
}

0 comments on commit 3275c18

Please sign in to comment.