//! Repurposed pin tests for the post-`MethodNameCollision`-retirement
//! workspace-load path. The two on-disk fixtures that fired
//! `WorkspaceLoadError::MethodNameCollision` before the type-driven
//! dispatch refactor now load cleanly;
//! the assertion migrates from "expect collision diagnostic" to "load
//! successful + `Env.method_to_candidate_classes` carries the
//! expected multi-entry set" (class-class case) or "load successful +
//! class-fn coexistence is legal" (class-fn case).
//!
//! The relocation from `crates/ailang-core/src/workspace.rs` to this
//! file is required because the post-retirement assertions read
//! `Env.method_to_candidate_classes`, which is built by `ailang-check`
//! (`build_check_env`) and not visible from `ailang-core`.

use ailang_check::build_check_env;
use ailang_surface::load_workspace;
use ailang_test_support::examples_dir;

/// Class-class repurpose: the fixture
/// `examples/test_22b2_method_name_collision_class_class.ail.json`
/// declares two classes `A` and `B` in the same module, each declaring
/// the method `foo`. Pre-canonical-class-form this fired
/// `WorkspaceLoadError::MethodNameCollision { kind: "class-class" }`.
/// Post-canonical-class-form the workspace loads cleanly and
/// `env.method_to_candidate_classes` carries both qualified classes as
/// candidates for the method name `foo`.
#[test]
fn mq3_class_class_collision_loads_clean_and_populates_candidates() {
    let entry = examples_dir()
        .join("test_22b2_method_name_collision_class_class.ail");
    let ws = load_workspace(&entry)
        .expect("post-canonical-class-form: workspace loads without collision diagnostic");

    let env = build_check_env(&ws);
    let candidates = env
        .method_to_candidate_classes
        .get("foo")
        .expect("`foo` must be in method_to_candidate_classes");
    assert!(
        candidates.contains("test_22b2_method_name_collision_class_class.A"),
        "candidates must include class A: {candidates:?}",
    );
    assert!(
        candidates.contains("test_22b2_method_name_collision_class_class.B"),
        "candidates must include class B: {candidates:?}",
    );
    assert_eq!(
        candidates.len(),
        2,
        "exactly two candidate classes for `foo`: {candidates:?}",
    );
}

/// Class-fn repurpose: the fixture
/// `examples/test_22b2_method_name_collision_class_fn.ail.json`
/// declares `class Greet { greet }` and `fn greet`. Pre-canonical-class-form this
/// fired `WorkspaceLoadError::MethodNameCollision { kind: "class-fn" }`.
/// Post-canonical-class-form the workspace loads cleanly — the method-vs-fn
/// coexistence is now legal at load time; the call-site emits a
/// `class-method-shadowed-by-fn` warning (covered by the multi-class E2E,
/// not this load-level pin).
#[test]
fn mq3_class_fn_collision_loads_clean() {
    let entry = examples_dir()
        .join("test_22b2_method_name_collision_class_fn.ail");
    load_workspace(&entry)
        .expect("post-canonical-class-form: workspace loads — class-vs-fn name overlap is no longer a load error");
}
