From 355baf69649446f6c74f3c532e35b8f9ba0ed411 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Thu, 1 Oct 2015 13:51:08 +0100 Subject: [PATCH] Add cpplint unit tests for short lambdas --- cpplint/cpplint_unittest.py | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index aaa3b24..bf9db39 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -3182,6 +3182,54 @@ class CpplintTest(CpplintTestBase): error_collector) cpplint._cpplint_state.verbose_level = old_verbose_level + def testLambdasOnSameLine(self): + error_collector = ErrorCollector(self.assert_) + old_verbose_level = cpplint._cpplint_state.verbose_level + cpplint._cpplint_state.verbose_level = 0 + cpplint.ProcessFileData('foo.cc', 'cc', + ['const auto lambda = ' + '[](const int i) { return i; };'], + error_collector) + cpplint._cpplint_state.verbose_level = old_verbose_level + self.assertEquals(0, error_collector.Results().count( + 'More than one command on the same line [whitespace/newline] [0]')) + + error_collector = ErrorCollector(self.assert_) + old_verbose_level = cpplint._cpplint_state.verbose_level + cpplint._cpplint_state.verbose_level = 0 + cpplint.ProcessFileData('foo.cc', 'cc', + ['const auto result = std::any_of(vector.begin(), ' + 'vector.end(), ' + '[](const int i) { return i > 0; });'], + error_collector) + cpplint._cpplint_state.verbose_level = old_verbose_level + self.assertEquals(0, error_collector.Results().count( + 'More than one command on the same line [whitespace/newline] [0]')) + + error_collector = ErrorCollector(self.assert_) + old_verbose_level = cpplint._cpplint_state.verbose_level + cpplint._cpplint_state.verbose_level = 0 + cpplint.ProcessFileData('foo.cc', 'cc', + ['return mutex::Lock([this]() { ' + 'this->ReadLock(); }, [this]() { ' + 'this->ReadUnlock(); });'], + error_collector) + cpplint._cpplint_state.verbose_level = old_verbose_level + self.assertEquals(0, error_collector.Results().count( + 'More than one command on the same line [whitespace/newline] [0]')) + + error_collector = ErrorCollector(self.assert_) + old_verbose_level = cpplint._cpplint_state.verbose_level + cpplint._cpplint_state.verbose_level = 0 + cpplint.ProcessFileData('foo.cc', 'cc', + ['return mutex::Lock([this]() { ' + 'this->ReadLock(); }, [this]() { ' + 'this->ReadUnlock(); }, object);'], + error_collector) + cpplint._cpplint_state.verbose_level = old_verbose_level + self.assertEquals(0, error_collector.Results().count( + 'More than one command on the same line [whitespace/newline] [0]')) + def testEndOfNamespaceComments(self): error_collector = ErrorCollector(self.assert_) cpplint.ProcessFileData('foo.cc', 'cc',