2016-11-19 19:16:20 -05:00
|
|
|
extern crate alacritty;
|
|
|
|
extern crate serde_json;
|
|
|
|
|
|
|
|
/// ref tests
|
|
|
|
mod reference {
|
|
|
|
use std::fs::File;
|
2016-12-04 18:48:30 -05:00
|
|
|
use std::io::{self, Read};
|
2016-11-19 19:16:20 -05:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use serde_json as json;
|
|
|
|
|
|
|
|
use alacritty::Grid;
|
|
|
|
use alacritty::Term;
|
|
|
|
use alacritty::term::Cell;
|
|
|
|
use alacritty::term::SizeInfo;
|
|
|
|
use alacritty::ansi;
|
|
|
|
|
2016-12-04 18:48:30 -05:00
|
|
|
/// The /dev/null of io::Write
|
|
|
|
struct Void;
|
|
|
|
|
|
|
|
impl io::Write for Void {
|
|
|
|
fn write(&mut self, bytes: &[u8]) -> io::Result<usize> {
|
|
|
|
Ok(bytes.len())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> io::Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-19 19:16:20 -05:00
|
|
|
macro_rules! ref_file {
|
|
|
|
($ref_name:ident, $file:expr) => {
|
|
|
|
concat!(
|
|
|
|
env!("CARGO_MANIFEST_DIR"),
|
|
|
|
"/tests/ref/", stringify!($ref_name), "/", $file
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! ref_test {
|
|
|
|
($name:ident) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
let recording = read_u8(ref_file!($name, "alacritty.recording"));
|
|
|
|
let serialized_size = read_string(ref_file!($name, "size.json"));
|
|
|
|
let serialized_grid = read_string(ref_file!($name, "grid.json"));
|
|
|
|
|
2016-11-20 10:45:18 -05:00
|
|
|
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
|
|
|
|
|
|
|
let mut terminal = Term::new(size);
|
|
|
|
let mut parser = ansi::Processor::new();
|
|
|
|
|
|
|
|
for byte in recording {
|
2016-12-04 18:48:30 -05:00
|
|
|
parser.advance(&mut terminal, byte, &mut Void);
|
2016-11-19 19:16:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(grid, *terminal.grid());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
($( $name:ident ),*) => {
|
|
|
|
$(
|
|
|
|
ref_test! { $name }
|
2016-11-19 21:12:04 -05:00
|
|
|
)*
|
|
|
|
};
|
2016-11-19 19:16:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ref tests!
|
2016-11-19 21:12:04 -05:00
|
|
|
ref_test! {
|
|
|
|
ll,
|
|
|
|
vim_simple_edit,
|
|
|
|
tmux_htop,
|
2016-11-28 17:13:11 -05:00
|
|
|
tmux_git_log,
|
2016-12-04 14:14:27 -05:00
|
|
|
vim_large_window_scroll,
|
2016-12-16 03:04:48 -05:00
|
|
|
indexed_256_colors,
|
|
|
|
fish_cc
|
2016-11-19 21:12:04 -05:00
|
|
|
}
|
2016-11-19 19:16:20 -05:00
|
|
|
}
|