2018-05-15 16:36:14 -04:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
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
|
|
|
|
2017-01-21 05:11:55 -05:00
|
|
|
use alacritty::Grid;
|
|
|
|
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;
|
2019-02-07 17:36:45 -05:00
|
|
|
use alacritty::term::cell::Cell;
|
2017-01-21 05:11:55 -05:00
|
|
|
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;
|
2019-02-07 17:36:45 -05:00
|
|
|
use alacritty::message_bar::MessageBuffer;
|
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
|
2018-12-09 10:28:22 -05:00
|
|
|
zerowidth
|
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
|
|
|
|
2018-05-15 16:36:14 -04:00
|
|
|
fn read_string<P>(path: P) -> Result<String, ::std::io::Error>
|
2017-01-21 05:11:55 -05:00
|
|
|
where P: AsRef<Path>
|
|
|
|
{
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2018-04-14 11:21:48 -04:00
|
|
|
let mut config: Config = Default::default();
|
2018-05-15 16:36:14 -04:00
|
|
|
config.set_history(ref_config.history_size);
|
2018-04-14 11:21:48 -04:00
|
|
|
|
2019-02-07 17:36:45 -05:00
|
|
|
let mut terminal = Term::new(&config, size, MessageBuffer::new());
|
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 {
|
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");
|
|
|
|
}
|
|
|
|
|
2018-05-15 16:36:14 -04:00
|
|
|
assert_eq!(grid, term_grid);
|
2016-11-19 19:16:20 -05:00
|
|
|
}
|