-
Notifications
You must be signed in to change notification settings - Fork 544
Expand file tree
/
Copy pathtest_template.tera
More file actions
27 lines (26 loc) · 1.1 KB
/
test_template.tera
File metadata and controls
27 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::collections::HashMap;
fn check_word_count(mut output: HashMap<String, u32>, pairs: &[(&str, u32)]) {
// The reason for the awkward code in here is to ensure that the failure
// message for assert_eq! is as informative as possible. A simpler
// solution would simply check the length of the map, and then
// check for the presence and value of each key in the given pairs vector.
for &(k, v) in pairs.iter() {
assert_eq!((k, output.remove(&k.to_string()).unwrap_or(0)), (k, v));
}
// may fail with a message that clearly shows all extra pairs in the map
assert_eq!(output.iter().collect::<Vec<(&String, &u32)>>(), vec![]);
}
{% for test in cases %}
#[test]
{% if loop.index != 1 -%}
#[ignore]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
let input = {{ test.input.sentence | json_encode() }};
let output = {{ crate_name }}::{{ fn_names[0] }}(input);
let expected = &[{% for key, value in test.expected -%}
({{ key | json_encode() }}, {{ value }}),
{%- endfor %}];
check_word_count(output, expected);
}
{% endfor -%}