Skip to content

Commit

Permalink
Use glob import in default test template (#1819)
Browse files Browse the repository at this point in the history
Glob imports are a better default for the test template. Some exercises
may require the student to implement a method. If the test file doesn't
have a glob import, the students will be forced to implement an inherent
method on a struct. On the other hand, if a glob import is used, the
students may choose to implement it as a method on a trait.
Traits are a powerful feature of Rust, so we want to enable students to
experiment with them whenever possible.
  • Loading branch information
senekor authored Dec 12, 2023
1 parent c8caf0b commit c7351dd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rust-tooling/generate/templates/default_test_template.tera
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use {{ crate_name }}::*;

{% for test in cases %}
#[test]
{% if loop.index != 1 -%}
#[ignore]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
let input = {{ test.input | json_encode() }};
let output = {{ crate_name }}::{{ fn_names[0] }}(input);
let output = {{ fn_names[0] }}(input);
let expected = {{ test.expected | json_encode() }};
assert_eq!(output, expected);
}
Expand Down

0 comments on commit c7351dd

Please sign in to comment.