mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Add better printing for ref test failure
The previous format was extremely difficult for a human to parse.
This commit is contained in:
parent
a66d19f633
commit
79576b6c0b
3 changed files with 46 additions and 1 deletions
14
src/grid.rs
14
src/grid.rs
|
@ -146,6 +146,10 @@ impl<T> Grid<T> {
|
||||||
self.cols
|
self.cols
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn iter_rows(&self) -> slice::Iter<Row<T>> {
|
||||||
|
self.raw.iter()
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scroll_down(&mut self, region: Range<index::Line>, positions: index::Line) {
|
pub fn scroll_down(&mut self, region: Range<index::Line>, positions: index::Line) {
|
||||||
for line in IndexRange(region).rev() {
|
for line in IndexRange(region).rev() {
|
||||||
|
@ -334,6 +338,16 @@ impl<T> Row<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, T> IntoIterator for &'a Grid<T> {
|
||||||
|
type Item = &'a Row<T>;
|
||||||
|
type IntoIter = slice::Iter<'a, Row<T>>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn into_iter(self) -> slice::Iter<'a, Row<T>> {
|
||||||
|
self.raw.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, T> IntoIterator for &'a Row<T> {
|
impl<'a, T> IntoIterator for &'a Row<T> {
|
||||||
type Item = &'a T;
|
type Item = &'a T;
|
||||||
type IntoIter = slice::Iter<'a, T>;
|
type IntoIter = slice::Iter<'a, T>;
|
||||||
|
|
15
src/util.rs
15
src/util.rs
|
@ -77,6 +77,21 @@ pub mod fmt {
|
||||||
/// Write a `Display` or `Debug` escaped with Yellow
|
/// Write a `Display` or `Debug` escaped with Yellow
|
||||||
pub struct Yellow => "33";
|
pub struct Yellow => "33";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write a `Display` or `Debug` escaped with Red
|
||||||
|
pub struct Green<T>(pub T);
|
||||||
|
|
||||||
|
impl<T: fmt::Display> fmt::Display for Green<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "\x1b[32m{}\x1b[0m", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: fmt::Debug> fmt::Debug for Green<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "\x1b[32m{:?}\x1b[0m", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
18
tests/ref.rs
18
tests/ref.rs
|
@ -7,9 +7,11 @@ use std::path::Path;
|
||||||
|
|
||||||
use alacritty::Grid;
|
use alacritty::Grid;
|
||||||
use alacritty::Term;
|
use alacritty::Term;
|
||||||
|
use alacritty::ansi;
|
||||||
|
use alacritty::index::{Line, Column};
|
||||||
use alacritty::term::Cell;
|
use alacritty::term::Cell;
|
||||||
use alacritty::term::SizeInfo;
|
use alacritty::term::SizeInfo;
|
||||||
use alacritty::ansi;
|
use alacritty::util::fmt::{Red, Green};
|
||||||
|
|
||||||
macro_rules! ref_tests {
|
macro_rules! ref_tests {
|
||||||
($($name:ident)*) => {
|
($($name:ident)*) => {
|
||||||
|
@ -71,5 +73,19 @@ fn ref_test(dir: &Path) {
|
||||||
parser.advance(&mut terminal, byte, &mut io::sink());
|
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 {
|
||||||
|
println!("[{i}][{j}] {original:?} => {now:?}",
|
||||||
|
i=i, j=j, original=Green(original_cell), now=Red(cell));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
panic!("Ref test failed; grid doesn't match");
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(grid, *terminal.grid());
|
assert_eq!(grid, *terminal.grid());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue