Browse Source

reset indent after port map

master
g2384 3 years ago
parent
commit
9007716393
4 changed files with 117 additions and 19 deletions
  1. +8
    -0
      VHDLFormatter.js
  2. +8
    -0
      VHDLFormatter.ts
  3. +101
    -0
      tests/VHDLFormatter.test.ts
  4. +0
    -19
      tests/VHDLFormatterUnitTests.ts

+ 8
- 0
VHDLFormatter.js View File

@ -817,7 +817,15 @@ function beautify3(block, result, settings, indent) {
continue; continue;
} }
if (input.regexStartsWith(/[\w\s:]*\bPORT\b([\s]|$)/)) { if (input.regexStartsWith(/[\w\s:]*\bPORT\b([\s]|$)/)) {
var preCursor = block.cursor;
beautifyPortGenericBlock(block, result, settings, indent, "PORT"); beautifyPortGenericBlock(block, result, settings, indent, "PORT");
var preLine = preCursor - 1;
if (preLine >= 0) {
var preL = block.lines[preLine];
if (preL.regexIndexOf(/:\s+(COMPONENT|ENTITY)/) >= 0) {
indent--;
}
}
continue; continue;
} }
if (input.regexStartsWith(/TYPE\s+\w+\s+IS\s+\(/)) { if (input.regexStartsWith(/TYPE\s+\w+\s+IS\s+\(/)) {


+ 8
- 0
VHDLFormatter.ts View File

@ -899,7 +899,15 @@ export function beautify3(block: CodeBlock, result: (FormattedLine | FormattedLi
continue; continue;
} }
if (input.regexStartsWith(/[\w\s:]*\bPORT\b([\s]|$)/)) { if (input.regexStartsWith(/[\w\s:]*\bPORT\b([\s]|$)/)) {
var preCursor = block.cursor;
beautifyPortGenericBlock(block, result, settings, indent, "PORT"); beautifyPortGenericBlock(block, result, settings, indent, "PORT");
var preLine = preCursor - 1;
if (preLine >= 0) {
var preL = block.lines[preLine];
if (preL.regexIndexOf(/:\s+(COMPONENT|ENTITY)/) >= 0) {
indent--;
}
}
continue; continue;
} }
if (input.regexStartsWith(/TYPE\s+\w+\s+IS\s+\(/)) { if (input.regexStartsWith(/TYPE\s+\w+\s+IS\s+\(/)) {


+ 101
- 0
tests/VHDLFormatter.test.ts View File

@ -211,6 +211,107 @@ describe('VHDLFormatter', function () {
let result = beautifyTestHelper(input, settings); let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output); expect(result).toStrictEqual(output);
}) })
it('indent PORT map', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = [
"test_iobuf : component IOBUF",
"port map(",
" I => '0',",
" T => '0'",
");",
"test_iobuf : component IOBUF",
" port map(",
" I => '0',",
" T => '0'",
");"
];
let output = [
"test_iobuf : COMPONENT IOBUF",
" PORT MAP(",
" I => '0',",
" T => '0'",
" );",
"test_iobuf : COMPONENT IOBUF",
" PORT MAP(",
" I => '0',",
" T => '0'",
" );"
];
let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output);
})
it('indent PORT map (2)', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = [
"i_Mux1 : entity work.T15_Mux(rtl) port map(",
" Sel => Sel,",
"Sig1 => Sig1,",
"Output => Output);",
"",
"-- Testbench process",
"process is",
"begin",
"wait for 10 ns;",
"Sel <= Sel + 1;",
"wait for 10 ns;",
"Sel <= \"UU\";",
"wait;",
"end process;"
];
let output = [
"i_Mux1 : ENTITY work.T15_Mux(rtl) PORT MAP(",
" Sel => Sel,",
" Sig1 => Sig1,",
" Output => Output);",
"",
"-- Testbench process",
"PROCESS IS",
"BEGIN",
" WAIT FOR 10 ns;",
" Sel <= Sel + 1;",
" WAIT FOR 10 ns;",
" Sel <= \"UU\";",
" WAIT;",
"END PROCESS;"
];
let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output);
});
it('multiline assignment', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = [
"test",
" := test"
];
let output = [
"test",
" := test" // is this desired?
];
let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output);
});
it('align <= => signs', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = [
"a <= (b => '000'); -- test",
"looong <= (others => '0'); -- test"
];
let output = [
"a <= (b => '000'); -- test",
"looong <= (OTHERS => '0'); -- test" // does comment need to be aligned?
];
let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output);
});
}); });
function beautifyTestHelper(array: Array<string>, settings: BeautifierSettings): Array<string> { function beautifyTestHelper(array: Array<string>, settings: BeautifierSettings): Array<string> {


+ 0
- 19
tests/VHDLFormatterUnitTests.ts View File

@ -933,12 +933,10 @@ function IntegrationTest() {
IntegrationTest67(); IntegrationTest67();
IntegrationTest68(); IntegrationTest68();
IntegrationTest69(); IntegrationTest69();
IntegrationTest70();
IntegrationTest71(); IntegrationTest71();
IntegrationTest72(); IntegrationTest72();
IntegrationTest73(); IntegrationTest73();
IntegrationTest74(); IntegrationTest74();
IntegrationTest76();
IntegrationTest77(); IntegrationTest77();
IntegrationTest78(); IntegrationTest78();
IntegrationTest79(); IntegrationTest79();
@ -1318,14 +1316,6 @@ function IntegrationTest69() {
assertAndCountTest("multiline enumerated type is", expected, actual); assertAndCountTest("multiline enumerated type is", expected, actual);
} }
function IntegrationTest70() {
let settings = GetDefaultSettings();
let input = 'test\r\n := test';
let expected = 'test\r\n:= test';
let actual = beautify(input, settings);
assertAndCountTest("multiline assignment", expected, actual);
}
function IntegrationTest71() { function IntegrationTest71() {
let settings = GetDefaultSettings(); let settings = GetDefaultSettings();
let input = 'VARIABLE \\#$)!?\\ : INTEGER;\r\nVARIABLE \\try this in verilog\\ : BIT;\r\nVARIABLE \\Buffer\\ : BIT;'; let input = 'VARIABLE \\#$)!?\\ : INTEGER;\r\nVARIABLE \\try this in verilog\\ : BIT;\r\nVARIABLE \\Buffer\\ : BIT;';
@ -1359,15 +1349,6 @@ function IntegrationTest74() {
assertAndCountTest("end of line 2", expected, actual); assertAndCountTest("end of line 2", expected, actual);
} }
function IntegrationTest76() {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", []);
let input = "a <= (b => '000'); -- test\r\nlooong <= (others => '0'); -- test";
let expected = "a <= (b => '000'); -- test\r\nlooong <= (OTHERS => '0'); -- test";
let actual = beautify(input, settings);
assertAndCountTest("align <= => signs", expected, actual);
}
function IntegrationTest77() { function IntegrationTest77() {
let settings = GetDefaultSettings(); let settings = GetDefaultSettings();
let input = "WHEN -2;\r\nSIGNAL +0;"; let input = "WHEN -2;\r\nSIGNAL +0;";


Loading…
Cancel
Save