diff options
author | Christian Duerr <contact@christianduerr.com> | 2018-04-14 17:21:48 +0200 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2018-05-14 09:50:12 -0700 |
commit | 400a2c1701e36ba7a5f9b2ffff79df392ebebaf9 (patch) | |
tree | 015effe2e58ab281f1307d017ab9a5c806e75286 /src/grid | |
parent | cf23f56999bee9884de81cd7e046e9a53ebb1632 (diff) | |
download | alacritty-400a2c1701e36ba7a5f9b2ffff79df392ebebaf9.tar.gz alacritty-400a2c1701e36ba7a5f9b2ffff79df392ebebaf9.zip |
Enable history comparison in ref-tests
Previously ref-tests just ignored the scrollback history to keep
the old tests working, this would lead to new tests which rely on
scrollback history to succeeed even though they should not.
This has been fixed and it is now possible to create ref-tests with and
without scrollback history. When available the scrollback history is
compared, but the old tests still work without having to adjust them.
This fixes #1244.
Diffstat (limited to 'src/grid')
-rw-r--r-- | src/grid/mod.rs | 21 | ||||
-rw-r--r-- | src/grid/storage.rs | 10 |
2 files changed, 20 insertions, 11 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs index ac54f580..b6cff604 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -52,9 +52,23 @@ impl<T> Deref for Indexed<T> { impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> { fn eq(&self, other: &Self) -> bool { + // Compare raw grid content + // TODO: This is pretty inefficient but only used in tests + let mut raw_match = true; + for i in 0..(self.lines.0 + self.history_size) { + for j in 0..self.cols.0 { + if self[i][Column(j)] != other[i][Column(j)] { + raw_match = false; + break; + } + } + } + + // Compare struct fields and check result of grid comparison self.cols.eq(&other.cols) && self.lines.eq(&other.lines) && - self.raw.eq(&other.raw) + self.history_size.eq(&other.history_size) && + raw_match } } @@ -88,6 +102,10 @@ pub struct Grid<T> { /// Selected region #[serde(skip)] pub selection: Option<Selection>, + + /// Maximum number of lines in the scrollback history + #[serde(default)] + history_size: usize, } pub struct GridIterator<'a, T: 'a> { @@ -132,6 +150,7 @@ impl<T: Copy + Clone> Grid<T> { display_offset: 0, scroll_limit: 0, selection: None, + history_size: scrollback, } } diff --git a/src/grid/storage.rs b/src/grid/storage.rs index fb66b0c3..50ce6aa5 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -22,16 +22,6 @@ pub struct Storage<T> { visible_lines: Line, } -impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> { - fn eq(&self, other: &Self) -> bool { - let mut equal = true; - for i in IndexRange(Line(0) .. self.visible_lines) { - equal = equal && (self[i] == other[i]) - } - equal - } -} - impl<T> Storage<T> { #[inline] pub fn with_capacity(cap: usize, lines: Line) -> Storage<T> { |