mirror of
https://github.com/alacritty/alacritty.git
synced 2024-10-27 05:32:54 -04:00
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.
This commit is contained in:
parent
688cabefc0
commit
b0f655ac85
24 changed files with 77 additions and 101 deletions
21
scripts/migrate_ref_tests.rb
Executable file
21
scripts/migrate_ref_tests.rb
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'json'
|
||||
|
||||
Dir.glob('./tests/ref/**/grid.json').each do |path|
|
||||
# Read contents
|
||||
s = File.open(path) { |f| f.read }
|
||||
|
||||
# Parse
|
||||
grid = JSON.parse(s)
|
||||
|
||||
# Check if it's already migrated / make this migration idempotent
|
||||
next if grid['raw'][0][0].is_a? Array
|
||||
|
||||
# Transform
|
||||
grid['raw'].reverse!
|
||||
grid['raw'] = [grid['raw'], 0, grid['lines'] - 1]
|
||||
|
||||
# Write updated grid
|
||||
File.open(path, 'w') { |f| f << JSON.generate(grid) }
|
||||
end
|
|
@ -89,9 +89,11 @@ pub struct Grid<T> {
|
|||
/// If the displayed region isn't at the bottom of the screen, it stays
|
||||
/// stationary while more text is emitted. The scrolling implementation
|
||||
/// updates this offset accordingly.
|
||||
#[serde(default)]
|
||||
display_offset: usize,
|
||||
|
||||
/// An limit on how far back it's possible to scroll
|
||||
#[serde(default)]
|
||||
scroll_limit: usize,
|
||||
|
||||
/// Selected region
|
||||
|
|
|
@ -13,15 +13,25 @@
|
|||
/// done so manually.
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use index::Line;
|
||||
use index::{IndexRange, Line};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Storage<T> {
|
||||
inner: Vec<T>,
|
||||
zero: usize,
|
||||
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> {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -2004,7 +2004,7 @@ mod tests {
|
|||
padding_y: 0.0,
|
||||
};
|
||||
let mut term = Term::new(&Default::default(), size);
|
||||
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(5), &Cell::default());
|
||||
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(5), 0, Cell::default());
|
||||
for i in 0..5 {
|
||||
for j in 0..2 {
|
||||
grid[Line(j)][Column(i)].c = 'a';
|
||||
|
@ -2021,18 +2021,18 @@ mod tests {
|
|||
mem::swap(&mut term.semantic_escape_chars, &mut escape_chars);
|
||||
|
||||
{
|
||||
let selection = Selection::semantic(Point { line: Line(0), col: Column(1) }, &term);
|
||||
assert_eq!(term.string_from_selection(&selection.to_span(&term).unwrap()), "aa");
|
||||
*term.selection_mut() = Some(Selection::semantic(Point { line: 2, col: Column(1) }, &term));
|
||||
assert_eq!(term.selection_to_string(), Some(String::from("aa")));
|
||||
}
|
||||
|
||||
{
|
||||
let selection = Selection::semantic(Point { line: Line(0), col: Column(4) }, &term);
|
||||
assert_eq!(term.string_from_selection(&selection.to_span(&term).unwrap()), "aaa");
|
||||
*term.selection_mut() = Some(Selection::semantic(Point { line: 2, col: Column(4) }, &term));
|
||||
assert_eq!(term.selection_to_string(), Some(String::from("aaa")));
|
||||
}
|
||||
|
||||
{
|
||||
let selection = Selection::semantic(Point { line: Line(1), col: Column(1) }, &term);
|
||||
assert_eq!(term.string_from_selection(&selection.to_span(&term).unwrap()), "aaa");
|
||||
*term.selection_mut() = Some(Selection::semantic(Point { line: 1, col: Column(1) }, &term));
|
||||
assert_eq!(term.selection_to_string(), Some(String::from("aaa")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2047,7 +2047,7 @@ mod tests {
|
|||
padding_y: 0.0,
|
||||
};
|
||||
let mut term = Term::new(&Default::default(), size);
|
||||
let mut grid: Grid<Cell> = Grid::new(Line(1), Column(5), &Cell::default());
|
||||
let mut grid: Grid<Cell> = Grid::new(Line(1), Column(5), 0, Cell::default());
|
||||
for i in 0..5 {
|
||||
grid[Line(0)][Column(i)].c = 'a';
|
||||
}
|
||||
|
@ -2057,10 +2057,8 @@ mod tests {
|
|||
|
||||
mem::swap(&mut term.grid, &mut grid);
|
||||
|
||||
let selection = Selection::lines(Point { line: Line(0), col: Column(3) });
|
||||
if let Some(span) = selection.to_span(&term) {
|
||||
assert_eq!(term.string_from_selection(&span), "\"aa\"a\n");
|
||||
}
|
||||
*term.selection_mut() = Some(Selection::lines(Point { line: 0, col: Column(3) }));
|
||||
assert_eq!(term.selection_to_string(), Some(String::from("\"aa\"a\n")));
|
||||
}
|
||||
|
||||
/// Check that the grid can be serialized back and forth losslessly
|
||||
|
@ -2071,7 +2069,7 @@ mod tests {
|
|||
fn grid_serde() {
|
||||
let template = Cell::default();
|
||||
|
||||
let grid = Grid::new(Line(24), Column(80), &template);
|
||||
let grid: Grid<Cell> = Grid::new(Line(24), Column(80), 0, template);
|
||||
let serialized = serde_json::to_string(&grid).expect("ser");
|
||||
let deserialized = serde_json::from_str::<Grid<Cell>>(&serialized)
|
||||
.expect("de");
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue