diff options
| author | bors <bors@rust-lang.org> | 2019-08-18 08:24:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-08-18 08:24:44 +0000 |
| commit | c5bb32253b145b96c2f3049c2f0644f13d921290 (patch) | |
| tree | d256c711aa4c1a8a12a14b7122d755df37a52d16 | |
| parent | 2cd06826c0f4da8bc92825717e73eb44cd18095d (diff) | |
| parent | 5b1e673cec1658afc4ebbbc800213847804facf5 (diff) | |
Auto merge of #209 - Dylnuge:slice-assert, r=komaeda
fix(primitive_types4): Fail on a slice covering the wrong area
I noticed this issue and it seems like a similar one was raised/fixed in #160 this way. This is my first contribution to this repo (or any Rust project) so let me know if I messed up or need to fix anything!
---
This commit converts primitive_types4 to a test and asserts that the
slice given is equal to the expected slice.
The intent of the primitive_types4 exercise appears to be to ensure the
user understands inclusive and exclusive bounds as well as slice syntax.
`rustlings` commands using `compile` do not verify that a specific
println is reached and, in the case of `watch` and `verify` (but not
`run`), they do not output the `println`s at all.
This fix is semantically similar to #198. It does not take a stance on
the correct way to handle this for all exercises; see #127. There are
likely other exercises whose intent are masked by this issue.
| -rw-r--r-- | exercises/primitive_types/README.md | 1 | ||||
| -rw-r--r-- | exercises/primitive_types/primitive_types4.rs | 29 | ||||
| -rw-r--r-- | info.toml | 2 |
3 files changed, 26 insertions, 6 deletions
diff --git a/exercises/primitive_types/README.md b/exercises/primitive_types/README.md index b53394a..daa70ee 100644 --- a/exercises/primitive_types/README.md +++ b/exercises/primitive_types/README.md @@ -6,3 +6,4 @@ compiler. In this section, we'll go through the most important ones. #### Book Sections - [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html) +- [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html) diff --git a/exercises/primitive_types/primitive_types4.rs b/exercises/primitive_types/primitive_types4.rs index 1147cf7..e1ccdbc 100644 --- a/exercises/primitive_types/primitive_types4.rs +++ b/exercises/primitive_types/primitive_types4.rs @@ -2,16 +2,13 @@ // Get a slice out of Array a where the ??? is so that the `if` statement // returns true. Scroll down for hints!! +#[test] fn main() { let a = [1, 2, 3, 4, 5]; let nice_slice = ??? - if nice_slice == [2, 3, 4] { - println!("Nice slice!"); - } else { - println!("Not quite what I was expecting... I see: {:?}", nice_slice); - } + assert_eq!([2, 3, 4], nice_slice) } @@ -38,6 +35,28 @@ fn main() { + + + + + + + + + + + + + + + + + + + + + + // Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book: // https://doc.rust-lang.org/book/ch04-03-slices.html // and use the starting and ending indices of the items in the Array @@ -66,7 +66,7 @@ mode = "compile" [[exercises]] path = "exercises/primitive_types/primitive_types4.rs" -mode = "compile" +mode = "test" [[exercises]] path = "exercises/primitive_types/primitive_types5.rs" |
