local G=require("\105\110\118\111\107\097\116\105\111\110\046\099\111\109\098\111\115\046\067\111\109\098\111\083\116\101\112")describe("\067\111\109\098\111\083\116\101\112",function()local z={id=1,name="\115\116\101\112\095\110\097\109\101",required=true;next={2,3}}local f before_each(function()f=G(z)end)describe("\046\083\116\097\116\101\078\097\109\101",function()it("\103\101\110\101\114\097\116\101\115 \097 \115\116\097\116\101 \110\097\109\101",function()assert.equal("\049\058\115\116\101\112\095\110\097\109\101",G.StateName(f))f.id=2 assert.equal("\050\058\115\116\101\112\095\110\097\109\101",G.StateName(f))f.id=3 f.name="\097\110\111\116\104\101\114\095\115\116\101\112"assert.equal("\051\058\097\110\111\116\104\101\114\095\115\116\101\112",G.StateName(f))end)end)describe("\046\069\118\101\110\116\078\097\109\101",function()it("\103\101\110\101\114\097\116\101\115 \097\110 \101\118\101\110\116 \110\097\109\101",function()assert.equal("\115\116\101\112\095\110\097\109\101",G.EventName(f))f.name="\097\110\111\116\104\101\114\095\115\116\101\112"assert.equal("\097\110\111\116\104\101\114\095\115\116\101\112",G.EventName(f))end)end)describe("\046\083\116\101\112\073\100",function()describe("\119\105\116\104 \118\097\108\105\100 \115\116\097\116\101 \110\097\109\101",function()it("\101\120\116\114\097\099\116\115 \097 \110\117\109\101\114\105\099 \115\116\101\112 \105\100 \102\114\111\109 \097 \115\116\097\116\101 \110\097\109\101",function()assert.equal(13,G.StepId("\049\051\058\115\116\101\112\095\110\097\109\101"))assert.equal(31,G.StepId("\051\049\058\097\110\111\116\104\101\114\095\115\116\101\112"))assert.equal(44,G.StepId("\052\052\058\121\101\116\095\097\110\111\116\104\101\114\095\115\116\101\112"))end)end)describe("\119\105\116\104 \097\110 \105\110\118\097\108\105\100 \115\116\097\116\101 \110\097\109\101",function()it("\114\101\116\117\114\110\115 \110\105\108",function()assert.is_nil(G.StepId("\105\110\118\097\108\105\100\095\115\116\097\116\101\095\110\097\109\101"))assert.is_nil(G.StepId("\105\110\118\097\108\105\100\058\115\116\097\116\101\095\110\097\109\101"))assert.is_nil(G.StepId("\048\046\053\058\115\116\097\116\101\095\110\097\109\101"))end)end)end)describe("\099\111\110\115\116\114\117\099\116\111\114",function()it("\105\110\105\116\105\097\108\105\122\101\115 \097\116\116\114\105\098\117\116\101\115",function()assert.equal(G.StateName(f),f.state)assert.equal(G.EventName(f),f.event)end)end)end)
local ComboStep = require("invokation.combos.ComboStep")

describe("ComboStep", function()
  local data = { id = 1, name = "step_name", required = true, next = { 2, 3 } }

  local step

  before_each(function()
    step = ComboStep(data)
  end)

  describe(".StateName", function()
    it("generates a state name", function()
      assert.equal("1:step_name", ComboStep.StateName(step))

      step.id = 2

      assert.equal("2:step_name", ComboStep.StateName(step))

      step.id = 3
      step.name = "another_step"

      assert.equal("3:another_step", ComboStep.StateName(step))
    end)
  end)

  describe(".EventName", function()
    it("generates an event name", function()
      assert.equal("step_name", ComboStep.EventName(step))

      step.name = "another_step"

      assert.equal("another_step", ComboStep.EventName(step))
    end)
  end)

  describe(".StepId", function()
    describe("with valid state name", function()
      it("extracts a numeric step id from a state name", function()
        assert.equal(13, ComboStep.StepId("13:step_name"))
        assert.equal(31, ComboStep.StepId("31:another_step"))
        assert.equal(44, ComboStep.StepId("44:yet_another_step"))
      end)
    end)

    describe("with an invalid state name", function()
      it("returns nil", function()
        assert.is_nil(ComboStep.StepId("invalid_state_name"))
        assert.is_nil(ComboStep.StepId("invalid:state_name"))
        assert.is_nil(ComboStep.StepId("0.5:state_name"))
      end)
    end)
  end)

  describe("constructor", function()
    it("initializes attributes", function()
      assert.equal(ComboStep.StateName(step), step.state)
      assert.equal(ComboStep.EventName(step), step.event)
    end)
  end)
end)
