Exemplo n.º 1
0
 def test_methods(self):
     # given
     config = {'naming': {'methods': '^([a-z0-9]+)([A-Z][a-z0-9]*)*$'}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = ["[Line 8, Col 8]: Method 'foo_method' does not match '^([a-z0-9]+)([A-Z][a-z0-9]*)*$'"]
     self.assertEqual([str(r) for r in result],asserted)
Exemplo n.º 2
0
 def test_struct(self):
     # given
     config = {'indent': {'struct': 2}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 9, Col 8]: Indent is wrong, should be '6', not '8'"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 3
0
 def test_method(self):
     # given
     config = {'indent': {'method': 2}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 14, Col 6]: Indent is wrong, should be '4', not '6'"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 4
0
 def test_function(self):
     # given
     config = {'indent': {'function': 2}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 3, Col 4]: Indent is wrong, should be '2', not '4'"
     # self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 5
0
 def test_functions(self):
     # given
     config = {'naming': {'functions': '^([a-z0-9]+)([A-Z][a-z0-9]*)*$'}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 19, Col 0]: Function 'foo_function' does not match '^([a-z0-9]+)([A-Z][a-z0-9]*)*$'"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 6
0
 def test_public_field(self):
     # given
     config = {'naming': {'members': {'public': '^([a-z0-9]+)(_[a-z0-9]+)*$'}}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 7, Col 8]: Field 'myPublicString' does not match '^([a-z0-9]+)(_[a-z0-9]+)*$'"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 7
0
 def test_variables(self):
     # given
     config = {'naming': {'variables': '^([a-z0-9]+)(_[a-z0-9]+)*$'}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 15, Col 2]: Variable 'wrongName' does not match '^([a-z0-9]+)(_[a-z0-9]+)*$'"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 8
0
 def test_classes(self):
     # given
     config = {'naming': {'classes': '^([A-Z][a-z0-9]*)+$'}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = "[Line 1, Col 0]: Class 'foo' does not match '^([A-Z][a-z0-9]*)+$'"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), asserted)
Exemplo n.º 9
0
 def test_force_access_specifier(self):
     # given
     root = self.source
     config = {'order': {'access_specifier_required': True}}
     # when
     result = check.check(self.file, root, config)
     # then
     expected = "[Line 5, Col 8]: Class 'Bar' should have an access specifier at first."
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), expected)
Exemplo n.º 10
0
 def test_class(self):
     # given
     config = {'indent': {'class': {'access_specifier': 0, 'default': 2}}}
     # when
     result = check.check(self.file, self.source, config)
     # then
     asserted = [
         "[Line 7, Col 1]: Indent is wrong, should be '0', not '1'",
         "[Line 8, Col 4]: Indent is wrong, should be '2', not '4'"
     ]
     self.assertEqual(len(result), 2)
     self.assertEqual(asserted, [str(r) for r in result])
Exemplo n.º 11
0
 def test_check_order(self):
     # given
     root = self.source
     config = {
         'order': {
             'access_specifier': ['public', 'protected', 'private']
         }
     }
     # when
     result = check.check(self.file, root, config)
     # then
     expected = "[Line 1, Col 0]: Class 'Foo' has wrong access specifier order: ['protected', 'public', 'private'], should be ['public', 'protected', 'private']"
     self.assertEqual(len(result), 1)
     self.assertEqual(str(result[0]), expected)