Skip to content

Commit 5b1e673

Browse files
committed
fix(primitive_types4): Fail on a slice covering the wrong area
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.
1 parent 2cd0682 commit 5b1e673

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

exercises/primitive_types/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ compiler. In this section, we'll go through the most important ones.
66
#### Book Sections
77

88
- [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html)
9+
- [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html)

exercises/primitive_types/primitive_types4.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
// Get a slice out of Array a where the ??? is so that the `if` statement
33
// returns true. Scroll down for hints!!
44

5+
#[test]
56
fn main() {
67
let a = [1, 2, 3, 4, 5];
78

89
let nice_slice = ???
910

10-
if nice_slice == [2, 3, 4] {
11-
println!("Nice slice!");
12-
} else {
13-
println!("Not quite what I was expecting... I see: {:?}", nice_slice);
14-
}
11+
assert_eq!([2, 3, 4], nice_slice)
1512
}
1613

1714

@@ -33,6 +30,28 @@ fn main() {
3330

3431

3532

33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
3655

3756

3857

info.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mode = "compile"
6666

6767
[[exercises]]
6868
path = "exercises/primitive_types/primitive_types4.rs"
69-
mode = "compile"
69+
mode = "test"
7070

7171
[[exercises]]
7272
path = "exercises/primitive_types/primitive_types5.rs"

0 commit comments

Comments
 (0)