blob: 0259e25d5f25d7f40706fd785a6cada17f1feaee (
plain)
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
|
#[cfg(test)]
pub mod integration_test_utils {
use std::io::BufReader;
use bytelines::ByteLines;
use console::strip_ansi_codes;
use crate::config;
use crate::delta::delta;
pub fn make_config(_args: &[&str]) -> config::Config {
// FIXME: should not be necessary
let (dummy_minus_file, dummy_plus_file) = ("/dev/null", "/dev/null");
let mut args = vec![dummy_minus_file, dummy_plus_file];
for arg in _args {
args.push(arg);
}
args.push("--no-gitconfig");
config::Config::from_args(&args, &mut None)
}
pub fn get_line_of_code_from_delta(
input: &str,
line_number: usize,
expected_text: &str,
config: &config::Config,
) -> String {
let output = run_delta(&input, config);
let line_of_code = output.lines().nth(line_number).unwrap();
assert!(strip_ansi_codes(line_of_code) == expected_text);
line_of_code.to_string()
}
pub fn run_delta(input: &str, config: &config::Config) -> String {
let mut writer: Vec<u8> = Vec::new();
delta(
ByteLines::new(BufReader::new(input.as_bytes())),
&mut writer,
&config,
)
.unwrap();
String::from_utf8(writer).unwrap()
}
}
|