#include #include #include using Void::Coro::Task; using Void::Fsm::ChildSuccess; using Void::Fsm::State; using Void::Fsm::StateKey; namespace Fsm = Void::Fsm; // A state's entry is inferred by signature (a 0-arg member returning StateKey / // Task). When several members match, one annotated // `[[= Void::Fsm::entry]]` is preferred; otherwise the first-declared wins. A // startup-data overload run(Cfg) is selected when the machine is launched with // data, and the nullary entry otherwise. namespace { // Two nullary entry candidates; the annotated one is chosen even though it // is not declared first. class Annotated : public Fsm::Machine { public: using Success = int; struct States { struct Pick : State { Task first() // declared first { co_return succeed(1); } [[= Fsm::entry]] Task chosen() { co_return succeed(2); } }; }; }; // Two nullary entry candidates, none annotated → first-declared wins. class FirstWins : public Fsm::Machine { public: using Success = int; struct States { struct Pick : State { Task first() { co_return succeed(1); } Task second() { co_return succeed(2); } }; }; }; } // namespace // @tag integration Void::Testing::Test annotated_entry_beats_first_declared() { Annotated fsm; const auto outcome = fsm.run_blocking(); Void::Testing::expect(outcome.has_value()); Void::Testing::expect_eq(*outcome, 2); // the [[= Fsm::entry]] member ran } // @tag integration Void::Testing::Test first_declared_entry_wins_without_annotation() { FirstWins fsm; const auto outcome = fsm.run_blocking(); Void::Testing::expect(outcome.has_value()); Void::Testing::expect_eq(*outcome, 1); // first-declared ran } // ── startup-data overload selection ───────────────────────────────────────── namespace { // Begin has both a nullary entry and a startup-data overload. The right one // is picked by whether the machine was launched with data. class Seeded : public Fsm::Machine { public: using Success = int; struct States { struct Begin : State { Task run() // no startup data { co_return succeed(0); } Task run(int seed) // with startup data { co_return succeed(seed); } }; }; }; class Launcher : public Fsm::Machine { public: using Success = int; struct States { struct Go : State { Task run() { co_return startMachine(7); } }; struct After : State { Task ok(ChildSuccess s) { co_return succeed(s.as()); } }; }; }; } // namespace // @tag integration Void::Testing::Test startup_entry_used_when_launched_with_data() { Launcher fsm; // Seeded launched via startMachine(7) const auto outcome = fsm.run_blocking(); Void::Testing::expect(outcome.has_value()); Void::Testing::expect_eq(*outcome, 7); // run(int) selected } // @tag integration Void::Testing::Test nullary_entry_used_without_startup_data() { Seeded fsm; // started normally, no startup data const auto outcome = fsm.run_blocking(); Void::Testing::expect(outcome.has_value()); Void::Testing::expect_eq(*outcome, 0); // run() selected }