Fixes issue 139 and issue 140.
This commit is contained in:
parent
bce8134d89
commit
f4eeaedb39
@ -82,9 +82,25 @@ def _GenerateMethods(output_lines, source, class_node):
|
|||||||
return_type += '*'
|
return_type += '*'
|
||||||
if node.return_type.reference:
|
if node.return_type.reference:
|
||||||
return_type += '&'
|
return_type += '&'
|
||||||
mock_method_macro = 'MOCK_%sMETHOD%d' % (const, len(node.parameters))
|
num_parameters = len(node.parameters)
|
||||||
|
if len(node.parameters) == 1:
|
||||||
|
first_param = node.parameters[0]
|
||||||
|
if source[first_param.start:first_param.end].strip() == 'void':
|
||||||
|
# We must treat T(void) as a function with no parameters.
|
||||||
|
num_parameters = 0
|
||||||
|
mock_method_macro = 'MOCK_%sMETHOD%d' % (const, num_parameters)
|
||||||
args = ''
|
args = ''
|
||||||
if node.parameters:
|
if node.parameters:
|
||||||
|
# Due to the parser limitations, it is impossible to keep comments
|
||||||
|
# while stripping the default parameters. When defaults are
|
||||||
|
# present, we choose to strip them and comments (and produce
|
||||||
|
# compilable code).
|
||||||
|
# TODO(nnorwitz@google.com): Investigate whether it is possible to
|
||||||
|
# preserve parameter name when reconstructing parameter text from
|
||||||
|
# the AST.
|
||||||
|
if len([param for param in node.parameters if param.default]) > 0:
|
||||||
|
args = ', '.join(param.type.name for param in node.parameters)
|
||||||
|
else:
|
||||||
# Get the full text of the parameters from the start
|
# Get the full text of the parameters from the start
|
||||||
# of the first parameter to the end of the last parameter.
|
# of the first parameter to the end of the last parameter.
|
||||||
start = node.parameters[0].start
|
start = node.parameters[0].start
|
||||||
|
@ -76,6 +76,17 @@ class Foo {
|
|||||||
'MOCK_CONST_METHOD1(Bar,\nvoid(bool flag));',
|
'MOCK_CONST_METHOD1(Bar,\nvoid(bool flag));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
|
def testExplicitVoid(self):
|
||||||
|
source = """
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
virtual int Bar(void);
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
|
'MOCK_METHOD0(Bar,\nint(void));',
|
||||||
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testStrangeNewlineInParameter(self):
|
def testStrangeNewlineInParameter(self):
|
||||||
source = """
|
source = """
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -88,6 +99,40 @@ a) = 0;
|
|||||||
'MOCK_METHOD1(Bar,\nvoid(int a));',
|
'MOCK_METHOD1(Bar,\nvoid(int a));',
|
||||||
self.GenerateMethodSource(source))
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
|
def testDefaultParameters(self):
|
||||||
|
source = """
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
virtual void Bar(int a, char c = 'x') = 0;
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
|
'MOCK_METHOD2(Bar,\nvoid(int, char));',
|
||||||
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
|
def testMultipleDefaultParameters(self):
|
||||||
|
source = """
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
virtual void Bar(int a = 42, char c = 'x') = 0;
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
|
'MOCK_METHOD2(Bar,\nvoid(int, char));',
|
||||||
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
|
def testRemovesCommentsWhenDefaultsArePresent(self):
|
||||||
|
source = """
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
virtual void Bar(int a = 42 /* a comment */,
|
||||||
|
char /* other comment */ c= 'x') = 0;
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
self.assertEqualIgnoreLeadingWhitespace(
|
||||||
|
'MOCK_METHOD2(Bar,\nvoid(int, char));',
|
||||||
|
self.GenerateMethodSource(source))
|
||||||
|
|
||||||
def testDoubleSlashCommentsInParameterListAreRemoved(self):
|
def testDoubleSlashCommentsInParameterListAreRemoved(self):
|
||||||
source = """
|
source = """
|
||||||
class Foo {
|
class Foo {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user