function Expectation.new(g)local h={value=g;successCondition=true,condition=false,matchers={},_boundMatchers={}}setmetatable(h,Expectation)h.a=bindSelf(h,h.a)h.an=h.a h.ok=bindSelf(h,h.ok)h.equal=bindSelf(h,h.equal)h.throw=bindSelf(h,h.throw)h.near=bindSelf(h,h.near)return h end function Expectation.checkMatcherNameCollisions(g)if SELF_KEYS[g]or NEGATION_KEYS[g]or Expectation[g]then return false end return true end function Expectation.extend(h,g)h.matchers=g or{}for g,l in pairs(h.matchers)do h._boundMatchers[g]=bindSelf(h,function(g,...)local V=l(h.value,...)local G=V.pass==h.successCondition assertLevel(G,V.message,3)h:_resetModifiers()return h end)end return h end function Expectation.__index(g,h)if SELF_KEYS[h]then return g end if NEGATION_KEYS[h]then local h=(Expectation.new(g.value)):extend(g.matchers)h.successCondition=not g.successCondition return h end if g._boundMatchers[h]then return g._boundMatchers[h]end return Expectation[h]end
--[[
	Create a new expectation
]]
function Expectation.new(value)
	local self = {
		value = value,
		successCondition = true,
		condition = false,
		matchers = {},
		_boundMatchers = {},
	}

	setmetatable(self, Expectation)

	self.a = bindSelf(self, self.a)
	self.an = self.a
	self.ok = bindSelf(self, self.ok)
	self.equal = bindSelf(self, self.equal)
	self.throw = bindSelf(self, self.throw)
	self.near = bindSelf(self, self.near)

	return self
end

function Expectation.checkMatcherNameCollisions(name)
	if SELF_KEYS[name] or NEGATION_KEYS[name] or Expectation[name] then
		return false
	end

	return true
end

function Expectation:extend(matchers)
	self.matchers = matchers or {}

	for name, implementation in pairs(self.matchers) do
		self._boundMatchers[name] = bindSelf(self, function(_self, ...)
			local result = implementation(self.value, ...)
			local pass = result.pass == self.successCondition

			assertLevel(pass, result.message, 3)
			self:_resetModifiers()
			return self
		end)
	end

	return self
end

function Expectation.__index(self, key)
	-- Keys that don't do anything except improve readability
	if SELF_KEYS[key] then
		return self
	end

	-- Invert your assertion
	if NEGATION_KEYS[key] then
		local newExpectation = Expectation.new(self.value):extend(self.matchers)
		newExpectation.successCondition = not self.successCondition

		return newExpectation
	end

	if self._boundMatchers[key] then
		return self._boundMatchers[key]
	end

	-- Fall back to methods provided by Expectation
	return Expectation[key]
end
