function Expectation.new(R)local k={value=R,successCondition=true;condition=false,matchers={},_boundMatchers={}}setmetatable(k,Expectation)k.a=bindSelf(k,k.a)k.an=k.a k.ok=bindSelf(k,k.ok)k.equal=bindSelf(k,k.equal)k.throw=bindSelf(k,k.throw)k.near=bindSelf(k,k.near)return k end function Expectation.checkMatcherNameCollisions(R)if SELF_KEYS[R]or NEGATION_KEYS[R]or Expectation[R]then return false end return true end function Expectation.extend(k,R)k.matchers=R or{}for R,t in pairs(k.matchers)do k._boundMatchers[R]=bindSelf(k,function(R,...)local u=t(k.value,...)local n=u.pass==k.successCondition assertLevel(n,u.message,3)k:_resetModifiers()return k end)end return k end function Expectation.__index(R,k)if SELF_KEYS[k]then return R end if NEGATION_KEYS[k]then local k=(Expectation.new(R.value)):extend(R.matchers)k.successCondition=not R.successCondition return k end if R._boundMatchers[k]then return R._boundMatchers[k]end return Expectation[k]end

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
