Add better printing for ref test failure

The previous format was extremely difficult for a human to parse.
This commit is contained in:
Joe Wilm 2017-04-03 20:21:55 -07:00 committed by Joe Wilm
parent a66d19f633
commit 79576b6c0b
3 changed files with 46 additions and 1 deletions

View File

@ -146,6 +146,10 @@ impl<T> Grid<T> {
self.cols
}
pub fn iter_rows(&self) -> slice::Iter<Row<T>> {
self.raw.iter()
}
#[inline]
pub fn scroll_down(&mut self, region: Range<index::Line>, positions: index::Line) {
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> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;

View File

@ -77,6 +77,21 @@ pub mod fmt {
/// Write a `Display` or `Debug` escaped with Yellow
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)]

View File

@ -7,9 +7,11 @@ use std::path::Path;
use alacritty::Grid;
use alacritty::Term;
use alacritty::ansi;
use alacritty::index::{Line, Column};
use alacritty::term::Cell;
use alacritty::term::SizeInfo;
use alacritty::ansi;
use alacritty::util::fmt::{Red, Green};
macro_rules! ref_tests {
($($name:ident)*) => {
@ -71,5 +73,19 @@ fn ref_test(dir: &Path) {
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());
}