local describe = require("lua_test.test").describe
local test = require("lua_test.test").test
local expect = require("lua_test.test").expect
local ACT = require("pasta.act")
local function create_mock_ctx()
return {
actors = {},
save = {},
yield = function() end,
end_action = function() end,
}
end
describe("ACT_IMPL.call - Level 4 (act method fallback)", function()
test("actメソッドがcall経由で呼び出せる", function()
local ctx = create_mock_ctx()
local act = ACT.new(ctx)
local called = false
ACT.IMPL._test_method_fallback = function(a)
called = true
return "method_result"
end
local result = act:call("global", "_test_method_fallback", {})
expect(called):toBe(true)
expect(result):toBe("method_result")
ACT.IMPL._test_method_fallback = nil
end)
test("引数がactメソッドに正しく渡される", function()
local ctx = create_mock_ctx()
local act = ACT.new(ctx)
local received = {}
ACT.IMPL._test_method_args = function(a, arg1, arg2)
received = { arg1, arg2 }
return "args_ok"
end
local result = act:call("global", "_test_method_args", {}, "hello", 42)
expect(result):toBe("args_ok")
expect(received[1]):toBe("hello")
expect(received[2]):toBe(42)
ACT.IMPL._test_method_args = nil
end)
test("non-function値(テーブル等)はフォールバック対象外", function()
local ctx = create_mock_ctx()
local act = ACT.new(ctx)
local result = act:call("global", "var", {})
expect(result):toBe(nil)
end)
end)
describe("ACT_IMPL.call - current_scene優先 over actメソッド", function()
test("current_sceneとactメソッド両方に同名が存在する場合、current_sceneが優先", function()
local ctx = create_mock_ctx()
local act = ACT.new(ctx)
act.current_scene = {
_test_priority = function(a) return "from_scene" end
}
ACT.IMPL._test_priority = function(a) return "from_method" end
local result = act:call("global", "_test_priority", {})
expect(result):toBe("from_scene")
ACT.IMPL._test_priority = nil
end)
test("current_sceneにない場合はactメソッドにフォールバック", function()
local ctx = create_mock_ctx()
local act = ACT.new(ctx)
act.current_scene = {}
ACT.IMPL._test_fallback_only = function(a) return "method_fallback" end
local result = act:call("global", "_test_fallback_only", {})
expect(result):toBe("method_fallback")
ACT.IMPL._test_fallback_only = nil
end)
end)
describe("ACT_IMPL.call - SHIORI_ACT method fallback", function()
test("SHIORI_ACT_IMPLのメソッドがcall経由で呼び出せる", function()
local SHIORI_ACT = require("pasta.shiori.act")
local ACTOR = require("pasta.actor")
local sakura = ACTOR.get_or_create("さくら")
sakura.spot = "sakura"
local actors = { sakura = sakura }
local req = {
reference = { [0] = "click_x", [1] = "click_y" },
id = "OnMouseClick",
base_id = "OnMouseClick",
}
local act = SHIORI_ACT.new(actors, req)
act:call("global", "transfer_req_to_var", {})
expect(act.var["r0"]):toBe("click_x")
expect(act.var["r1"]):toBe("click_y")
expect(act.var.r0):toBe("click_x")
expect(act.var.r1):toBe("click_y")
expect(act.var.req_id):toBe("OnMouseClick")
end)
end)
print(" ✅ act_method_fallback tests defined")