local U=require("\105\110\118\111\107\097\116\105\111\110\046\108\097\110\103\046\102\117\110\099\116\105\111\110")describe("\102\117\110\099\116\105\111\110",function()describe("\046\108\111\111\107\117\112\098\121\110\097\109\101",function()it("\099\114\101\097\116\101\115 \097 \119\114\097\112\112\101\114 \102\117\110\099\116\105\111\110 \116\104\097\116 \112\101\114\102\111\114\109\115 \109\101\116\104\111\100 \108\111\111\107\117\112 \098\121 \110\097\109\101",function()local e={}e.greet=function(U)return"\071\114\101\101\116\105\110\103\115\044 "..U end local Q=spy.on(e,"\103\114\101\101\116")local R=U.lookupbyname(e,"\103\114\101\101\116")assert.is_function(R)assert.not_equal(e.greet,R)assert.equal("\071\114\101\101\116\105\110\103\115\044 \065\108\105\099\101",R("\065\108\105\099\101"));(assert.spy(Q)).was.called_with("\065\108\105\099\101")e.greet=function(U)return"\087\101\108\099\111\109\101\044 "..U end Q=spy.on(e,"\103\114\101\101\116")assert.equal("\087\101\108\099\111\109\101\044 \066\111\098",R("\066\111\098"));(assert.spy(Q)).was.called_with("\066\111\098")end)end)end)
local func = require("invokation.lang.function")

describe("function", function()
  describe(".lookupbyname", function()
    it("creates a wrapper function that performs method lookup by name", function()
      local t = {}

      t.greet = function(name)
        return "Greetings, " .. name
      end

      local greetSpy = spy.on(t, "greet")
      local fn = func.lookupbyname(t, "greet")

      assert.is_function(fn)
      assert.not_equal(t.greet, fn)
      assert.equal("Greetings, Alice", fn("Alice"))
      assert.spy(greetSpy).was.called_with("Alice")

      t.greet = function(name)
        return "Welcome, " .. name
      end

      greetSpy = spy.on(t, "greet")

      assert.equal("Welcome, Bob", fn("Bob"))
      assert.spy(greetSpy).was.called_with("Bob")
    end)
  end)
end)
