//! RFC-0027 in-tree snapshot tests — gdscript backend.
//!
//! Mirrors python_snapshots.rs against the gdscript target.
//! Re-bless workflow + corpus discipline documented in
//! CONTRIBUTING.md § "Snapshot tests (RFC-0027)".

mod common;

use common::{compile_fixture, compile_source};

#[test]
fn linear_fsm() {
    insta::assert_snapshot!(compile_fixture("01_linear_fsm", "gdscript"));
}

/// Regression for the `push$ -> $State` codegen bug (Issue #42): the
/// with-transition form must use the compartment model (`__prepareEnter` +
/// `__transition`), not the removed `_transition()`. The `05_pushpop` fixture
/// only covers bare `push$` + a separate transition.
#[test]
fn push_transition() {
    let src = r#"
@@system PushTransition {
    interface:
        go()
        back()
    machine:
        $A { go() { push$ -> $B } }
        $B { back() { -> pop$ } }
}
"#;
    let out = compile_source(src, "gdscript");
    assert!(
        out.contains("self._state_stack.append(self.__compartment)"),
        "push$ -> $State must push the current compartment:\n{out}"
    );
    assert!(
        out.contains("self.__transition(__compartment)"),
        "push$ -> $State must transition via the compartment model:\n{out}"
    );
    assert!(
        !out.contains("self._transition("),
        "push$ -> $State must not call the non-existent _transition():\n{out}"
    );
}

#[test]
fn hsm() {
    insta::assert_snapshot!(compile_fixture("02_hsm", "gdscript"));
}

#[test]
fn persist() {
    insta::assert_snapshot!(compile_fixture("03_persist", "gdscript"));
}

#[test]
fn state_args() {
    insta::assert_snapshot!(compile_fixture("04_state_args", "gdscript"));
}

#[test]
fn pushpop() {
    insta::assert_snapshot!(compile_fixture("05_pushpop", "gdscript"));
}

#[test]
fn selfcall() {
    insta::assert_snapshot!(compile_fixture("06_selfcall", "gdscript"));
}

#[test]
fn forward() {
    insta::assert_snapshot!(compile_fixture("07_forward", "gdscript"));
}

#[test]
fn lifecycle() {
    insta::assert_snapshot!(compile_fixture("08_lifecycle", "gdscript"));
}

#[test]
fn return_explicit() {
    insta::assert_snapshot!(compile_fixture("09_return_explicit", "gdscript"));
}

#[test]
fn actions() {
    insta::assert_snapshot!(compile_fixture("10_actions", "gdscript"));
}

#[test]
fn consts() {
    insta::assert_snapshot!(compile_fixture("11_consts", "gdscript"));
}

#[test]
fn no_persist() {
    insta::assert_snapshot!(compile_fixture("12_no_persist", "gdscript"));
}

#[test]
fn lifecycle_args() {
    insta::assert_snapshot!(compile_fixture("13_lifecycle_args", "gdscript"));
}
