243 lines
8.4 KiB
Python
243 lines
8.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import unittest
|
|
|
|
from tests import utils
|
|
from vsg import vhdlFile
|
|
from vsg.rules import generate
|
|
|
|
sTestDir = os.path.dirname(__file__)
|
|
|
|
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_400_test_input.vhd"))
|
|
|
|
|
|
class test_generate_rule(unittest.TestCase):
|
|
def setUp(self):
|
|
self.oFile = vhdlFile.vhdlFile(lFile)
|
|
self.assertIsNone(eError)
|
|
|
|
###############################################################################
|
|
def test_rule_400_yes_yes_yes_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "yes"
|
|
oRule.blank_line_ends_group = "yes"
|
|
oRule.comment_line_ends_group = "yes"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 11, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_rule_400_true_true_true_false_false(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = True
|
|
oRule.blank_line_ends_group = True
|
|
oRule.comment_line_ends_group = True
|
|
oRule.if_control_statements_ends_group = False
|
|
oRule.case_control_statements_ends_group = False
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 11, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_fix_rule_400_yes_yes_yes_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "yes"
|
|
oRule.blank_line_ends_group = "yes"
|
|
oRule.comment_line_ends_group = "yes"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
oRule.fix(self.oFile)
|
|
|
|
lExpected = []
|
|
lExpected.append("")
|
|
utils.read_file(os.path.join(sTestDir, "rule_400_test_input.fixed_yes_yes_yes_no_no.vhd"), lExpected)
|
|
|
|
lActual = self.oFile.get_lines()
|
|
|
|
self.assertEqual(lExpected, lActual)
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(oRule.violations, [])
|
|
|
|
###############################################################################
|
|
def test_rule_400_yes_yes_no_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "yes"
|
|
oRule.blank_line_ends_group = "yes"
|
|
oRule.comment_line_ends_group = "no"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 11, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_rule_400_true_true_false_false_false(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = True
|
|
oRule.blank_line_ends_group = True
|
|
oRule.comment_line_ends_group = False
|
|
oRule.if_control_statements_ends_group = False
|
|
oRule.case_control_statements_ends_group = False
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 11, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_fix_rule_400_yes_yes_no_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "yes"
|
|
oRule.blank_line_ends_group = "yes"
|
|
oRule.comment_line_ends_group = "no"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
oRule.fix(self.oFile)
|
|
|
|
lExpected = []
|
|
lExpected.append("")
|
|
utils.read_file(os.path.join(sTestDir, "rule_400_test_input.fixed_yes_yes_no_no_no.vhd"), lExpected)
|
|
|
|
lActual = self.oFile.get_lines()
|
|
|
|
self.assertEqual(lExpected, lActual)
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(oRule.violations, [])
|
|
|
|
###############################################################################
|
|
def test_rule_400_yes_no_no_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "yes"
|
|
oRule.blank_line_ends_group = "no"
|
|
oRule.comment_line_ends_group = "no"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 11, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_rule_400_true_false_false_false_false(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = True
|
|
oRule.blank_line_ends_group = False
|
|
oRule.comment_line_ends_group = False
|
|
oRule.if_control_statements_ends_group = False
|
|
oRule.case_control_statements_ends_group = False
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 11, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_fix_rule_400_yes_no_no_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "yes"
|
|
oRule.blank_line_ends_group = "no"
|
|
oRule.comment_line_ends_group = "no"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
oRule.fix(self.oFile)
|
|
|
|
lExpected = []
|
|
lExpected.append("")
|
|
utils.read_file(os.path.join(sTestDir, "rule_400_test_input.fixed_yes_no_no_no_no.vhd"), lExpected)
|
|
|
|
lActual = self.oFile.get_lines()
|
|
|
|
self.assertEqual(lExpected, lActual)
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(oRule.violations, [])
|
|
|
|
###############################################################################
|
|
def test_rule_400_no_no_no_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "no"
|
|
oRule.blank_line_ends_group = "no"
|
|
oRule.comment_line_ends_group = "no"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_rule_400_false_false_false_false_false(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = False
|
|
oRule.blank_line_ends_group = False
|
|
oRule.comment_line_ends_group = False
|
|
oRule.if_control_statements_ends_group = False
|
|
oRule.case_control_statements_ends_group = False
|
|
|
|
self.assertTrue(oRule)
|
|
self.assertEqual(oRule.name, "generate")
|
|
self.assertEqual(oRule.identifier, "400")
|
|
|
|
lExpected = [8, 9, 12, 14]
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
|
|
|
def test_fix_rule_400_no_no_no_no_no(self):
|
|
oRule = generate.rule_400()
|
|
oRule.compact_alignment = "no"
|
|
oRule.blank_line_ends_group = "no"
|
|
oRule.comment_line_ends_group = "no"
|
|
oRule.if_control_statements_ends_group = "no"
|
|
oRule.case_control_statements_ends_group = "no"
|
|
|
|
oRule.fix(self.oFile)
|
|
|
|
lExpected = []
|
|
lExpected.append("")
|
|
utils.read_file(os.path.join(sTestDir, "rule_400_test_input.fixed_no_no_no_no_no.vhd"), lExpected)
|
|
|
|
lActual = self.oFile.get_lines()
|
|
|
|
self.assertEqual(lExpected, lActual)
|
|
|
|
oRule.analyze(self.oFile)
|
|
self.assertEqual(oRule.violations, [])
|