2019-10-04 20:29:26 -04:00
|
|
|
use serde::Deserialize;
|
2018-12-10 12:53:56 -05:00
|
|
|
use 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
|
|
|
|
2019-04-28 09:24:58 -04:00
|
|
|
use alacritty_terminal::ansi;
|
2019-04-28 16:21:39 -04:00
|
|
|
use alacritty_terminal::clipboard::Clipboard;
|
2019-10-04 20:29:26 -04:00
|
|
|
use alacritty_terminal::config::MockConfig;
|
|
|
|
use alacritty_terminal::event::{Event, EventListener};
|
2019-04-28 09:24:58 -04:00
|
|
|
use alacritty_terminal::index::Column;
|
|
|
|
use alacritty_terminal::term::cell::Cell;
|
|
|
|
use alacritty_terminal::term::SizeInfo;
|
|
|
|
use alacritty_terminal::Grid;
|
|
|
|
use alacritty_terminal::Term;
|
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
|
2018-04-14 11:37:57 -04:00
|
|
|
grid_reset
|
2019-07-10 17:17:20 -04:00
|
|
|
row_reset
|
2018-12-09 10:28:22 -05:00
|
|
|
zerowidth
|
2019-08-06 18:59:16 -04:00
|
|
|
selective_erasure
|
2019-11-10 14:26:39 -05:00
|
|
|
colored_reset
|
2019-11-15 17:37:24 -05:00
|
|
|
delete_lines
|
2019-11-16 19:04:16 -05:00
|
|
|
delete_chars_reset
|
|
|
|
alt_reset
|
|
|
|
deccolm_reset
|
|
|
|
decaln_reset
|
|
|
|
insert_blank_reset
|
|
|
|
erase_chars_reset
|
|
|
|
scroll_up_reset
|
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>
|
2019-03-30 12:48:36 -04:00
|
|
|
where
|
|
|
|
P: AsRef<Path>,
|
2017-01-21 05:11:55 -05:00
|
|
|
{
|
|
|
|
let mut res = Vec::new();
|
2019-03-30 12:48:36 -04:00
|
|
|
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
|
|
|
|
2018-05-15 16:36:14 -04:00
|
|
|
fn read_string<P>(path: P) -> Result<String, ::std::io::Error>
|
2019-03-30 12:48:36 -04:00
|
|
|
where
|
|
|
|
P: AsRef<Path>,
|
2017-01-21 05:11:55 -05:00
|
|
|
{
|
|
|
|
let mut res = String::new();
|
2018-05-15 16:36:14 -04:00
|
|
|
File::open(path.as_ref()).and_then(|mut f| f.read_to_string(&mut res))?;
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2018-05-15 16:36:14 -04:00
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Default)]
|
|
|
|
struct RefConfig {
|
|
|
|
history_size: u32,
|
2017-01-21 05:11:55 -05:00
|
|
|
}
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2019-10-04 20:29:26 -04:00
|
|
|
struct Mock;
|
|
|
|
impl EventListener for Mock {
|
|
|
|
fn send_event(&self, _event: Event) {}
|
|
|
|
}
|
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
fn ref_test(dir: &Path) {
|
|
|
|
let recording = read_u8(dir.join("alacritty.recording"));
|
2018-05-15 16:36:14 -04:00
|
|
|
let serialized_size = read_string(dir.join("size.json")).unwrap();
|
|
|
|
let serialized_grid = read_string(dir.join("grid.json")).unwrap();
|
|
|
|
let serialized_cfg = read_string(dir.join("config.json")).unwrap_or_default();
|
2017-01-21 05:11:55 -05:00
|
|
|
|
|
|
|
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
|
|
|
|
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
|
2018-05-15 16:36:14 -04:00
|
|
|
let ref_config: RefConfig = json::from_str(&serialized_cfg).unwrap_or_default();
|
2016-11-19 19:16:20 -05:00
|
|
|
|
2019-10-04 20:29:26 -04:00
|
|
|
let mut config = MockConfig::default();
|
2019-05-10 07:36:16 -04:00
|
|
|
config.scrolling.set_history(ref_config.history_size);
|
2018-04-14 11:21:48 -04:00
|
|
|
|
2019-10-04 20:29:26 -04:00
|
|
|
let mut terminal = Term::new(&config, &size, Clipboard::new_nop(), Mock);
|
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
|
|
|
|
2018-05-15 16:36:14 -04:00
|
|
|
// Truncate invisible lines from the grid
|
|
|
|
let mut term_grid = terminal.grid().clone();
|
2018-12-07 20:50:01 -05:00
|
|
|
term_grid.initialize_all(&Cell::default());
|
2018-05-15 16:36:14 -04:00
|
|
|
term_grid.truncate();
|
|
|
|
|
|
|
|
if grid != term_grid {
|
2018-04-28 10:15:21 -04:00
|
|
|
for i in 0..grid.len() {
|
2018-04-14 11:21:48 -04:00
|
|
|
for j in 0..grid.num_cols().0 {
|
2018-12-07 20:50:01 -05:00
|
|
|
let cell = term_grid[i][Column(j)];
|
2018-04-14 11:21:48 -04:00
|
|
|
let original_cell = grid[i][Column(j)];
|
|
|
|
if original_cell != cell {
|
2019-03-30 12:48:36 -04:00
|
|
|
println!(
|
|
|
|
"[{i}][{j}] {original:?} => {now:?}",
|
|
|
|
i = i,
|
|
|
|
j = j,
|
2019-08-01 10:26:55 -04:00
|
|
|
original = original_cell,
|
|
|
|
now = cell,
|
2019-03-30 12:48:36 -04:00
|
|
|
);
|
2017-04-03 23:21:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("Ref test failed; grid doesn't match");
|
|
|
|
}
|
|
|
|
|
2018-05-15 16:36:14 -04:00
|
|
|
assert_eq!(grid, term_grid);
|
2016-11-19 19:16:20 -05:00
|
|
|
}
|