mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-03 04:34:21 -05:00
30bee80a69
The terminal now has a `renderable_cells()` function that returns a `RenderableCellIter` iterator. This allows reuse of the cell selection code by multiple renderers, makes it testable, and makes it independently optimizable. The render API now takes an `Iterator<Item=IndexedCell>` to support both the new renderable cells iterator and the `render_string()` method which generates its own iterator. The `vim_large_window_scoll` ref test was added here because it provides a nice large and busy grid to benchmark the cell selection with.
84 lines
2 KiB
Rust
84 lines
2 KiB
Rust
extern crate alacritty;
|
|
extern crate serde_json;
|
|
|
|
/// ref tests
|
|
mod reference {
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
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;
|
|
|
|
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"));
|
|
|
|
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
|
|
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
|
|
|
|
let mut terminal = Term::new(size);
|
|
let mut parser = ansi::Processor::new();
|
|
|
|
for byte in recording {
|
|
parser.advance(&mut terminal, byte);
|
|
}
|
|
|
|
assert_eq!(grid, *terminal.grid());
|
|
}
|
|
};
|
|
|
|
($( $name:ident ),*) => {
|
|
$(
|
|
ref_test! { $name }
|
|
)*
|
|
};
|
|
}
|
|
|
|
// Ref tests!
|
|
ref_test! {
|
|
ll,
|
|
vim_simple_edit,
|
|
tmux_htop,
|
|
tmux_git_log,
|
|
vim_large_window_scroll
|
|
}
|
|
}
|