From 277425956f361677deb1de92b25aeca9cbcd1cd1 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Thu, 12 Oct 2017 20:01:28 -0700 Subject: Move grid Row and tests into submodules This is part of some cleanup for the grid module as a whole. --- src/grid/tests.rs | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 src/grid/tests.rs (limited to 'src/grid/tests.rs') diff --git a/src/grid/tests.rs b/src/grid/tests.rs new file mode 100644 index 00000000..169cefa0 --- /dev/null +++ b/src/grid/tests.rs @@ -0,0 +1,188 @@ +// Copyright 2016 Joe Wilm, The Alacritty Project Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests for the Gird + +use super::{Grid, BidirectionalIterator}; +use index::{Point, Line, Column}; + +#[test] +fn grid_swap_lines_ok() { + let mut grid = Grid::new(Line(10), Column(1), &0); + info!(""); + + // swap test ends + grid[Line(0)][Column(0)] = 1; + grid[Line(9)][Column(0)] = 2; + + assert_eq!(grid[Line(0)][Column(0)], 1); + assert_eq!(grid[Line(9)][Column(0)], 2); + + grid.swap_lines(Line(0), Line(9)); + + assert_eq!(grid[Line(0)][Column(0)], 2); + assert_eq!(grid[Line(9)][Column(0)], 1); + + // swap test mid + grid[Line(4)][Column(0)] = 1; + grid[Line(5)][Column(0)] = 2; + + info!("grid: {:?}", grid); + + assert_eq!(grid[Line(4)][Column(0)], 1); + assert_eq!(grid[Line(5)][Column(0)], 2); + + grid.swap_lines(Line(4), Line(5)); + + info!("grid: {:?}", grid); + + assert_eq!(grid[Line(4)][Column(0)], 2); + assert_eq!(grid[Line(5)][Column(0)], 1); +} + +#[test] +#[should_panic] +fn grid_swap_lines_oob1() { + let mut grid = Grid::new(Line(10), Column(1), &0); + grid.swap_lines(Line(0), Line(10)); +} + +#[test] +#[should_panic] +fn grid_swap_lines_oob2() { + let mut grid = Grid::new(Line(10), Column(1), &0); + grid.swap_lines(Line(10), Line(0)); +} + +#[test] +#[should_panic] +fn grid_swap_lines_oob3() { + let mut grid = Grid::new(Line(10), Column(1), &0); + grid.swap_lines(Line(10), Line(10)); +} + +// Scroll up moves lines upwards +#[test] +fn scroll_up() { + info!(""); + + let mut grid = Grid::new(Line(10), Column(1), &0); + for i in 0..10 { + grid[Line(i)][Column(0)] = i; + } + + info!("grid: {:?}", grid); + + grid.scroll_up(Line(0)..Line(10), Line(2)); + + info!("grid: {:?}", grid); + + let mut other = Grid::new(Line(10), Column(1), &9); + + other[Line(0)][Column(0)] = 2; + other[Line(1)][Column(0)] = 3; + other[Line(2)][Column(0)] = 4; + other[Line(3)][Column(0)] = 5; + other[Line(4)][Column(0)] = 6; + other[Line(5)][Column(0)] = 7; + other[Line(6)][Column(0)] = 8; + other[Line(7)][Column(0)] = 9; + other[Line(8)][Column(0)] = 0; + other[Line(9)][Column(0)] = 1; + + for i in 0..10 { + assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); + } +} + +// Scroll down moves lines downwards +#[test] +fn scroll_down() { + info!(""); + + let mut grid = Grid::new(Line(10), Column(1), &0); + for i in 0..10 { + grid[Line(i)][Column(0)] = i; + } + + info!("grid: {:?}", grid); + + grid.scroll_down(Line(0)..Line(10), Line(2)); + + info!("grid: {:?}", grid); + + let mut other = Grid::new(Line(10), Column(1), &9); + + other[Line(0)][Column(0)] = 8; + other[Line(1)][Column(0)] = 9; + other[Line(2)][Column(0)] = 0; + other[Line(3)][Column(0)] = 1; + other[Line(4)][Column(0)] = 2; + other[Line(5)][Column(0)] = 3; + other[Line(6)][Column(0)] = 4; + other[Line(7)][Column(0)] = 5; + other[Line(8)][Column(0)] = 6; + other[Line(9)][Column(0)] = 7; + + for i in 0..10 { + assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); + } +} + +// Test that GridIterator works +#[test] +fn test_iter() { + info!(""); + + let mut grid = Grid::new(Line(5), Column(5), &0); + for i in 0..5 { + for j in 0..5 { + grid[Line(i)][Column(j)] = i*5 + j; + } + } + + info!("grid: {:?}", grid); + + let mut iter = grid.iter_from(Point { + line: Line(0), + col: Column(0), + }); + + assert_eq!(None, iter.prev()); + assert_eq!(Some(&1), iter.next()); + assert_eq!(Column(1), iter.cur.col); + assert_eq!(Line(0), iter.cur.line); + + assert_eq!(Some(&2), iter.next()); + assert_eq!(Some(&3), iter.next()); + assert_eq!(Some(&4), iter.next()); + + // test linewrapping + assert_eq!(Some(&5), iter.next()); + assert_eq!(Column(0), iter.cur.col); + assert_eq!(Line(1), iter.cur.line); + + assert_eq!(Some(&4), iter.prev()); + assert_eq!(Column(4), iter.cur.col); + assert_eq!(Line(0), iter.cur.line); + + + // test that iter ends at end of grid + let mut final_iter = grid.iter_from(Point { + line: Line(4), + col: Column(4), + }); + assert_eq!(None, final_iter.next()); + assert_eq!(Some(&23), final_iter.prev()); +} -- cgit From b0f655ac85ab6d86e9e482cbb9035200c6f08d40 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 9 Mar 2018 13:49:47 -0800 Subject: Make tests compile again Some tests are still not passing, though. A migration script was added to migrate serialized grids from pre-scrollback to the current format. The script is included with this commit for completeness, posterity, and as an example to be used in the future. A few tests in grid/tests.rs were removed due to becoming irrelevant. --- src/grid/tests.rs | 79 +++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 67 deletions(-) (limited to 'src/grid/tests.rs') diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 169cefa0..547fbcf9 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -17,78 +17,23 @@ use super::{Grid, BidirectionalIterator}; use index::{Point, Line, Column}; -#[test] -fn grid_swap_lines_ok() { - let mut grid = Grid::new(Line(10), Column(1), &0); - info!(""); - - // swap test ends - grid[Line(0)][Column(0)] = 1; - grid[Line(9)][Column(0)] = 2; - - assert_eq!(grid[Line(0)][Column(0)], 1); - assert_eq!(grid[Line(9)][Column(0)], 2); - - grid.swap_lines(Line(0), Line(9)); - - assert_eq!(grid[Line(0)][Column(0)], 2); - assert_eq!(grid[Line(9)][Column(0)], 1); - - // swap test mid - grid[Line(4)][Column(0)] = 1; - grid[Line(5)][Column(0)] = 2; - - info!("grid: {:?}", grid); - - assert_eq!(grid[Line(4)][Column(0)], 1); - assert_eq!(grid[Line(5)][Column(0)], 2); - - grid.swap_lines(Line(4), Line(5)); - - info!("grid: {:?}", grid); - - assert_eq!(grid[Line(4)][Column(0)], 2); - assert_eq!(grid[Line(5)][Column(0)], 1); -} - -#[test] -#[should_panic] -fn grid_swap_lines_oob1() { - let mut grid = Grid::new(Line(10), Column(1), &0); - grid.swap_lines(Line(0), Line(10)); -} - -#[test] -#[should_panic] -fn grid_swap_lines_oob2() { - let mut grid = Grid::new(Line(10), Column(1), &0); - grid.swap_lines(Line(10), Line(0)); -} - -#[test] -#[should_panic] -fn grid_swap_lines_oob3() { - let mut grid = Grid::new(Line(10), Column(1), &0); - grid.swap_lines(Line(10), Line(10)); -} - // Scroll up moves lines upwards #[test] fn scroll_up() { info!(""); - let mut grid = Grid::new(Line(10), Column(1), &0); + let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { grid[Line(i)][Column(0)] = i; } info!("grid: {:?}", grid); - grid.scroll_up(Line(0)..Line(10), Line(2)); + grid.scroll_up(&(Line(0)..Line(10)), Line(2)); info!("grid: {:?}", grid); - let mut other = Grid::new(Line(10), Column(1), &9); + let mut other = Grid::new(Line(10), Column(1), 0, 9); other[Line(0)][Column(0)] = 2; other[Line(1)][Column(0)] = 3; @@ -111,18 +56,18 @@ fn scroll_up() { fn scroll_down() { info!(""); - let mut grid = Grid::new(Line(10), Column(1), &0); + let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { grid[Line(i)][Column(0)] = i; } info!("grid: {:?}", grid); - grid.scroll_down(Line(0)..Line(10), Line(2)); + grid.scroll_down(&(Line(0)..Line(10)), Line(2)); info!("grid: {:?}", grid); - let mut other = Grid::new(Line(10), Column(1), &9); + let mut other = Grid::new(Line(10), Column(1), 0, 9); other[Line(0)][Column(0)] = 8; other[Line(1)][Column(0)] = 9; @@ -145,7 +90,7 @@ fn scroll_down() { fn test_iter() { info!(""); - let mut grid = Grid::new(Line(5), Column(5), &0); + let mut grid = Grid::new(Line(5), Column(5), 0, 0); for i in 0..5 { for j in 0..5 { grid[Line(i)][Column(j)] = i*5 + j; @@ -155,14 +100,14 @@ fn test_iter() { info!("grid: {:?}", grid); let mut iter = grid.iter_from(Point { - line: Line(0), + line: 4, col: Column(0), }); assert_eq!(None, iter.prev()); assert_eq!(Some(&1), iter.next()); assert_eq!(Column(1), iter.cur.col); - assert_eq!(Line(0), iter.cur.line); + assert_eq!(4, iter.cur.line); assert_eq!(Some(&2), iter.next()); assert_eq!(Some(&3), iter.next()); @@ -171,16 +116,16 @@ fn test_iter() { // test linewrapping assert_eq!(Some(&5), iter.next()); assert_eq!(Column(0), iter.cur.col); - assert_eq!(Line(1), iter.cur.line); + assert_eq!(3, iter.cur.line); assert_eq!(Some(&4), iter.prev()); assert_eq!(Column(4), iter.cur.col); - assert_eq!(Line(0), iter.cur.line); + assert_eq!(4, iter.cur.line); // test that iter ends at end of grid let mut final_iter = grid.iter_from(Point { - line: Line(4), + line: 0, col: Column(4), }); assert_eq!(None, final_iter.next()); -- cgit From 54314380f07f25b22591775931994196c30240ed Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 9 Mar 2018 14:00:36 -0800 Subject: Fix grid scroll tests --- src/grid/tests.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/grid/tests.rs') diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 547fbcf9..107e7103 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -43,11 +43,13 @@ fn scroll_up() { other[Line(5)][Column(0)] = 7; other[Line(6)][Column(0)] = 8; other[Line(7)][Column(0)] = 9; - other[Line(8)][Column(0)] = 0; - other[Line(9)][Column(0)] = 1; + other[Line(8)][Column(0)] = 0; // should be cleared on scroll; was 0 + other[Line(9)][Column(0)] = 0; // should be cleared on scroll; was 1 for i in 0..10 { - assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); + assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)], + "index={}; actual: {:?}, expected: {:?}", + Line(i), grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); } } @@ -69,8 +71,8 @@ fn scroll_down() { let mut other = Grid::new(Line(10), Column(1), 0, 9); - other[Line(0)][Column(0)] = 8; - other[Line(1)][Column(0)] = 9; + other[Line(0)][Column(0)] = 0; // Should be cleared upon recycle; was 8 + other[Line(1)][Column(0)] = 0; // Should be cleared upon recycle; was 9 other[Line(2)][Column(0)] = 0; other[Line(3)][Column(0)] = 1; other[Line(4)][Column(0)] = 2; @@ -81,7 +83,9 @@ fn scroll_down() { other[Line(9)][Column(0)] = 7; for i in 0..10 { - assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); + assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)], + "index={}; actual: {:?}, expected: {:?}", + Line(i), grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); } } -- cgit From b19045da66899999856c6b2cc6707b60c607660a Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 2 Apr 2018 08:44:54 -0700 Subject: Fix BCE ref tests BCE was broken in attempt to optimize row clearing. The fix is to revert to passing in the current cursor state when clearing. --- src/grid/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/grid/tests.rs') diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 107e7103..3e229fb6 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -29,7 +29,7 @@ fn scroll_up() { info!("grid: {:?}", grid); - grid.scroll_up(&(Line(0)..Line(10)), Line(2)); + grid.scroll_up(&(Line(0)..Line(10)), Line(2), &0); info!("grid: {:?}", grid); @@ -65,7 +65,7 @@ fn scroll_down() { info!("grid: {:?}", grid); - grid.scroll_down(&(Line(0)..Line(10)), Line(2)); + grid.scroll_down(&(Line(0)..Line(10)), Line(2), &0); info!("grid: {:?}", grid); -- cgit From c61a912f6221a320ec4787cd883527b0e7f26a8e Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 19 May 2018 11:18:37 -0700 Subject: Optimize Row::reset Now, only cells that have been used are cleared. This is achieved by using a "occupied" memo on the Row itself. The value, `occ`, is updated wherever the Row is accessed mutably, and it's cleared to zero in Row::reset. The tests for grid scroll_up and scroll_down were updated to include a test on the value `occ` and slightly refactored, but are otherwise equivalent to the previous implementation of those tests. Because of the change to the `Row` struct, the ref tests were updated so Deserialization keeps working as expected. --- src/grid/tests.rs | 92 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 44 deletions(-) (limited to 'src/grid/tests.rs') diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 3e229fb6..435f0c3d 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -20,73 +20,77 @@ use index::{Point, Line, Column}; // Scroll up moves lines upwards #[test] fn scroll_up() { - info!(""); + println!(""); let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { grid[Line(i)][Column(0)] = i; } - info!("grid: {:?}", grid); + println!("grid: {:?}", grid); grid.scroll_up(&(Line(0)..Line(10)), Line(2), &0); - info!("grid: {:?}", grid); - - let mut other = Grid::new(Line(10), Column(1), 0, 9); - - other[Line(0)][Column(0)] = 2; - other[Line(1)][Column(0)] = 3; - other[Line(2)][Column(0)] = 4; - other[Line(3)][Column(0)] = 5; - other[Line(4)][Column(0)] = 6; - other[Line(5)][Column(0)] = 7; - other[Line(6)][Column(0)] = 8; - other[Line(7)][Column(0)] = 9; - other[Line(8)][Column(0)] = 0; // should be cleared on scroll; was 0 - other[Line(9)][Column(0)] = 0; // should be cleared on scroll; was 1 - - for i in 0..10 { - assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)], - "index={}; actual: {:?}, expected: {:?}", - Line(i), grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); - } + println!("grid: {:?}", grid); + + assert_eq!(grid[Line(0)][Column(0)], 2); + assert_eq!(grid[Line(0)].occ, 1); + assert_eq!(grid[Line(1)][Column(0)], 3); + assert_eq!(grid[Line(1)].occ, 1); + assert_eq!(grid[Line(2)][Column(0)], 4); + assert_eq!(grid[Line(2)].occ, 1); + assert_eq!(grid[Line(3)][Column(0)], 5); + assert_eq!(grid[Line(3)].occ, 1); + assert_eq!(grid[Line(4)][Column(0)], 6); + assert_eq!(grid[Line(4)].occ, 1); + assert_eq!(grid[Line(5)][Column(0)], 7); + assert_eq!(grid[Line(5)].occ, 1); + assert_eq!(grid[Line(6)][Column(0)], 8); + assert_eq!(grid[Line(6)].occ, 1); + assert_eq!(grid[Line(7)][Column(0)], 9); + assert_eq!(grid[Line(7)].occ, 1); + assert_eq!(grid[Line(8)][Column(0)], 0); // was 0 + assert_eq!(grid[Line(8)].occ, 0); + assert_eq!(grid[Line(9)][Column(0)], 0); // was 1 + assert_eq!(grid[Line(9)].occ, 0); } // Scroll down moves lines downwards #[test] fn scroll_down() { - info!(""); + println!(""); let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { grid[Line(i)][Column(0)] = i; } - info!("grid: {:?}", grid); + println!("grid: {:?}", grid); grid.scroll_down(&(Line(0)..Line(10)), Line(2), &0); - info!("grid: {:?}", grid); - - let mut other = Grid::new(Line(10), Column(1), 0, 9); - - other[Line(0)][Column(0)] = 0; // Should be cleared upon recycle; was 8 - other[Line(1)][Column(0)] = 0; // Should be cleared upon recycle; was 9 - other[Line(2)][Column(0)] = 0; - other[Line(3)][Column(0)] = 1; - other[Line(4)][Column(0)] = 2; - other[Line(5)][Column(0)] = 3; - other[Line(6)][Column(0)] = 4; - other[Line(7)][Column(0)] = 5; - other[Line(8)][Column(0)] = 6; - other[Line(9)][Column(0)] = 7; - - for i in 0..10 { - assert_eq!(grid[Line(i)][Column(0)], other[Line(i)][Column(0)], - "index={}; actual: {:?}, expected: {:?}", - Line(i), grid[Line(i)][Column(0)], other[Line(i)][Column(0)]); - } + println!("grid: {:?}", grid); + + assert_eq!(grid[Line(0)][Column(0)], 0); // was 8 + assert_eq!(grid[Line(0)].occ, 0); + assert_eq!(grid[Line(1)][Column(0)], 0); // was 9 + assert_eq!(grid[Line(1)].occ, 0); + assert_eq!(grid[Line(2)][Column(0)], 0); + assert_eq!(grid[Line(2)].occ, 1); + assert_eq!(grid[Line(3)][Column(0)], 1); + assert_eq!(grid[Line(3)].occ, 1); + assert_eq!(grid[Line(4)][Column(0)], 2); + assert_eq!(grid[Line(4)].occ, 1); + assert_eq!(grid[Line(5)][Column(0)], 3); + assert_eq!(grid[Line(5)].occ, 1); + assert_eq!(grid[Line(6)][Column(0)], 4); + assert_eq!(grid[Line(6)].occ, 1); + assert_eq!(grid[Line(7)][Column(0)], 5); + assert_eq!(grid[Line(7)].occ, 1); + assert_eq!(grid[Line(8)][Column(0)], 6); + assert_eq!(grid[Line(8)].occ, 1); + assert_eq!(grid[Line(9)][Column(0)], 7); + assert_eq!(grid[Line(9)].occ, 1); } // Test that GridIterator works -- cgit From f50ca1a54c94fe324d22d985c1acae1ff7c16a80 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 21 Jul 2018 17:17:41 +0000 Subject: Scrollback cleanup There were some unneeded codeblocks and TODO/XXX comments in the code that have been removed. All issues marked with TODO/XXX have either been already resolved or tracking issues exist. --- src/grid/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/grid/tests.rs') diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 435f0c3d..e136e3b3 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -20,7 +20,7 @@ use index::{Point, Line, Column}; // Scroll up moves lines upwards #[test] fn scroll_up() { - println!(""); + println!(); let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { @@ -58,7 +58,7 @@ fn scroll_up() { // Scroll down moves lines downwards #[test] fn scroll_down() { - println!(""); + println!(); let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { -- cgit