//! Matrix coverage for `drop column [from] [table] <T> : <col>`
//! (ADR-0013).
//!
//! Handoff-12 §2.2 flagged that the DDL `TABLE_NAME_EXISTING`
//! slot didn't set `writes_table`, so at `drop column from T: `
//! the column-name slot couldn't narrow to T's columns —
//! candidates leaked from every table. This file asserts the
//! per-table narrowing; the fix lands alongside it.

use crate::typing_surface::*;
use rdbms_playground::input_render::InputState;

#[test]
fn after_drop_column_offers_table_names() {
    let schema = schema_multi_table();
    let a = assess_at_end("drop column from ", &schema);
    assert!(matches!(a.state, InputState::IncompleteAtEof));
    assert_candidate_present(&a, &["Customers", "Orders"]);
    crate::snap!("after_from", a);
}

#[test]
fn after_table_name_expects_colon() {
    let schema = schema_serial_pk();
    let a = assess_at_end("drop column from Customers", &schema);
    assert!(matches!(a.state, InputState::IncompleteAtEof));
    crate::snap!("after_table_name", a);
}

// =========================================================
// Handoff §2.2 — column slot narrows to the active table.
// =========================================================

#[test]
fn after_colon_offers_only_active_table_columns_no_leakage() {
    let schema = schema_multi_table();
    let a = assess_at_end("drop column from Customers: ", &schema);
    assert!(matches!(a.state, InputState::IncompleteAtEof));
    // Customers's columns must be offered.
    assert_candidate_present(&a, &["id", "Name"]);
    // Orders's columns must NOT leak.
    assert_no_candidate_named(&a, &["OrderId", "CustId", "Total"]);
    crate::snap!("after_colon_multi_table", a);
}

#[test]
fn after_colon_serial_pk_offers_all_columns() {
    let schema = schema_serial_pk();
    let a = assess_at_end("drop column from Customers: ", &schema);
    assert_candidate_present(&a, &["id", "Name", "Email"]);
    crate::snap!("after_colon_serial_pk", a);
}

#[test]
fn complete_drop_column_parses() {
    let schema = schema_serial_pk();
    let a = assess_at_end("drop column from Customers: Email", &schema);
    assert!(matches!(a.state, InputState::Valid));
    assert_eq!(a.parse_result.as_deref(), Ok("DropColumn"));
    crate::snap!("complete_drop_column", a);
}

#[test]
fn drop_column_with_table_keyword_parses() {
    let schema = schema_serial_pk();
    let a = assess_at_end("drop column from table Customers: Email", &schema);
    assert!(matches!(a.state, InputState::Valid));
    crate::snap!("with_table_keyword", a);
}
