Updates for issue #492:

Prefix and suffix rules would fail if uppercase prefixes/suffixes were used.

  1)  Added tests to expose the issue
  2)  Updated prefix and suffix base rules to allow upper or lower case.
This commit is contained in:
Jeremiah Leary 2020-12-17 12:11:10 -06:00
parent eb31465fb5
commit e4ffbfa047
8 changed files with 65 additions and 5 deletions

View File

@ -38,12 +38,15 @@ class token_prefix(rule.Rule):
return oFile.get_tokens_matching(self.lTokens)
def _analyze(self, lToi):
lPrefixLower = []
for sPrefix in self.prefixes:
lPrefixLower.append(sPrefix.lower())
for oToi in lToi:
lTokens = oToi.get_tokens()
sToken = lTokens[0].get_value().lower()
bValid = False
for sPrefix in self.prefixes:
if sToken.startswith(sPrefix):
for sPrefix in lPrefixLower:
if sToken.startswith(sPrefix.lower()):
bValid = True
if not bValid:
sSolution = 'Prefix ' + lTokens[0].get_value() + ' with one of the following: ' + ', '.join(self.prefixes)

View File

@ -40,11 +40,14 @@ class token_prefix_between_tokens(rule.Rule):
return oFile.get_tokens_matching_in_range_bounded_by_tokens(self.lTokens, self.oStart, self.oEnd)
def _analyze(self, lToi):
lPrefixLower = []
for sPrefix in self.prefixes:
lPrefixLower.append(sPrefix.lower())
for oToi in lToi:
lTokens = oToi.get_tokens()
sToken = lTokens[0].get_value().lower()
bValid = False
for sPrefix in self.prefixes:
for sPrefix in lPrefixLower:
if sToken.startswith(sPrefix):
bValid = True
if not bValid:

View File

@ -37,11 +37,14 @@ class token_suffix(rule.Rule):
return oFile.get_tokens_matching(self.lTokens)
def _analyze(self, lToi):
lSuffixLower = []
for sSuffix in self.suffixes:
lSuffixLower.append(sSuffix.lower())
for oToi in lToi:
lTokens = oToi.get_tokens()
sToken = lTokens[0].get_value().lower()
bValid = False
for sSuffix in self.suffixes:
for sSuffix in lSuffixLower:
if sToken.endswith(sSuffix):
bValid = True
if not bValid:

View File

@ -39,11 +39,14 @@ class token_suffix_between_tokens(rule.Rule):
return oFile.get_tokens_matching_in_range_bounded_by_tokens(self.lTokens, self.oStart, self.oEnd)
def _analyze(self, lToi):
lSuffixLower = []
for sSuffix in self.suffixes:
lSuffixLower.append(sSuffix.lower())
for oToi in lToi:
lTokens = oToi.get_tokens()
sToken = lTokens[0].get_value().lower()
bValid = False
for sSuffix in self.suffixes:
for sSuffix in lSuffixLower:
if sToken.endswith(sSuffix):
bValid = True
if not bValid:

View File

@ -26,3 +26,15 @@ class test_generic_rule(unittest.TestCase):
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_rule_020_w_uppercase(self):
oRule = generic.rule_020()
oRule.prefixes = ['G_']
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'generic')
self.assertEqual(oRule.identifier, '020')
lExpected = [14, 15]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -27,3 +27,15 @@ class test_package_body_rule(unittest.TestCase):
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_rule_600_capitalized(self):
oRule = package_body.rule_600()
oRule.suffixes = ['_PKG']
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'package_body')
self.assertEqual(oRule.identifier, '600')
lExpected = [6, 8]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -26,3 +26,15 @@ class test_port_rule(unittest.TestCase):
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_rule_025_capitalized(self):
oRule = port.rule_025()
oRule.suffixes = ['_I', '_O', '_IO']
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'port')
self.assertEqual(oRule.identifier, '025')
lExpected = [14, 15, 16, 17]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))

View File

@ -26,3 +26,15 @@ class test_subtype_rule(unittest.TestCase):
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_rule_004_capitalized(self):
oRule = subtype.rule_004()
oRule.prefixes = ['ST_']
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'subtype')
self.assertEqual(oRule.identifier, '004')
lExpected = [7, 8, 10, 11]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))