tastty-core 0.1.0

Sans-IO core of the tastty terminal session library: VT parser, screen buffer, and byte encoders.
use super::*;

#[test]
fn cells_yields_rows_times_cols_on_blank_screen() {
    let screen = make_screen(3, 4);
    let collected: Vec<_> = screen.cells().collect();
    assert_eq!(
        collected.len(),
        12,
        "cells() on a 3x4 blank screen must yield every cell once (rows*cols)",
    );
    for (pos, cell) in collected {
        assert!(
            !cell.has_contents(),
            "cell at {pos:?} on blank screen must be empty",
        );
    }
}

#[test]
fn cells_positions_are_row_major() {
    let screen = make_screen(2, 3);
    let positions: Vec<Position> = screen.cells().map(|(p, _)| p).collect();
    assert_eq!(
        positions,
        vec![
            Position { row: 0, col: 0 },
            Position { row: 0, col: 1 },
            Position { row: 0, col: 2 },
            Position { row: 1, col: 0 },
            Position { row: 1, col: 1 },
            Position { row: 1, col: 2 },
        ],
    );
}

#[test]
fn cells_skips_wide_continuation() {
    let mut screen = make_screen(1, 4);
    screen.text('\u{6f22}');
    screen.text('X');
    assert!(screen.cell(0, 0).unwrap().is_wide());
    assert!(screen.cell(0, 1).unwrap().is_wide_continuation());
    let positions: Vec<u16> = screen.cells().map(|(p, _)| p.col).collect();
    assert_eq!(positions, vec![0, 2, 3]);
}

#[test]
fn row_cells_skips_wide_continuation() {
    let mut screen = make_screen(1, 4);
    screen.text('\u{6f22}');
    screen.text('X');
    let positions: Vec<u16> = screen.row_cells(0).map(|(p, _)| p.col).collect();
    assert_eq!(positions, vec![0, 2, 3]);
}

#[test]
fn row_cells_out_of_bounds_is_empty() {
    let screen = make_screen(2, 3);
    assert_eq!(screen.row_cells(999).count(), 0);
}