示例#1
0
def ParseCheckerAssertion(parent, line, variant, lineNo):
  """ This method parses the content of a check line stripped of the initial
      comment symbol and the CHECK keyword.
  """
  assertion = TestAssertion(parent, variant, line, lineNo)
  # Loop as long as there is something to parse.
  while line:
    # Search for the nearest occurrence of the special markers.
    matchWhitespace = re.search(r"\s+", line)
    matchPattern = re.search(RegexExpression.Regex.regexPattern, line)
    matchVariableReference = re.search(RegexExpression.Regex.regexVariableReference, line)
    matchVariableDefinition = re.search(RegexExpression.Regex.regexVariableDefinition, line)

    # If one of the above was identified at the current position, extract them
    # from the line, parse them and add to the list of line parts.
    if __isMatchAtStart(matchWhitespace):
      # A whitespace in the check line creates a new separator of line parts.
      # This allows for ignored output between the previous and next parts.
      line = line[matchWhitespace.end():]
      assertion.addExpression(RegexExpression.createSeparator())
    elif __isMatchAtStart(matchPattern):
      pattern = line[0:matchPattern.end()]
      pattern = pattern[2:-2]
      line = line[matchPattern.end():]
      assertion.addExpression(RegexExpression.createPattern(pattern))
    elif __isMatchAtStart(matchVariableReference):
      var = line[0:matchVariableReference.end()]
      line = line[matchVariableReference.end():]
      name = var[2:-2]
      assertion.addExpression(RegexExpression.createVariableReference(name))
    elif __isMatchAtStart(matchVariableDefinition):
      var = line[0:matchVariableDefinition.end()]
      line = line[matchVariableDefinition.end():]
      colonPos = var.find(":")
      name = var[2:colonPos]
      body = var[colonPos+1:-2]
      assertion.addExpression(RegexExpression.createVariableDefinition(name, body))
    else:
      # If we're not currently looking at a special marker, this is a plain
      # text match all the way until the first special marker (or the end
      # of the line).
      firstMatch = __firstMatch([ matchWhitespace,
                                  matchPattern,
                                  matchVariableReference,
                                  matchVariableDefinition ],
                                line)
      text = line[0:firstMatch]
      line = line[firstMatch:]
      assertion.addExpression(RegexExpression.createText(text))
  return assertion
示例#2
0
 def createFile(self, caseList):
   testFile = CheckerFile("<test_file>")
   for caseEntry in caseList:
     caseName = caseEntry[0]
     testCase = TestCase(testFile, caseName, 0)
     assertionList = caseEntry[1]
     for assertionEntry in assertionList:
       content = assertionEntry[0]
       variant = assertionEntry[1]
       assertion = TestAssertion(testCase, variant, content, 0)
       assertion.addExpression(RegexExpression.createText(content))
   return testFile
示例#3
0
 def assertEqualsVarRef(self, string, name):
   self.assertEqual(self.parseExpression(string), RegexExpression.createVariableReference(name))
示例#4
0
 def assertEqualsPattern(self, string, pattern):
   self.assertEqual(self.parseExpression(string), RegexExpression.createPattern(pattern))
示例#5
0
 def assertEqualsText(self, string, text):
   self.assertEqual(self.parseExpression(string), RegexExpression.createText(text))
示例#6
0
 def assertEqualsVarDef(self, string, name, pattern):
   self.assertEqual(self.parseExpression(string),
                    RegexExpression.createVariableDefinition(name, pattern))