aboutsummaryrefslogtreecommitdiff
path: root/tests/ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ref.rs')
-rw-r--r--tests/ref.rs49
1 files changed, 34 insertions, 15 deletions
diff --git a/tests/ref.rs b/tests/ref.rs
index b8587955..74cac6fa 100644
--- a/tests/ref.rs
+++ b/tests/ref.rs
@@ -1,5 +1,7 @@
-extern crate alacritty;
+#[macro_use]
+extern crate serde_derive;
extern crate serde_json as json;
+extern crate alacritty;
use std::fs::File;
use std::io::{self, Read};
@@ -8,10 +10,11 @@ use std::path::Path;
use alacritty::Grid;
use alacritty::Term;
use alacritty::ansi;
-use alacritty::index::{Line, Column};
+use alacritty::index::Column;
use alacritty::term::Cell;
use alacritty::term::SizeInfo;
use alacritty::util::fmt::{Red, Green};
+use alacritty::config::Config;
macro_rules! ref_tests {
($($name:ident)*) => {
@@ -46,6 +49,8 @@ ref_tests! {
vttest_scroll
vttest_tab_clear_set
zsh_tab_completion
+ history
+ grid_reset
}
fn read_u8<P>(path: P) -> Vec<u8>
@@ -58,36 +63,50 @@ fn read_u8<P>(path: P) -> Vec<u8>
res
}
-fn read_string<P>(path: P) -> String
+fn read_string<P>(path: P) -> Result<String, ::std::io::Error>
where P: AsRef<Path>
{
let mut res = String::new();
- File::open(path.as_ref()).unwrap()
- .read_to_string(&mut res).unwrap();
+ File::open(path.as_ref()).and_then(|mut f| f.read_to_string(&mut res))?;
- res
+ Ok(res)
+}
+
+#[derive(Deserialize, Default)]
+struct RefConfig {
+ history_size: u32,
}
fn ref_test(dir: &Path) {
let recording = read_u8(dir.join("alacritty.recording"));
- let serialized_size = read_string(dir.join("size.json"));
- let serialized_grid = read_string(dir.join("grid.json"));
+ 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();
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
+ let ref_config: RefConfig = json::from_str(&serialized_cfg).unwrap_or_default();
- let mut terminal = Term::new(&Default::default(), size);
+ let mut config: Config = Default::default();
+ config.set_history(ref_config.history_size);
+
+ let mut terminal = Term::new(&config, size);
let mut parser = ansi::Processor::new();
for byte in recording {
parser.advance(&mut terminal, byte, &mut io::sink());
}
- if grid != *terminal.grid() {
- for (i, row) in terminal.grid().iter_rows().enumerate() {
- for (j, cell) in row.iter().enumerate() {
- let original_cell = &grid[Line(i)][Column(j)];
- if *original_cell != *cell {
+ // Truncate invisible lines from the grid
+ let mut term_grid = terminal.grid().clone();
+ term_grid.truncate();
+
+ if grid != term_grid {
+ for i in 0..grid.len() {
+ for j in 0..grid.num_cols().0 {
+ let cell = terminal.grid()[i][Column(j)];
+ let original_cell = grid[i][Column(j)];
+ if original_cell != cell {
println!("[{i}][{j}] {original:?} => {now:?}",
i=i, j=j, original=Green(original_cell), now=Red(cell));
}
@@ -97,5 +116,5 @@ fn ref_test(dir: &Path) {
panic!("Ref test failed; grid doesn't match");
}
- assert_eq!(grid, *terminal.grid());
+ assert_eq!(grid, term_grid);
}