local d=require("\064\112\107\103\047\074\101\115\116\071\108\111\098\097\108\115")local h=d.test local c=d.expect local W=require("\046\047\098\105\110\100")h("\098\105\110\100\115 \'\115\101\108\102\' \116\111 \116\104\101 \103\105\118\101\110 \099\097\108\108\098\097\099\107",function()local d={value="\102\111\111",callback=function(d)return d.value end}local h=W(d,d.callback);(c(h())).toBe("\102\111\111")end)h("\119\111\114\107\115 \102\111\114 \116\104\101 \117\115\097\103\101 \101\120\097\109\112\108\101",function()local d={}d.__index=d function d.new()local h={}h.value="\102\111\111"return setmetatable(h,d)end function d.getValue(d)return d.value end local h=d.new()local a=W(h,h.getValue);(c(a())).toBe("\102\111\111")end)
local JestGlobals = require("@pkg/JestGlobals")
local test = JestGlobals.test
local expect = JestGlobals.expect

local bind = require("./bind")

test("binds 'self' to the given callback", function()
	local module = {
		value = "foo",
		callback = function(self)
			return self.value
		end,
	}

	local callback = bind(module, module.callback)

	expect(callback()).toBe("foo")
end)

test("works for the usage example", function()
	local Class = {}
	Class.__index = Class

	function Class.new()
		local self = {}
		self.value = "foo"
		return setmetatable(self, Class)
	end

	function Class:getValue()
		return self.value
	end

	local instance = Class.new()
	local getValue = bind(instance, instance.getValue)

	expect(getValue()).toBe("foo")
end)
