Googletest export

Update auto_mock to support C++17 nested namespaces

PiperOrigin-RevId: 318192214
This commit is contained in:
Abseil Team 2020-06-24 23:00:53 -04:00 committed by Mark Barolak
parent 849ed6b172
commit 05c4a036bb
2 changed files with 7 additions and 8 deletions

View File

@ -1599,12 +1599,11 @@ class AstBuilder(object):
bases, templated_types, body, self.namespace_stack) bases, templated_types, body, self.namespace_stack)
def handle_namespace(self): def handle_namespace(self):
token = self._GetNextToken()
# Support anonymous namespaces. # Support anonymous namespaces.
name = None name = None
if token.token_type == tokenize.NAME: name_tokens, token = self.GetName()
name = token.name if name_tokens:
token = self._GetNextToken() name = ''.join([t.name for t in name_tokens])
self.namespace_stack.append(name) self.namespace_stack.append(name)
assert token.token_type == tokenize.SYNTAX, token assert token.token_type == tokenize.SYNTAX, token
# Create an internal token that denotes when the namespace is complete. # Create an internal token that denotes when the namespace is complete.

View File

@ -361,26 +361,26 @@ class GenerateMocksTest(TestCase):
source = """ source = """
namespace Foo { namespace Foo {
namespace Bar { class Forward; } namespace Bar { class Forward; }
namespace Baz { namespace Baz::Qux {
class Test { class Test {
public: public:
virtual void Foo(); virtual void Foo();
}; };
} // namespace Baz } // namespace Baz::Qux
} // namespace Foo } // namespace Foo
""" """
expected = """\ expected = """\
namespace Foo { namespace Foo {
namespace Baz { namespace Baz::Qux {
class MockTest : public Test { class MockTest : public Test {
public: public:
MOCK_METHOD(void, Foo, (), (override)); MOCK_METHOD(void, Foo, (), (override));
}; };
} // namespace Baz } // namespace Baz::Qux
} // namespace Foo } // namespace Foo
""" """
self.assertEqualIgnoreLeadingWhitespace(expected, self.assertEqualIgnoreLeadingWhitespace(expected,