Пример #1
0
	def testOrListMerge(self):
		"Test the funky feature of or-lists attempting to merge adjacent entries."
		for s, sres in self.knownValues:
			p = rdparse.parse(s, MergeTInfo)
			self.assertEqual(str(p), sres)
			# This will error out if finalize has not been called.
			p.eval(None)
			
		# This case should simply return the end node, no fuss no
		# muss.
		p = rdparse.parse("one: a one: b", MergeTInfo)
		self.assertEqual(isinstance(p, MergeTerm), 1)
		p.eval(None)
Пример #2
0
def parseline(line, lineno):
	r = Rule(lineno)
	n = line.split(None, 1)
	if len(n) < 2:
		raise BadInput, "too few elements in rule"
	if n[0][-1] != ':':
		raise BadInput, "class name does not end with a ':'"
	if n[0][0] == '/':
		raise BadInput, "class name section has no actual name"
	rcomp = n[0][:-1]
	# we rstrip for '/label', because this increases the odds of
	# sharing strings if this is a single-argument matcher (the
	# usual case for '/label'). Since whitespace is meaningless
	# at the end of rules, this is harmless.
	rulestr = n[1].rstrip()
	
	# Our major piece of work is parsing the name portion of the
	# rule. Parsing the rule itself is passed off to rdparse.
	pos = rcomp.find('/')
	# pos is either -1 or larger than zero.
	if pos == -1:
		rname = rcomp
	else:
		rname = rcomp[:pos]
		rnotes = rcomp[pos+1:]
		setrulenotes(r, rnotes, rulestr)
	# Set the final bit.
	r.clsname = rname
	try:
		r.matcher = rdparse.parse(rulestr, matchers.matchinfo)
	except rdparse.ParseError, e:
		raise BadInput, e
Пример #3
0
	def testParseEval(self):
		"Test that we properly parse and evaluate known strings."
		for testline in self.knownParseEvals:
			pstr = testline[0]
			pres = testline[1]
			root = rdparse.parse(pstr, matchers.matchinfo)
			self.assertEqual(str(root), pres)
			# The following re-parsing test is pure paranoia.
			# But I'm paranoid.
			r2 = rdparse.parse(pres, matchers.matchinfo)
			self.assertEqual(str(r2), pres, "%s did not reparse identical" % (pres,))
			for ip, res in testline[2:]:
				hi = makehi(rip = ip)
				# We manually add a class so we can use it.
				hi.addclass("frotz")
				self.assertEqual(root.eval(hi), res,
						 "%s failed on host %s" % (pstr, ip))
Пример #4
0
	def testStableRepr(self):
		"Test that reparsing the string version of a matcher gets the same result."
		for p, res in self.basicOps:
			s1 = str(rdparse.parse(p, matchers.matchinfo))
			s2 = str(rdparse.parse(s1, matchers.matchinfo))
			self.assertEqual(s1, s2, "%s did not stabilize" % (p,))
Пример #5
0
	def testParsedRepr(self):
		"Test the ability of all matchers to be parsed and to report themselves."
		for p, res in self.basicOps:
			tree = rdparse.parse(p, matchers.matchinfo)
			self.assertEqual(str(tree), res)
Пример #6
0
	def testReprParses(self):
		"The string representation of parses should parse to the same thing."
		for pstr, strres in self.knownValues:
			res = str(rdparse.parse(pstr, NodeInfo()))
			self.assertEqual(str(rdparse.parse(res, NodeInfo())), res)
Пример #7
0
	def testKnownParses(self):
		"Insure that known good parses parse."
		for pstr, strres in self.knownValues:
			self.assertEqual(str(rdparse.parse(pstr, NodeInfo())), strres)
Пример #8
0
	def testEvaluation(self):
		"Test that the parse trees evaluate properly."
		for s, res in self.knownResults:
			p = rdparse.parse(s, BoolTInfo())
			self.assertEqual(p.eval(None), res, "failed on "+s)