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)
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)
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)
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)
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)
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)
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)
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)
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)
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])
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)