//! Mono-synthesis existence pin for milestone 24.2's Show class.
//!
//! Asserts that the four primitive Show instances (Int/Bool/Str/Float)
//! cause the mono pass to synthesise `show__Int`, `show__Bool`,
//! `show__Str`, `show__Float` as `Def::Fn` entries in the prelude
//! post-mono module.

use ailang_core::ast::Def;
use ailang_surface::load_workspace;
use ailang_check::{check_workspace, monomorphise_workspace};
use std::path::PathBuf;

fn fixture_path() -> PathBuf {
    let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    d.pop();
    d.pop();
    d.join("examples").join("show_mono_pin_smoke.ail")
}

#[test]
fn primitive_show_mono_symbols_synthesise() {
    let ws = load_workspace(&fixture_path()).expect("workspace loads");
    let diags = check_workspace(&ws);
    assert!(diags.is_empty(), "typecheck diagnostics: {diags:#?}");
    let post_mono = monomorphise_workspace(&ws).expect("mono green");

    let prelude_mod = post_mono
        .modules
        .get("prelude")
        .expect("prelude module present");

    for sym in &["show__Int", "show__Bool", "show__Str", "show__Float"] {
        let found = prelude_mod
            .defs
            .iter()
            .any(|d| matches!(d, Def::Fn(f) if f.name == *sym));
        assert!(
            found,
            "mono symbol {sym} not found in prelude module post-mono"
        );
    }
}
