2016-11-19 19:16:20 -05:00
|
|
|
extern crate alacritty;
|
2017-01-21 05:11:55 -05:00
|
|
|
extern crate serde_json as json;
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{self, Read};
|
2017-02-02 23:50:48 -05:00
|
|
|
use std::path::Path;
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
use alacritty::Grid;
|
2017-10-12 23:29:35 -04:00
|
|
|
use alacritty::grid::IndexRegion;
|
2017-01-21 05:11:55 -05:00
|
|
|
use alacritty::Term;
|
2017-04-03 23:21:55 -04:00
|
|
|
use alacritty::ansi;
|
2018-04-14 11:21:48 -04:00
|
|
|
use alacritty::index::Column;
|
2017-01-21 05:11:55 -05:00
|
|
|
use alacritty::term::Cell;
|
|
|
|
use alacritty::term::SizeInfo;
|
2017-04-03 23:21:55 -04:00
|
|
|
use alacritty::util::fmt::{Red, Green};
|
2018-04-14 11:21:48 -04:00
|
|
|
use alacritty::config::Config;
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-02-02 23:50:48 -05:00
|
|
|
macro_rules! ref_tests {
|
2017-02-27 11:03:08 -05:00
|
|
|
($($name:ident)*) => {
|
2017-02-02 23:50:48 -05:00
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let test_dir = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/ref"));
|
|
|
|
let test_path = test_dir.join(stringify!($name));
|
|
|
|
ref_test(&test_path);
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
2017-01-21 05:11:55 -05:00
|
|
|
}
|
2016-12-04 18:48:30 -05:00
|
|
|
|
2017-02-02 23:50:48 -05:00
|
|
|
ref_tests! {
|
2017-09-30 13:34:06 -04:00
|
|
|
csi_rep
|
2017-02-27 11:03:08 -05:00
|
|
|
fish_cc
|
|
|
|
indexed_256_colors
|
2017-11-11 11:51:53 -05:00
|
|
|
issue_855
|
2017-02-27 11:03:08 -05:00
|
|
|
ll
|
2017-11-11 11:49:44 -05:00
|
|
|
newline_with_cursor_beyond_scroll_region
|
2017-04-04 11:47:28 -04:00
|
|
|
tab_rendering
|
2017-02-27 11:03:08 -05:00
|
|
|
tmux_git_log
|
|
|
|
tmux_htop
|
2017-11-11 11:49:44 -05:00
|
|
|
vim_24bitcolors_bce
|
2017-02-27 11:03:08 -05:00
|
|
|
vim_large_window_scroll
|
|
|
|
vim_simple_edit
|
2017-04-19 23:24:02 -04:00
|
|
|
vttest_cursor_movement_1
|
2017-05-01 01:10:38 -04:00
|
|
|
vttest_insert
|
2017-04-19 23:24:02 -04:00
|
|
|
vttest_origin_mode_1
|
|
|
|
vttest_origin_mode_2
|
2017-04-19 23:17:13 -04:00
|
|
|
vttest_scroll
|
2017-05-01 00:11:47 -04:00
|
|
|
vttest_tab_clear_set
|
2017-02-27 11:03:08 -05:00
|
|
|
zsh_tab_completion
|
2018-04-14 11:21:48 -04:00
|
|
|
history
|
2017-01-21 05:11:55 -05:00
|
|
|
}
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
fn read_u8<P>(path: P) -> Vec<u8>
|
|
|
|
where P: AsRef<Path>
|
|
|
|
{
|
|
|
|
let mut res = Vec::new();
|
|
|
|
File::open(path.as_ref()).unwrap()
|
|
|
|
.read_to_end(&mut res).unwrap();
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
res
|
|
|
|
}
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
fn read_string<P>(path: P) -> String
|
|
|
|
where P: AsRef<Path>
|
|
|
|
{
|
|
|
|
let mut res = String::new();
|
|
|
|
File::open(path.as_ref()).unwrap()
|
|
|
|
.read_to_string(&mut res).unwrap();
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
res
|
|
|
|
}
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
fn ref_test(dir: &Path) {
|
|
|
|
let recording = read_u8(dir.join("alacritty.recording"));
|
|
|
|
let serialized_size = read_string(dir.join("size.json"));
|
|
|
|
let serialized_grid = read_string(dir.join("grid.json"));
|
|
|
|
|
|
|
|
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
|
|
|
|
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2018-04-14 11:21:48 -04:00
|
|
|
let mut config: Config = Default::default();
|
|
|
|
config.set_history(grid.history_size() as u32);
|
|
|
|
|
|
|
|
let mut terminal = Term::new(&config, size);
|
2017-01-21 05:11:55 -05:00
|
|
|
let mut parser = ansi::Processor::new();
|
|
|
|
|
|
|
|
for byte in recording {
|
|
|
|
parser.advance(&mut terminal, byte, &mut io::sink());
|
2016-11-19 21:12:04 -05:00
|
|
|
}
|
2017-01-21 05:11:55 -05:00
|
|
|
|
2017-04-03 23:21:55 -04:00
|
|
|
if grid != *terminal.grid() {
|
2018-04-14 11:21:48 -04:00
|
|
|
for i in 0..(grid.num_lines().0 + grid.history_size()) {
|
|
|
|
for j in 0..grid.num_cols().0 {
|
|
|
|
let cell = terminal.grid()[i][Column(j)];
|
|
|
|
let original_cell = grid[i][Column(j)];
|
|
|
|
if original_cell != cell {
|
2017-04-03 23:21:55 -04:00
|
|
|
println!("[{i}][{j}] {original:?} => {now:?}",
|
|
|
|
i=i, j=j, original=Green(original_cell), now=Red(cell));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("Ref test failed; grid doesn't match");
|
|
|
|
}
|
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
assert_eq!(grid, *terminal.grid());
|
2016-11-19 19:16:20 -05:00
|
|
|
}
|