local describe = require("lua_test.test").describe
local test = require("lua_test.test").test
local expect = require("lua_test.test").expect
describe("STORE.actor_spots - 初期化 (Task 5.1)", function()
test("STORE.actor_spotsフィールドが存在する", function()
local STORE = require("pasta.store")
expect(type(STORE.actor_spots)):toBe("table")
end)
test("CONFIG.actor未定義時にactor_spotsが空テーブル", function()
local STORE = require("pasta.store")
expect(type(STORE.actor_spots)):toBe("table")
end)
end)
describe("STORE.actor_spots - reset() (Task 5.2)", function()
test("STORE.reset()がactor_spotsを空テーブルにクリアする", function()
local STORE = require("pasta.store")
STORE.actor_spots["テスト"] = 5
STORE.actor_spots["キャラ"] = 3
STORE.reset()
expect(next(STORE.actor_spots)):toBe(nil)
expect(type(STORE.actor_spots)):toBe("table")
end)
test("reset()後もactor_spotsへの書き込みが可能", function()
local STORE = require("pasta.store")
STORE.reset()
STORE.actor_spots["新キャラ"] = 2
expect(STORE.actor_spots["新キャラ"]):toBe(2)
STORE.reset()
end)
end)
describe("SHIORI_ACT.build() - STORE.actor_spots連携 (Task 6.1)", function()
test("build()後にSTORE.actor_spotsが更新される", function()
local SHIORI_ACT = require("pasta.shiori.act")
local STORE = require("pasta.store")
local ACTOR = require("pasta.actor")
STORE.reset()
local sakura = ACTOR.get_or_create("さくら")
sakura.spot = "sakura"
local kero = ACTOR.get_or_create("うにゅう")
kero.spot = "kero"
local actors = {
sakura = sakura,
kero = kero,
}
local act = SHIORI_ACT.new(actors)
act:set_spot("sakura", 0)
act:set_spot("kero", 1)
act.sakura:talk("Hello")
act.kero:talk("Hi")
local result = act:build()
expect(result):toBeTruthy()
expect(result:find("\\p%[0%]")):toBeTruthy()
expect(result:find("\\p%[1%]")):toBeTruthy()
expect(STORE.actor_spots["さくら"]):toBe(0)
expect(STORE.actor_spots["うにゅう"]):toBe(1)
STORE.reset()
end)
test("トークン0件時(nil返却)でSTORE更新がスキップされる", function()
local SHIORI_ACT = require("pasta.shiori.act")
local STORE = require("pasta.store")
STORE.reset()
STORE.actor_spots["さくら"] = 0
local act = SHIORI_ACT.new({})
local result = act:build()
expect(result):toBe(nil)
expect(STORE.actor_spots["さくら"]):toBe(0)
STORE.reset()
end)
end)
describe("SHIORI_ACT.build() - シーン連続実行でスポット値引き継ぎ (Task 6.2)", function()
test("%行ありシーン → %行なしシーンでスポット値が引き継がれる", function()
local SHIORI_ACT = require("pasta.shiori.act")
local STORE = require("pasta.store")
local ACTOR = require("pasta.actor")
STORE.reset()
local sakura = ACTOR.get_or_create("さくら")
sakura.spot = "sakura"
local kero = ACTOR.get_or_create("うにゅう")
kero.spot = "kero"
local actors = {
sakura = sakura,
kero = kero,
}
local act1 = SHIORI_ACT.new(actors)
act1:set_spot("sakura", 0)
act1:set_spot("kero", 1)
act1.sakura:talk("Scene1 Sakura")
act1.kero:talk("Scene1 Kero")
local result1 = act1:build()
expect(result1):toBeTruthy()
expect(result1:find("\\p%[0%]")):toBeTruthy()
expect(result1:find("\\p%[1%]")):toBeTruthy()
expect(STORE.actor_spots["さくら"]):toBe(0)
expect(STORE.actor_spots["うにゅう"]):toBe(1)
local act2 = SHIORI_ACT.new(actors)
act2.sakura:talk("Scene2 Sakura")
act2.kero:talk("Scene2 Kero")
local result2 = act2:build()
expect(result2):toBeTruthy()
expect(result2:find("\\p%[0%]")):toBeTruthy()
expect(result2:find("\\p%[1%]")):toBeTruthy()
STORE.reset()
end)
end)
describe("SHIORI_ACT.build() - CONFIG未設定時のデフォルト動作 (Task 6.3)", function()
test("CONFIG.actor未定義時にactor_spotsが空テーブルで動作する", function()
local SHIORI_ACT = require("pasta.shiori.act")
local STORE = require("pasta.store")
local ACTOR = require("pasta.actor")
STORE.reset()
local sakura = ACTOR.get_or_create("さくら")
sakura.spot = "sakura"
local actors = { sakura = sakura }
local act = SHIORI_ACT.new(actors)
act.sakura:talk("Default spot")
local result = act:build()
expect(result):toBeTruthy()
expect(result:find("\\p%[0%]")):toBeTruthy()
STORE.reset()
end)
end)