//! Tests for [`super`] (the `transform` command dispatcher).
//!
//! Moved out of `transform.rs` so the production module stays focused on
//! command dispatch and transformation logic. Everything else is unchanged:
//! the test module still has free access to `super::*` private helpers so no
//! visibility boundaries are crossed.

use super::*;
use crate::command::command::TableNavDirection;
use crate::engine::engine::EditorEngine;
use crate::model::block::{Block, BlockId};
use crate::model::inline::TextSpan;
use crate::model::selection::{CellCoord, CellSelection, Position};
use crate::op::apply::apply_op;

fn doc_with_text(id: &str, text: &str) -> Document {
    let mut doc = Document::new();
    let mut block = Block::new_paragraph(BlockId::new(id));
    if !text.is_empty() {
        block.content = vec![TextSpan::plain(text)];
    }
    doc.insert_block(block, 0);
    doc
}

fn apply_all(doc: &mut Document, sel: &mut Option<Selection>, ops: &[Operation]) {
    for op in ops {
        apply_op(doc, sel, op).unwrap();
    }
}

fn doc_with_table(rows: usize, cols: usize) -> (Document, BlockId) {
    let mut doc = Document::new();
    doc.insert_block(Block::new_paragraph(BlockId::new("p1")), 0);

    let sel = Selection::collapsed("p1", 0);
    let mut id_gen = SequentialIdGenerator::new("t");
    let ops = transform(
        &doc,
        &sel,
        &Command::InsertTable { rows, cols },
        &mut id_gen,
        None,
    )
    .unwrap();
    let mut sel = Some(sel);
    apply_all(&mut doc, &mut sel, &ops);

    let table_id = doc.root_block_ids()[1].clone();
    (doc, table_id)
}

fn table_grid(doc: &Document, table_id: &BlockId) -> Vec<Vec<BlockId>> {
    doc.table_cell_grid(table_id)
}

// Tests are split across three files so no single file exceeds 1000
// lines. Each submodule picks up the shared helpers via `use super::*`.
mod tests_1;
mod tests_2;
mod tests_3;
