function TestNode.new(v,N,u,j)j=j or TestEnum.NodeModifier.None local a={plan=v;phrase=N;type=u,modifier=j,children={};callback=nil;parent=nil}a.environment=newEnvironment(a,v.extraEnvironment)return setmetatable(a,TestNode)end local function v(v,N,u)if N and(u==nil or u==TestEnum.NodeModifier.None)then if v:match(N)then return TestEnum.NodeModifier.Focus else return TestEnum.NodeModifier.Skip end end return u end function TestNode.addChild(a,N,u,j)if u==TestEnum.NodeType.It then for v,u in pairs(a.children)do if u.phrase==N then error("\068\117\112\108\105\099\097\116\101 \105\116 \098\108\111\099\107 \102\111\117\110\100\058 "..u:getFullName())end end end local l=a:getFullName()..(" "..N)j=v(l,a.plan.testNamePattern,j)local J=TestNode.new(a.plan,N,u,j)J.parent=a table.insert(a.children,J)return J end
--[[
	Create a new test node. A pointer to the test plan, a phrase to describe it
	and the type of node it is are required. The modifier is optional and will
	be None if left blank.
]]
function TestNode.new(plan, phrase, nodeType, nodeModifier)
	nodeModifier = nodeModifier or TestEnum.NodeModifier.None

	local node = {
		plan = plan,
		phrase = phrase,
		type = nodeType,
		modifier = nodeModifier,
		children = {},
		callback = nil,
		parent = nil,
	}

	node.environment = newEnvironment(node, plan.extraEnvironment)
	return setmetatable(node, TestNode)
end

local function getModifier(name, pattern, modifier)
	if pattern and (modifier == nil or modifier == TestEnum.NodeModifier.None) then
		if name:match(pattern) then
			return TestEnum.NodeModifier.Focus
		else
			return TestEnum.NodeModifier.Skip
		end
	end
	return modifier
end

function TestNode:addChild(phrase, nodeType, nodeModifier)
	if nodeType == TestEnum.NodeType.It then
		for _, child in pairs(self.children) do
			if child.phrase == phrase then
				error("Duplicate it block found: " .. child:getFullName())
			end
		end
	end

	local childName = self:getFullName() .. " " .. phrase
	nodeModifier = getModifier(childName, self.plan.testNamePattern, nodeModifier)
	local child = TestNode.new(self.plan, phrase, nodeType, nodeModifier)
	child.parent = self
	table.insert(self.children, child)
	return child
end
