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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#[step]
fn a_trivial_setup(context: &mut Context, initial: usize) {
context.counter = initial;
}
#[step]
fn a_trivial_cleanup(_context: &mut Context, _initial: usize) {}
#[step]
fn increment_counter(context: &mut Context) {
context.counter += 1;
}
#[step]
fn internal_check_counter(context: &Context, num: usize) {
if context.counter != num {
throw!(format!(
"Counter was wrong, it was {} but {} was expected",
context.counter, num
));
}
}
#[step]
fn check_counter(context: &ScenarioContext, num: usize) {
internal_check_counter::call(context, num)?;
}
#[step]
fn acquire_file_content(context: &mut Context, somename: &str, file: SubplotDataFile) {
context.remember_file(somename, file);
}
#[step]
fn remember_target(context: &mut Context, somename: &str) {
if let Some(file) = context.files.get(somename) {
context.this_file = Some(file.clone());
} else {
throw!(format!("Unknown file {}", somename));
}
}
#[step]
fn check_contents(context: &mut Context, text: &str) {
if let Some(file) = context.this_file.as_ref() {
let body_as_text = String::from_utf8_lossy(file.data());
if !body_as_text.as_ref().contains(text) {
throw!(format!(
"Failed to find {} when looking at {}",
text,
file.name().display()
));
}
} else {
throw!("Not looking at a file");
}
}
|