2019-10-05 02:29:26 +02:00
|
|
|
use serde::Deserialize;
|
2018-12-10 09:53:56 -08:00
|
|
|
use serde_json as json;
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2017-01-21 10:11:55 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{self, Read};
|
2017-02-02 20:50:48 -08:00
|
|
|
use std::path::Path;
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2019-04-28 06:24:58 -07:00
|
|
|
use alacritty_terminal::ansi;
|
2019-04-28 20:21:39 +00:00
|
|
|
use alacritty_terminal::clipboard::Clipboard;
|
2019-10-05 02:29:26 +02:00
|
|
|
use alacritty_terminal::config::MockConfig;
|
|
|
|
use alacritty_terminal::event::{Event, EventListener};
|
2019-04-28 06:24:58 -07: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 16:16:20 -08:00
|
|
|
|
2017-02-02 20:50:48 -08:00
|
|
|
macro_rules! ref_tests {
|
2017-02-27 08:03:08 -08:00
|
|
|
($($name:ident)*) => {
|
2017-02-02 20:50:48 -08: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 10:11:55 +00:00
|
|
|
}
|
2016-12-04 15:48:30 -08:00
|
|
|
|
2017-02-02 20:50:48 -08:00
|
|
|
ref_tests! {
|
2017-09-30 10:34:06 -07:00
|
|
|
csi_rep
|
2017-02-27 08:03:08 -08:00
|
|
|
fish_cc
|
|
|
|
indexed_256_colors
|
2017-11-11 08:51:53 -08:00
|
|
|
issue_855
|
2017-02-27 08:03:08 -08:00
|
|
|
ll
|
2017-11-11 08:49:44 -08:00
|
|
|
newline_with_cursor_beyond_scroll_region
|
2017-04-04 08:47:28 -07:00
|
|
|
tab_rendering
|
2017-02-27 08:03:08 -08:00
|
|
|
tmux_git_log
|
|
|
|
tmux_htop
|
2017-11-11 08:49:44 -08:00
|
|
|
vim_24bitcolors_bce
|
2017-02-27 08:03:08 -08:00
|
|
|
vim_large_window_scroll
|
|
|
|
vim_simple_edit
|
2017-04-19 20:24:02 -07:00
|
|
|
vttest_cursor_movement_1
|
2017-04-30 22:10:38 -07:00
|
|
|
vttest_insert
|
2017-04-19 20:24:02 -07:00
|
|
|
vttest_origin_mode_1
|
|
|
|
vttest_origin_mode_2
|
2017-04-19 20:17:13 -07:00
|
|
|
vttest_scroll
|
2017-04-30 21:11:47 -07:00
|
|
|
vttest_tab_clear_set
|
2017-02-27 08:03:08 -08:00
|
|
|
zsh_tab_completion
|
2018-04-14 17:21:48 +02:00
|
|
|
history
|
2018-04-14 17:37:57 +02:00
|
|
|
grid_reset
|
2019-07-10 21:17:20 +00:00
|
|
|
row_reset
|
2018-12-09 15:28:22 +00:00
|
|
|
zerowidth
|
2019-08-07 07:59:16 +09:00
|
|
|
selective_erasure
|
2019-11-10 20:26:39 +01:00
|
|
|
colored_reset
|
2019-11-15 23:37:24 +01:00
|
|
|
delete_lines
|
2019-11-17 03:04:16 +03:00
|
|
|
delete_chars_reset
|
|
|
|
alt_reset
|
|
|
|
deccolm_reset
|
|
|
|
decaln_reset
|
|
|
|
insert_blank_reset
|
|
|
|
erase_chars_reset
|
|
|
|
scroll_up_reset
|
2017-01-21 10:11:55 +00:00
|
|
|
}
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2017-01-21 10:11:55 +00:00
|
|
|
fn read_u8<P>(path: P) -> Vec<u8>
|
2019-03-30 16:48:36 +00:00
|
|
|
where
|
|
|
|
P: AsRef<Path>,
|
2017-01-21 10:11:55 +00:00
|
|
|
{
|
|
|
|
let mut res = Vec::new();
|
2019-03-30 16:48:36 +00:00
|
|
|
File::open(path.as_ref()).unwrap().read_to_end(&mut res).unwrap();
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2017-01-21 10:11:55 +00:00
|
|
|
res
|
|
|
|
}
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2018-05-15 22:36:14 +02:00
|
|
|
fn read_string<P>(path: P) -> Result<String, ::std::io::Error>
|
2019-03-30 16:48:36 +00:00
|
|
|
where
|
|
|
|
P: AsRef<Path>,
|
2017-01-21 10:11:55 +00:00
|
|
|
{
|
|
|
|
let mut res = String::new();
|
2018-05-15 22:36:14 +02:00
|
|
|
File::open(path.as_ref()).and_then(|mut f| f.read_to_string(&mut res))?;
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2018-05-15 22:36:14 +02:00
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Default)]
|
|
|
|
struct RefConfig {
|
|
|
|
history_size: u32,
|
2017-01-21 10:11:55 +00:00
|
|
|
}
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2019-10-05 02:29:26 +02:00
|
|
|
struct Mock;
|
|
|
|
impl EventListener for Mock {
|
|
|
|
fn send_event(&self, _event: Event) {}
|
|
|
|
}
|
|
|
|
|
2017-01-21 10:11:55 +00:00
|
|
|
fn ref_test(dir: &Path) {
|
|
|
|
let recording = read_u8(dir.join("alacritty.recording"));
|
2018-05-15 22:36:14 +02: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 10:11:55 +00:00
|
|
|
|
|
|
|
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
|
|
|
|
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
|
2018-05-15 22:36:14 +02:00
|
|
|
let ref_config: RefConfig = json::from_str(&serialized_cfg).unwrap_or_default();
|
2016-11-19 16:16:20 -08:00
|
|
|
|
2019-10-05 02:29:26 +02:00
|
|
|
let mut config = MockConfig::default();
|
2019-05-10 11:36:16 +00:00
|
|
|
config.scrolling.set_history(ref_config.history_size);
|
2018-04-14 17:21:48 +02:00
|
|
|
|
2019-10-05 02:29:26 +02:00
|
|
|
let mut terminal = Term::new(&config, &size, Clipboard::new_nop(), Mock);
|
2017-01-21 10:11:55 +00:00
|
|
|
let mut parser = ansi::Processor::new();
|
|
|
|
|
|
|
|
for byte in recording {
|
|
|
|
parser.advance(&mut terminal, byte, &mut io::sink());
|
2016-11-19 18:12:04 -08:00
|
|
|
}
|
2017-01-21 10:11:55 +00:00
|
|
|
|
2018-05-15 22:36:14 +02:00
|
|
|
// Truncate invisible lines from the grid
|
|
|
|
let mut term_grid = terminal.grid().clone();
|
2018-12-08 01:50:01 +00:00
|
|
|
term_grid.initialize_all(&Cell::default());
|
2018-05-15 22:36:14 +02:00
|
|
|
term_grid.truncate();
|
|
|
|
|
|
|
|
if grid != term_grid {
|
2018-04-28 16:15:21 +02:00
|
|
|
for i in 0..grid.len() {
|
2018-04-14 17:21:48 +02:00
|
|
|
for j in 0..grid.num_cols().0 {
|
2018-12-08 01:50:01 +00:00
|
|
|
let cell = term_grid[i][Column(j)];
|
2018-04-14 17:21:48 +02:00
|
|
|
let original_cell = grid[i][Column(j)];
|
|
|
|
if original_cell != cell {
|
2019-03-30 16:48:36 +00:00
|
|
|
println!(
|
|
|
|
"[{i}][{j}] {original:?} => {now:?}",
|
|
|
|
i = i,
|
|
|
|
j = j,
|
2019-08-01 14:26:55 +00:00
|
|
|
original = original_cell,
|
|
|
|
now = cell,
|
2019-03-30 16:48:36 +00:00
|
|
|
);
|
2017-04-03 20:21:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("Ref test failed; grid doesn't match");
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:36:14 +02:00
|
|
|
assert_eq!(grid, term_grid);
|
2016-11-19 16:16:20 -08:00
|
|
|
}
|