autopep8 formatting
This commit is contained in:
parent
f8710cb984
commit
88447385c2
|
@ -130,7 +130,9 @@ _UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'
|
|||
# Utility functions and classes
|
||||
# =============================
|
||||
|
||||
|
||||
class _AttributeHolder(object):
|
||||
|
||||
"""Abstract base class that provides __repr__.
|
||||
|
||||
The __repr__ method returns a string in the format::
|
||||
|
@ -166,6 +168,7 @@ def _ensure_value(namespace, name, value):
|
|||
# ===============
|
||||
|
||||
class HelpFormatter(object):
|
||||
|
||||
"""Formatter for generating usage messages and argument help strings.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -639,13 +642,14 @@ class HelpFormatter(object):
|
|||
def _fill_text(self, text, width, indent):
|
||||
text = self._whitespace_matcher.sub(' ', text).strip()
|
||||
return _textwrap.fill(text, width, initial_indent=indent,
|
||||
subsequent_indent=indent)
|
||||
subsequent_indent=indent)
|
||||
|
||||
def _get_help_string(self, action):
|
||||
return action.help
|
||||
|
||||
|
||||
class RawDescriptionHelpFormatter(HelpFormatter):
|
||||
|
||||
"""Help message formatter which retains any formatting in descriptions.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -657,6 +661,7 @@ class RawDescriptionHelpFormatter(HelpFormatter):
|
|||
|
||||
|
||||
class RawTextHelpFormatter(RawDescriptionHelpFormatter):
|
||||
|
||||
"""Help message formatter which retains formatting of all help text.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -668,6 +673,7 @@ class RawTextHelpFormatter(RawDescriptionHelpFormatter):
|
|||
|
||||
|
||||
class ArgumentDefaultsHelpFormatter(HelpFormatter):
|
||||
|
||||
"""Help message formatter which adds default values to argument help.
|
||||
|
||||
Only the name of this class is considered a public API. All the methods
|
||||
|
@ -692,7 +698,7 @@ def _get_action_name(argument):
|
|||
if argument is None:
|
||||
return None
|
||||
elif argument.option_strings:
|
||||
return '/'.join(argument.option_strings)
|
||||
return '/'.join(argument.option_strings)
|
||||
elif argument.metavar not in (None, SUPPRESS):
|
||||
return argument.metavar
|
||||
elif argument.dest not in (None, SUPPRESS):
|
||||
|
@ -702,6 +708,7 @@ def _get_action_name(argument):
|
|||
|
||||
|
||||
class ArgumentError(Exception):
|
||||
|
||||
"""An error from creating or using an argument (optional or positional).
|
||||
|
||||
The string value of this exception is the message, augmented with
|
||||
|
@ -722,6 +729,7 @@ class ArgumentError(Exception):
|
|||
|
||||
|
||||
class ArgumentTypeError(Exception):
|
||||
|
||||
"""An error from trying to convert a command line string to a type."""
|
||||
pass
|
||||
|
||||
|
@ -731,6 +739,7 @@ class ArgumentTypeError(Exception):
|
|||
# ==============
|
||||
|
||||
class Action(_AttributeHolder):
|
||||
|
||||
"""Information about how to convert command line strings to Python objects.
|
||||
|
||||
Action objects are used by an ArgumentParser to represent the information
|
||||
|
@ -1108,7 +1117,8 @@ class _SubParsersAction(Action):
|
|||
# parse all the remaining options into the namespace
|
||||
# store any unrecognized options on the object, so that the top
|
||||
# level parser can decide what to do with them
|
||||
namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)
|
||||
namespace, arg_strings = parser.parse_known_args(
|
||||
arg_strings, namespace)
|
||||
if arg_strings:
|
||||
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
|
||||
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
|
||||
|
@ -1119,6 +1129,7 @@ class _SubParsersAction(Action):
|
|||
# ==============
|
||||
|
||||
class FileType(object):
|
||||
|
||||
"""Factory for creating file object types
|
||||
|
||||
Instances of FileType are typically passed as type= arguments to the
|
||||
|
@ -1161,7 +1172,9 @@ class FileType(object):
|
|||
# Optional and Positional Parsing
|
||||
# ===========================
|
||||
|
||||
|
||||
class Namespace(_AttributeHolder):
|
||||
|
||||
"""Simple object for storing attributes.
|
||||
|
||||
Implements equality by attribute names and values, and provides a simple
|
||||
|
@ -1263,7 +1276,6 @@ class _ActionsContainer(object):
|
|||
return action.default
|
||||
return self._defaults.get(dest, None)
|
||||
|
||||
|
||||
# =======================
|
||||
# Adding argument actions
|
||||
# =======================
|
||||
|
@ -1535,6 +1547,7 @@ class _MutuallyExclusiveGroup(_ArgumentGroup):
|
|||
|
||||
|
||||
class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
|
||||
"""Object for parsing command line strings into Python objects.
|
||||
|
||||
Keyword Arguments:
|
||||
|
@ -1610,12 +1623,12 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
default_prefix = prefix_chars[0]
|
||||
if self.add_help:
|
||||
self.add_argument(
|
||||
default_prefix+'h', default_prefix*2+'help',
|
||||
default_prefix + 'h', default_prefix * 2 + 'help',
|
||||
action='help', default=SUPPRESS,
|
||||
help=_('show this help message and exit'))
|
||||
if self.version:
|
||||
self.add_argument(
|
||||
default_prefix+'v', default_prefix*2+'version',
|
||||
default_prefix + 'v', default_prefix * 2 + 'version',
|
||||
action='version', default=SUPPRESS,
|
||||
version=self.version,
|
||||
help=_("show program's version number and exit"))
|
||||
|
@ -2075,7 +2088,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
# if multiple actions match, the option string was ambiguous
|
||||
if len(option_tuples) > 1:
|
||||
options = ', '.join([option_string
|
||||
for action, option_string, explicit_arg in option_tuples])
|
||||
for action, option_string, explicit_arg in option_tuples])
|
||||
tup = arg_string, options
|
||||
self.error(_('ambiguous option: %s could match %s') % tup)
|
||||
|
||||
|
|
|
@ -2,33 +2,34 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def readdate(data):
|
||||
datepos = -1
|
||||
if data[:5] == 'DATE ':
|
||||
datepos = 0
|
||||
else:
|
||||
datepos = data.find('\nDATE ')
|
||||
if datepos >= 0:
|
||||
datepos = datepos + 1
|
||||
datepos = -1
|
||||
if data[:5] == 'DATE ':
|
||||
datepos = 0
|
||||
else:
|
||||
datepos = data.find('\nDATE ')
|
||||
if datepos >= 0:
|
||||
datepos = datepos + 1
|
||||
|
||||
if datepos < 0:
|
||||
return None
|
||||
if datepos < 0:
|
||||
return None
|
||||
|
||||
datestr = ''
|
||||
datepos = datepos + 5
|
||||
while True:
|
||||
if datepos >= len(data):
|
||||
return None
|
||||
d = data[datepos]
|
||||
if d>='0' and d<='9':
|
||||
datestr = datestr + d
|
||||
elif d=='\n':
|
||||
if len(datestr) == 8:
|
||||
return datestr[:4] + '-' + datestr[4:6] + '-' + datestr[6:]
|
||||
return None
|
||||
elif d!=' ' and d!='-':
|
||||
return None
|
||||
datepos = datepos + 1
|
||||
datestr = ''
|
||||
datepos = datepos + 5
|
||||
while True:
|
||||
if datepos >= len(data):
|
||||
return None
|
||||
d = data[datepos]
|
||||
if d >= '0' and d <= '9':
|
||||
datestr = datestr + d
|
||||
elif d == '\n':
|
||||
if len(datestr) == 8:
|
||||
return datestr[:4] + '-' + datestr[4:6] + '-' + datestr[6:]
|
||||
return None
|
||||
elif d != ' ' and d != '-':
|
||||
return None
|
||||
datepos = datepos + 1
|
||||
|
||||
path = '.'
|
||||
if len(sys.argv) == 2:
|
||||
|
@ -46,47 +47,48 @@ recent = []
|
|||
|
||||
daca2 = os.path.expanduser('~/daca2/')
|
||||
for lib in range(2):
|
||||
for a in "0123456789abcdefghijklmnopqrstuvwxyz":
|
||||
if lib == 1:
|
||||
a = "lib" + a
|
||||
if os.path.isfile(daca2 + a + '/results.txt'):
|
||||
f = open(daca2 + a + '/results.txt', 'rt')
|
||||
data = f.read()
|
||||
f.close()
|
||||
for a in "0123456789abcdefghijklmnopqrstuvwxyz":
|
||||
if lib == 1:
|
||||
a = "lib" + a
|
||||
if os.path.isfile(daca2 + a + '/results.txt'):
|
||||
f = open(daca2 + a + '/results.txt', 'rt')
|
||||
data = f.read()
|
||||
f.close()
|
||||
|
||||
datestr = readdate(data)
|
||||
if datestr:
|
||||
if not lastupdate or datestr > lastupdate:
|
||||
lastupdate = datestr
|
||||
recent = []
|
||||
if datestr == lastupdate:
|
||||
recent.append(a)
|
||||
datestr = readdate(data)
|
||||
if datestr:
|
||||
if not lastupdate or datestr > lastupdate:
|
||||
lastupdate = datestr
|
||||
recent = []
|
||||
if datestr == lastupdate:
|
||||
recent.append(a)
|
||||
|
||||
mainpage.write('<a href="daca2-'+a+'.html">'+a+'</a><br>\n')
|
||||
mainpage.write(
|
||||
'<a href="daca2-' + a + '.html">' + a + '</a><br>\n')
|
||||
|
||||
data = data.replace('&', ' ')
|
||||
data = data.replace('<', '<')
|
||||
data = data.replace('>', '>')
|
||||
data = data.replace('\'', ''')
|
||||
data = data.replace('"', '"')
|
||||
data = data.replace('\n', '\n')
|
||||
data = data.replace('&', ' ')
|
||||
data = data.replace('<', '<')
|
||||
data = data.replace('>', '>')
|
||||
data = data.replace('\'', ''')
|
||||
data = data.replace('"', '"')
|
||||
data = data.replace('\n', '\n')
|
||||
|
||||
f = open(path+'/daca2-'+a+'.html', 'wt')
|
||||
f.write('<html>\n')
|
||||
f.write('<head><title>DACA2 - ' + a + '</title></head>\n')
|
||||
f.write('<body>\n')
|
||||
f.write('<h1>DACA2 - ' + a + '</h1>')
|
||||
f.write('<pre>\n' + data + '</pre>\n')
|
||||
f.write('</body>\n')
|
||||
f.write('</html>\n')
|
||||
f.close()
|
||||
f = open(path + '/daca2-' + a + '.html', 'wt')
|
||||
f.write('<html>\n')
|
||||
f.write('<head><title>DACA2 - ' + a + '</title></head>\n')
|
||||
f.write('<body>\n')
|
||||
f.write('<h1>DACA2 - ' + a + '</h1>')
|
||||
f.write('<pre>\n' + data + '</pre>\n')
|
||||
f.write('</body>\n')
|
||||
f.write('</html>\n')
|
||||
f.close()
|
||||
|
||||
if lastupdate:
|
||||
mainpage.write('<p>Last update: ' + lastupdate + '</p>')
|
||||
allrecent = ''
|
||||
for r in recent:
|
||||
allrecent = allrecent + ' <a href="daca2-'+r+'.html">' + r + '</a>'
|
||||
mainpage.write('<p>Most recently updated: ' + allrecent + '</p>')
|
||||
mainpage.write('<p>Last update: ' + lastupdate + '</p>')
|
||||
allrecent = ''
|
||||
for r in recent:
|
||||
allrecent = allrecent + ' <a href="daca2-' + r + '.html">' + r + '</a>'
|
||||
mainpage.write('<p>Most recently updated: ' + allrecent + '</p>')
|
||||
|
||||
mainpage.write('</body>\n')
|
||||
mainpage.write('</html>\n')
|
||||
|
|
|
@ -21,6 +21,7 @@ FTPSERVER = 'ftp.sunet.se'
|
|||
FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/'
|
||||
FOLDER = 'b'
|
||||
|
||||
|
||||
def handleRemoveReadonly(func, path, exc):
|
||||
import stat
|
||||
if not os.access(path, os.W_OK):
|
||||
|
@ -30,6 +31,7 @@ def handleRemoveReadonly(func, path, exc):
|
|||
else:
|
||||
raise
|
||||
|
||||
|
||||
def removeAllExceptResults():
|
||||
count = 5
|
||||
while count > 0:
|
||||
|
@ -63,9 +65,10 @@ def removeAllExceptResults():
|
|||
continue
|
||||
count = 0
|
||||
|
||||
|
||||
def removeLargeFiles(path):
|
||||
for g in glob.glob(path + '*'):
|
||||
if g=='.' or g=='..':
|
||||
if g == '.' or g == '..':
|
||||
continue
|
||||
if os.path.isdir(g):
|
||||
removeLargeFiles(g + '/')
|
||||
|
@ -74,6 +77,7 @@ def removeLargeFiles(path):
|
|||
if statinfo.st_size > 100000:
|
||||
os.remove(g)
|
||||
|
||||
|
||||
def scanarchive(fullpath):
|
||||
results = open('results.txt', 'at')
|
||||
results.write(fullpath + '\n')
|
||||
|
|
|
@ -27,6 +27,7 @@ import re
|
|||
|
||||
|
||||
class Extract:
|
||||
|
||||
"""
|
||||
Read Cppcheck test file and create data
|
||||
representation
|
||||
|
@ -50,7 +51,7 @@ class Extract:
|
|||
fin = open(filename, 'r')
|
||||
for line in fin:
|
||||
# testclass starts
|
||||
res = re.match('class ('+name+')', line)
|
||||
res = re.match('class (' + name + ')', line)
|
||||
if res is not None:
|
||||
testclass = res.group(1)
|
||||
|
||||
|
@ -59,7 +60,7 @@ class Extract:
|
|||
testclass = None
|
||||
|
||||
# function start
|
||||
res = re.match('\\s+void ('+name+')\\(\\)', line)
|
||||
res = re.match('\\s+void (' + name + ')\\(\\)', line)
|
||||
if res is not None:
|
||||
functionName = res.group(1)
|
||||
|
||||
|
@ -70,12 +71,12 @@ class Extract:
|
|||
continue
|
||||
|
||||
# check
|
||||
res = re.match('\s+check.*\('+string, line)
|
||||
res = re.match('\s+check.*\(' + string, line)
|
||||
if res is not None:
|
||||
code = res.group(1)
|
||||
|
||||
# code..
|
||||
res = re.match('\\s+'+string, line)
|
||||
res = re.match('\\s+' + string, line)
|
||||
if res is not None:
|
||||
code = code + res.group(1)
|
||||
|
||||
|
@ -114,7 +115,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
fout.write('<head>\n')
|
||||
fout.write(' <style type="text/css">\n')
|
||||
fout.write(' body { font-size: 0.8em }\n')
|
||||
fout.write(' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
fout.write(
|
||||
' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
fout.write(' td { background-color: white; vertical-align: text-top }\n')
|
||||
fout.write(' pre { background-color: #EEEEEE }\n')
|
||||
fout.write(' </style>\n')
|
||||
|
@ -123,9 +125,10 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
|
||||
fout.write('<a href="index.htm">Home</a> -- ')
|
||||
if errorsOnly:
|
||||
fout.write('<a href="all-'+functionName+'.htm">All test cases</a>')
|
||||
fout.write('<a href="all-' + functionName + '.htm">All test cases</a>')
|
||||
else:
|
||||
fout.write('<a href="errors-'+functionName+'.htm">Error test cases</a>')
|
||||
fout.write(
|
||||
'<a href="errors-' + functionName + '.htm">Error test cases</a>')
|
||||
fout.write('<br><br>')
|
||||
|
||||
testclass = None
|
||||
|
@ -138,13 +141,17 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
|
||||
if not testclass:
|
||||
testclass = node['testclass']
|
||||
fout.write('<h1>' + node['testclass'] + '::' + functionName + '</h1>')
|
||||
fout.write(
|
||||
'<h1>' + node['testclass'] + '::' + functionName + '</h1>')
|
||||
fout.write('<table border="0" cellspacing="0">\n')
|
||||
fout.write(' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
|
||||
fout.write(
|
||||
' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
|
||||
|
||||
fout.write(' <tr><td>' + str(num) + '</td>')
|
||||
fout.write('<td><pre>' + strtoxml(node['code']).replace('\\n', '\n') + '</pre></td>')
|
||||
fout.write('<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
|
||||
fout.write('<td><pre>' + strtoxml(
|
||||
node['code']).replace('\\n', '\n') + '</pre></td>')
|
||||
fout.write(
|
||||
'<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
|
||||
fout.write('</tr>\n')
|
||||
|
||||
if testclass is not None:
|
||||
|
@ -155,7 +162,8 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
|||
|
||||
if len(sys.argv) <= 1 or '--help' in sys.argv:
|
||||
print ('Extract test cases from test file')
|
||||
print ('Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp')
|
||||
print (
|
||||
'Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp')
|
||||
sys.exit(0)
|
||||
|
||||
# parse command line
|
||||
|
@ -189,7 +197,7 @@ if filename is not None:
|
|||
print ('<tree>')
|
||||
count = 0
|
||||
for node in e.nodes:
|
||||
s = ' <node'
|
||||
s = ' <node'
|
||||
s += ' function="' + node['functionName'] + '"'
|
||||
s += ' code="' + strtoxml(node['code']) + '"'
|
||||
s += ' expected="' + strtoxml(node['expected']) + '"'
|
||||
|
@ -206,8 +214,10 @@ if filename is not None:
|
|||
findex.write('<head>\n')
|
||||
findex.write(' <style type="text/css">\n')
|
||||
findex.write(' table { font-size: 0.8em }\n')
|
||||
findex.write(' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
findex.write(' td { background-color: #F0FFE0; vertical-align: text-top }\n')
|
||||
findex.write(
|
||||
' th { background-color: #A3C159; text-transform: uppercase }\n')
|
||||
findex.write(
|
||||
' td { background-color: #F0FFE0; vertical-align: text-top }\n')
|
||||
findex.write(' A:link { text-decoration: none }\n')
|
||||
findex.write(' A:visited { text-decoration: none }\n')
|
||||
findex.write(' A:active { text-decoration: none }\n')
|
||||
|
@ -227,7 +237,7 @@ if filename is not None:
|
|||
findex.write('<table border="0" cellspacing="0">\n')
|
||||
findex.write(' <tr><th>Name</th><th>Errors</th><th>All</th></tr>\n')
|
||||
for functionname in functionNames:
|
||||
findex.write(' <tr><td>'+functionname+'</td>')
|
||||
findex.write(' <tr><td>' + functionname + '</td>')
|
||||
numall = 0
|
||||
numerr = 0
|
||||
for node in e.nodes:
|
||||
|
@ -238,8 +248,10 @@ if filename is not None:
|
|||
if numerr == 0:
|
||||
findex.write('<td><div align="right">0</div></td>')
|
||||
else:
|
||||
findex.write('<td><a href="errors-'+functionname+'.htm"><div align="right">' + str(numerr) + '</div></a></td>')
|
||||
findex.write('<td><a href="all-'+functionname+'.htm"><div align="right">' + str(numall) + '</div></a></td>')
|
||||
findex.write('<td><a href="errors-' + functionname +
|
||||
'.htm"><div align="right">' + str(numerr) + '</div></a></td>')
|
||||
findex.write('<td><a href="all-' + functionname +
|
||||
'.htm"><div align="right">' + str(numall) + '</div></a></td>')
|
||||
findex.write('</tr>\n')
|
||||
|
||||
findex.write('</table>\n')
|
||||
|
@ -267,7 +279,7 @@ if filename is not None:
|
|||
if not os.path.exists(codedir):
|
||||
os.mkdir(codedir)
|
||||
|
||||
errors = open(codedir+'errors.txt', 'w')
|
||||
errors = open(codedir + 'errors.txt', 'w')
|
||||
|
||||
for node in e.nodes:
|
||||
testnum = testnum + 1
|
||||
|
@ -291,7 +303,8 @@ if filename is not None:
|
|||
if expected != '':
|
||||
expected = expected.replace('\\n', '\n')
|
||||
expected = expected.replace('\\"', '"')
|
||||
expected = re.sub('\\[test.cp?p?:', '['+filename+':', expected)
|
||||
expected = re.sub(
|
||||
'\\[test.cp?p?:', '[' + filename + ':', expected)
|
||||
errors.write(expected)
|
||||
errors.close()
|
||||
else:
|
||||
|
|
|
@ -21,13 +21,17 @@ import matchcompiler
|
|||
|
||||
|
||||
class MatchCompilerTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mc = matchcompiler.MatchCompiler(verify_mode=False)
|
||||
|
||||
def test_parseMatch(self):
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok, ";") ', 2), ['Token::Match(tok, ";")', 'tok', ' ";"'])
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok,', 2), None) # multiline Token::Match is not supported yet
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(Token::findsimplematch(tok,")"), ";")', 2), ['Token::Match(Token::findsimplematch(tok,")"), ";")', 'Token::findsimplematch(tok,")")', ' ";"']) # inner function call
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok, ";") ', 2), [
|
||||
'Token::Match(tok, ";")', 'tok', ' ";"'])
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(tok,', 2), None)
|
||||
# multiline Token::Match is not supported yet
|
||||
self.assertEqual(self.mc.parseMatch(' Token::Match(Token::findsimplematch(tok,")"), ";")', 2), [
|
||||
'Token::Match(Token::findsimplematch(tok,")"), ";")', 'Token::findsimplematch(tok,")")', ' ";"']) # inner function call
|
||||
|
||||
def test_replaceTokenMatch(self):
|
||||
input = 'if (Token::Match(tok, "foobar")) {'
|
||||
|
@ -44,7 +48,8 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
input = 'if (Token::Match(tok, "foo\"special\"bar %num%")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::Match(tok, "foo"special"bar %num%")) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::Match(tok, "foo"special"bar %num%")) {')
|
||||
# self.assertEqual(3, len(self.mc._matchStrs))
|
||||
|
||||
def test_replaceTokenMatchWithVarId(self):
|
||||
|
@ -55,13 +60,15 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
|
||||
input = 'if (Token::Match(tok->next()->next(), "%varid% foobar", tok->varId())) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
self.assertEqual(output, 'if (match2(tok->next()->next(), tok->varId())) {')
|
||||
self.assertEqual(
|
||||
output, 'if (match2(tok->next()->next(), tok->varId())) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
input = 'if (Token::Match(tok, "foo\"special\"bar %type% %varid%", my_varid_cache)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::Match(tok, "foo"special"bar %type% %varid%", my_varid_cache)) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::Match(tok, "foo"special"bar %type% %varid%", my_varid_cache)) {')
|
||||
# self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
# test caching: reuse existing matchX()
|
||||
|
@ -92,7 +99,8 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
input = 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
def test_replaceTokenFindSimpleMatch(self):
|
||||
|
@ -104,14 +112,16 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
|
||||
input = 'if (Token::findsimplematch(tok->next()->next(), "foobar", tok->link())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
self.assertEqual(output, 'if (findmatch2(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch2(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
self.assertEqual(1, self.mc._matchStrs['foobar'])
|
||||
|
||||
input = 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
# FIXME: Currently detected as non-static pattern
|
||||
self.assertEqual(output, 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(
|
||||
output, 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {')
|
||||
self.assertEqual(1, len(self.mc._matchStrs))
|
||||
|
||||
def test_replaceTokenFindMatch(self):
|
||||
|
@ -131,14 +141,16 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
# findmatch with end token
|
||||
input = 'if (Token::findmatch(tok->next()->next(), "foobar %type%", tok->link())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
self.assertEqual(output, 'if (findmatch3(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch3(tok->next()->next(), tok->link())) {')
|
||||
self.assertEqual(2, len(self.mc._matchStrs))
|
||||
self.assertEqual(1, self.mc._matchStrs['foobar'])
|
||||
|
||||
# findmatch with end token and varid
|
||||
input = 'if (Token::findmatch(tok->next()->next(), "foobar %type% %varid%", tok->link(), 123)) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
self.assertEqual(output, 'if (findmatch4(tok->next()->next(), tok->link(), 123)) {')
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch4(tok->next()->next(), tok->link(), 123)) {')
|
||||
self.assertEqual(2, len(self.mc._matchStrs))
|
||||
self.assertEqual(1, self.mc._matchStrs['foobar'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue