Browse Source

use system EOL symbol or user-specified

master
g2384 5 years ago
parent
commit
3326575be0
7 changed files with 142 additions and 155 deletions
  1. +3
    -0
      README.md
  2. +4
    -3
      VHDLFormatter.js
  3. +5
    -2
      VHDLFormatter.ts
  4. +11
    -3
      descriptiveCounter.js
  5. +12
    -4
      descriptiveCounter.ts
  6. +32
    -19
      index.html
  7. +75
    -124
      tests/VHDLFormatterUnitTests.ts

+ 3
- 0
README.md View File

@ -12,6 +12,9 @@ VHDL formatter web online written in javascript
- add `tests` folder, improve the project management - add `tests` folder, improve the project management
- support extended identifier (backslash names) - support extended identifier (backslash names)
- fix exponential notation - fix exponential notation
- user can choose EOL symbols (or use system's by default)
Many thanks to @MihaiBabiac
### 2.2 [2018-10-16] ### 2.2 [2018-10-16]


+ 4
- 3
VHDLFormatter.js View File

@ -229,7 +229,7 @@ function SetNewLinesAfterSymbols(text, newLineSettings) {
} }
exports.SetNewLinesAfterSymbols = SetNewLinesAfterSymbols; exports.SetNewLinesAfterSymbols = SetNewLinesAfterSymbols;
class BeautifierSettings { class BeautifierSettings {
constructor(removeComments, removeReport, checkAlias, signAlign, signAlignAll, keywordCase, indentation, newLineSettings) {
constructor(removeComments, removeReport, checkAlias, signAlign, signAlignAll, keywordCase, indentation, newLineSettings, endOfLine) {
this.RemoveComments = removeComments; this.RemoveComments = removeComments;
this.RemoveAsserts = removeReport; this.RemoveAsserts = removeReport;
this.CheckAlias = checkAlias; this.CheckAlias = checkAlias;
@ -238,6 +238,7 @@ class BeautifierSettings {
this.KeywordCase = keywordCase; this.KeywordCase = keywordCase;
this.Indentation = indentation; this.Indentation = indentation;
this.NewLineSettings = newLineSettings; this.NewLineSettings = newLineSettings;
this.EndOfLine = endOfLine;
} }
} }
exports.BeautifierSettings = BeautifierSettings; exports.BeautifierSettings = BeautifierSettings;
@ -280,8 +281,7 @@ function beautify(input, settings) {
input = arr.join("\r\n"); input = arr.join("\r\n");
input = input.replace(/([a-zA-Z0-9\); ])\);(@@comments[0-9]+)?@@end/g, '$1\r\n);$2@@end'); input = input.replace(/([a-zA-Z0-9\); ])\);(@@comments[0-9]+)?@@end/g, '$1\r\n);$2@@end');
input = input.replace(/[ ]?([&=:\-<>\+|\*])[ ]?/g, ' $1 '); input = input.replace(/[ ]?([&=:\-<>\+|\*])[ ]?/g, ' $1 ');
// Fix reals in expoential format broken by previous step
input = input.replace(/(\d+e) +([+\-]) +(\d+)/g, '$1$2$3');
input = input.replace(/(\d+e) +([+\-]) +(\d+)/g, '$1$2$3'); // Fix exponential notation format broken by previous step
input = input.replace(/[ ]?([,])[ ]?/g, '$1 '); input = input.replace(/[ ]?([,])[ ]?/g, '$1 ');
input = input.replace(/[ ]?(['"])(THEN)/g, '$1 $2'); input = input.replace(/[ ]?(['"])(THEN)/g, '$1 $2');
input = input.replace(/[ ]?(\?)?[ ]?(<|:|>|\/)?[ ]+(=)?[ ]?/g, ' $1$2$3 '); input = input.replace(/[ ]?(\?)?[ ]?(<|:|>|\/)?[ ]+(=)?[ ]?/g, ' $1$2$3 ');
@ -311,6 +311,7 @@ function beautify(input, settings) {
input = replaceEscapedWords(input, backslashes, ILBackslashesPrefix); input = replaceEscapedWords(input, backslashes, ILBackslashesPrefix);
input = input.replace(/@@semicolon/g, ";"); input = input.replace(/@@semicolon/g, ";");
input = input.replace(/@@[a-z]+/g, ""); input = input.replace(/@@[a-z]+/g, "");
input = input.replace(/\r\n/g, settings.EndOfLine);
return input; return input;
} }
exports.beautify = beautify; exports.beautify = beautify;


+ 5
- 2
VHDLFormatter.ts View File

@ -277,10 +277,11 @@ export class BeautifierSettings {
SignAlignKeyWords: Array<string>; SignAlignKeyWords: Array<string>;
KeywordCase: string; KeywordCase: string;
Indentation: string; Indentation: string;
NewLineSettings: NewLineSettings
NewLineSettings: NewLineSettings;
EndOfLine: string;
constructor(removeComments: boolean, removeReport: boolean, checkAlias: boolean, constructor(removeComments: boolean, removeReport: boolean, checkAlias: boolean,
signAlign: boolean, signAlignAll: boolean, keywordCase: string, indentation: string, signAlign: boolean, signAlignAll: boolean, keywordCase: string, indentation: string,
newLineSettings: NewLineSettings) {
newLineSettings: NewLineSettings, endOfLine: string) {
this.RemoveComments = removeComments; this.RemoveComments = removeComments;
this.RemoveAsserts = removeReport; this.RemoveAsserts = removeReport;
this.CheckAlias = checkAlias; this.CheckAlias = checkAlias;
@ -289,6 +290,7 @@ export class BeautifierSettings {
this.KeywordCase = keywordCase; this.KeywordCase = keywordCase;
this.Indentation = indentation; this.Indentation = indentation;
this.NewLineSettings = newLineSettings; this.NewLineSettings = newLineSettings;
this.EndOfLine = endOfLine;
} }
} }
@ -371,6 +373,7 @@ export function beautify(input: string, settings: BeautifierSettings) {
input = input.replace(/@@semicolon/g, ";"); input = input.replace(/@@semicolon/g, ";");
input = input.replace(/@@[a-z]+/g, ""); input = input.replace(/@@[a-z]+/g, "");
input = input.replace(/\r\n/g, settings.EndOfLine);
return input; return input;
} }


+ 11
- 3
descriptiveCounter.js View File

@ -1,12 +1,14 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
function indent_decode() {
var custom_indent = document.getElementById("cust_indent").value;
function counterDecode(inputId, outputId) {
var custom_indent = document.getElementById(inputId).value;
var result = descriptiveCounter(custom_indent); var result = descriptiveCounter(custom_indent);
document.getElementById("indent_s").innerHTML = result;
document.getElementById(outputId).innerHTML = result;
} }
function descriptiveCounter(input) { function descriptiveCounter(input) {
input = input.replace(/\\t/g, " "); input = input.replace(/\\t/g, " ");
input = input.replace(/\\r/g, "\r");
input = input.replace(/\\n/g, "\n");
var tokens = input.split(""); var tokens = input.split("");
var result = ""; var result = "";
var repeatedCharCount = 0; var repeatedCharCount = 0;
@ -23,6 +25,12 @@ function descriptiveCounter(input) {
case "\t": case "\t":
char = "tab"; char = "tab";
break; break;
case "\n":
char = "\\n";
break;
case "\r":
char = "\\r";
break;
default: default:
char = "'" + char + "'"; char = "'" + char + "'";
} }


+ 12
- 4
descriptiveCounter.ts View File

@ -1,12 +1,14 @@
function indent_decode() {
var custom_indent: string = (<HTMLInputElement>document.getElementById("cust_indent")).value;
function counterDecode(inputId: string, outputId: string) {
var custom_indent: string = (<HTMLInputElement>document.getElementById(inputId)).value;
var result: string = descriptiveCounter(custom_indent); var result: string = descriptiveCounter(custom_indent);
document.getElementById("indent_s").innerHTML = result;
document.getElementById(outputId).innerHTML = result;
} }
export function descriptiveCounter(input: string): string { export function descriptiveCounter(input: string): string {
input = input.replace(/\\t/g, " "); input = input.replace(/\\t/g, " ");
input = input.replace(/\\r/g, "\r");
input = input.replace(/\\n/g, "\n");
var tokens: Array<string> = input.split(""); var tokens: Array<string> = input.split("");
var result = ""; var result = "";
var repeatedCharCount = 0; var repeatedCharCount = 0;
@ -22,6 +24,12 @@ export function descriptiveCounter(input: string): string {
case "\t": case "\t":
char = "tab"; char = "tab";
break; break;
case "\n":
char = "\\n";
break;
case "\r":
char = "\\r";
break;
default: default:
char = "'" + char + "'"; char = "'" + char + "'";
} }


+ 32
- 19
index.html View File

@ -253,47 +253,47 @@
<form id="new_line_after_then"> <form id="new_line_after_then">
<span class="code">THEN</span> <span class="code">THEN</span>
<label> <label>
<input type="radio" name="new_line_after_thencase" value="NewLine" checked="checked">New Line</label>
<input type="radio" name="new_line_after_thencase" value="NewLine" checked="checked">New Line</label>
<label> <label>
<input type="radio" name="new_line_after_thencase" value="NoNewLine">No New Line</label>
<input type="radio" name="new_line_after_thencase" value="NoNewLine">No New Line</label>
<label> <label>
<input type="radio" name="new_line_after_thencase" value="None">None</label>
<input type="radio" name="new_line_after_thencase" value="None">None</label>
</form> </form>
<form id="new_line_after_semicolon"> <form id="new_line_after_semicolon">
<span class="code">semicolon ";"</span> <span class="code">semicolon ";"</span>
<label> <label>
<input type="radio" name="new_line_after_semicoloncase" value="NewLine" checked="checked">New Line</label>
<input type="radio" name="new_line_after_semicoloncase" value="NewLine" checked="checked">New Line</label>
<label> <label>
<input type="radio" name="new_line_after_semicoloncase" value="NoNewLine">No New Line</label>
<input type="radio" name="new_line_after_semicoloncase" value="NoNewLine">No New Line</label>
<label> <label>
<input type="radio" name="new_line_after_semicoloncase" value="None">None</label>
<input type="radio" name="new_line_after_semicoloncase" value="None">None</label>
</form> </form>
<form id="new_line_after_else"> <form id="new_line_after_else">
<span class="code">ELSE</span> <span class="code">ELSE</span>
<label> <label>
<input type="radio" name="new_line_after_elsecase" value="NewLine">New Line</label>
<input type="radio" name="new_line_after_elsecase" value="NewLine">New Line</label>
<label> <label>
<input type="radio" name="new_line_after_elsecase" value="NoNewLine">No New Line</label>
<input type="radio" name="new_line_after_elsecase" value="NoNewLine">No New Line</label>
<label> <label>
<input type="radio" name="new_line_after_elsecase" value="None" checked="checked">None</label>
<input type="radio" name="new_line_after_elsecase" value="None" checked="checked">None</label>
</form> </form>
<form id="new_line_after_port"> <form id="new_line_after_port">
<span class="code">PORT | PORT MAP</span> <span class="code">PORT | PORT MAP</span>
<label> <label>
<input type="radio" name="new_line_after_portcase" value="NewLine">New Line</label>
<input type="radio" name="new_line_after_portcase" value="NewLine">New Line</label>
<label> <label>
<input type="radio" name="new_line_after_portcase" value="NoNewLine">No New Line</label>
<input type="radio" name="new_line_after_portcase" value="NoNewLine">No New Line</label>
<label> <label>
<input type="radio" name="new_line_after_portcase" value="None" checked="checked">None</label>
<input type="radio" name="new_line_after_portcase" value="None" checked="checked">None</label>
</form> </form>
<form id="new_line_after_generic"> <form id="new_line_after_generic">
<span class="code">GENERIC</span> <span class="code">GENERIC</span>
<label> <label>
<input type="radio" name="new_line_after_genericcase" value="NewLine">New Line</label>
<input type="radio" name="new_line_after_genericcase" value="NewLine">New Line</label>
<label> <label>
<input type="radio" name="new_line_after_genericcase" value="NoNewLine">No New Line</label>
<input type="radio" name="new_line_after_genericcase" value="NoNewLine">No New Line</label>
<label> <label>
<input type="radio" name="new_line_after_genericcase" value="None" checked="checked">None</label>
<input type="radio" name="new_line_after_genericcase" value="None" checked="checked">None</label>
</form> </form>
</fieldset> </fieldset>
<div class="checkbox inline" id="remove_comments_div"> <div class="checkbox inline" id="remove_comments_div">
@ -340,7 +340,7 @@
<input type="checkbox" id="use_space"> <input type="checkbox" id="use_space">
<label for="use_space">Customise Indentation: </label> <label for="use_space">Customise Indentation: </label>
</div>(tab is \t) </div>(tab is \t)
<input type="text" id="cust_indent" size="8" onKeyUp="indent_decode()" value=" " /> (
<input type="text" id="cust_indent" size="8" onKeyUp="counterDecode('cust_indent', 'indent_s')" value=" " /> (
<span id="indent_s">four blankspaces</span>) <span id="indent_s">four blankspaces</span>)
</div> </div>
<div class="checkbox" id="compress_div"> <div class="checkbox" id="compress_div">
@ -351,10 +351,14 @@
<input type="checkbox" id="mix_letter"> <input type="checkbox" id="mix_letter">
<label for="mix_letter">! EVIL - unreadable (mix upper/lower-case letters)</label> <label for="mix_letter">! EVIL - unreadable (mix upper/lower-case letters)</label>
</div> </div>
<div>
End of line:
<input type="text" id="cust_eol" size="8" onKeyUp="counterDecode('cust_eol', 'eol_s')" value="\r\n" /> (
<span id="eol_s">one \r & one \n</span>)
</div>
<input type="button" class="btn" onclick="f()" value="start" /> <input type="button" class="btn" onclick="f()" value="start" />
<span class="show"> <span class="show">
<input type="button" class="btn " id="selectAll" value="Select All" onclick="selectText(document.getElementById('vhdl'))"
/>
<input type="button" class="btn " id="selectAll" value="Select All" onclick="selectText(document.getElementById('vhdl'))" />
<div class="checkbox inline"> <div class="checkbox inline">
<input type="checkbox" onclick="wordWrap()" id="word_wrap"> <input type="checkbox" onclick="wordWrap()" id="word_wrap">
<label for="word_wrap">Word wrap</label> <label for="word_wrap">Word wrap</label>
@ -417,6 +421,9 @@
<script src="VHDLFormatter.js"></script> <script src="VHDLFormatter.js"></script>
<script src="descriptiveCounter.js"></script> <script src="descriptiveCounter.js"></script>
<script> <script>
let global_endOfLine = navigator.platform === 'Win32' ? '\\r\\n' : '\\n';
document.getElementById("cust_eol").value = global_endOfLine;
function f() { function f() {
var input = document.getElementById("in").value; var input = document.getElementById("in").value;
var no_format = document.getElementById("no_format").checked; var no_format = document.getElementById("no_format").checked;
@ -445,6 +452,9 @@
var cust_indent = document.getElementById("cust_indent").value; var cust_indent = document.getElementById("cust_indent").value;
var keywordcase = document.getElementById("keyword").elements.namedItem("keywordcase").value; var keywordcase = document.getElementById("keyword").elements.namedItem("keywordcase").value;
var mix_letter = document.getElementById("mix_letter").checked; var mix_letter = document.getElementById("mix_letter").checked;
var endOfLine = document.getElementById("cust_eol").value;
endOfLine = endOfLine.replace(/\\r/g, "\r");
endOfLine = endOfLine.replace(/\\n/g, "\n");
if (compress) { if (compress) {
remove_comments = true; remove_comments = true;
} }
@ -482,7 +492,10 @@
beautifierSettings = new BeautifierSettings(remove_comments, remove_report, check_alias, sign_align, beautifierSettings = new BeautifierSettings(remove_comments, remove_report, check_alias, sign_align,
sign_align_all, sign_align_all,
keywordcase, indentation, newLineSettings);
keywordcase,
indentation,
newLineSettings,
endOfLine);
beautifierSettings.SignAlignKeyWords = signAlignKeywords; beautifierSettings.SignAlignKeyWords = signAlignKeywords;
input = beautify(input, beautifierSettings); input = beautify(input, beautifierSettings);


+ 75
- 124
tests/VHDLFormatterUnitTests.ts View File

@ -9,7 +9,7 @@ import { FormattedLine } from "../VHDLFormatter";
import { FormattedLineToString } from "../VHDLFormatter"; import { FormattedLineToString } from "../VHDLFormatter";
import { CompareString } from "./assert"; import { CompareString } from "./assert";
import { assert } from "./assert"; import { assert } from "./assert";
import {testDescriptiveCounter} from "./descriptiveCounterTests";
import { testDescriptiveCounter } from "./descriptiveCounterTests";
let testCount: number = 0; let testCount: number = 0;
@ -82,7 +82,7 @@ function Beautify3Case1() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = ["a;", "b;"]; let inputs: Array<string> = ["a;", "b;"];
let expected: (FormattedLine | FormattedLine[])[] = [new FormattedLine("a;", 0), new FormattedLine("b;", 0)]; let expected: (FormattedLine | FormattedLine[])[] = [new FormattedLine("a;", 0), new FormattedLine("b;", 0)];
UnitTest6(beautify3, "General", settings, inputs, expected, 0, 1, 0); UnitTest6(beautify3, "General", settings, inputs, expected, 0, 1, 0);
@ -92,7 +92,7 @@ function Beautify3Case2() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = ["IF x = '1' THEN", "RETURN 1;", "END IF;"]; let inputs: Array<string> = ["IF x = '1' THEN", "RETURN 1;", "END IF;"];
let expected: (FormattedLine | FormattedLine[])[] = [ let expected: (FormattedLine | FormattedLine[])[] = [
new FormattedLine("IF x = '1' THEN", 0), new FormattedLine("IF x = '1' THEN", 0),
@ -106,7 +106,7 @@ function Beautify3Case3() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"IF x = '1' THEN", "IF x = '1' THEN",
"RETURN 1;", "RETURN 1;",
@ -131,7 +131,7 @@ function Beautify3Case4() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = ["END"]; let inputs: Array<string> = ["END"];
let expected: (FormattedLine | FormattedLine[])[] = [new FormattedLine("END", 0)]; let expected: (FormattedLine | FormattedLine[])[] = [new FormattedLine("END", 0)];
UnitTest6(beautify3, "one line END", settings, inputs, expected, 0, 0, 0); UnitTest6(beautify3, "one line END", settings, inputs, expected, 0, 0, 0);
@ -141,7 +141,7 @@ function Beautify3Case5() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"CASE b", "CASE b",
"WHEN 1 =>", "WHEN 1 =>",
@ -165,7 +165,7 @@ function Beautify3Case6() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"CASE b", "CASE b",
"WHEN 1 =>", "WHEN 1 =>",
@ -201,7 +201,7 @@ function Beautify3Case7() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"ARCHITECTURE a OF one IS", "ARCHITECTURE a OF one IS",
"SIGNAL x : INTEGER;", "SIGNAL x : INTEGER;",
@ -223,7 +223,7 @@ function Beautify3Case8() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"ARCHITECTURE a OF one IS", "ARCHITECTURE a OF one IS",
"SIGNAL x : INTEGER;", "SIGNAL x : INTEGER;",
@ -255,7 +255,7 @@ function Beautify3Case9() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS", "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS",
"VARIABLE i : INTEGER;", "VARIABLE i : INTEGER;",
@ -277,7 +277,7 @@ function Beautify3Case10() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"PACKAGE three IS", "PACKAGE three IS",
"SIGNAL s : INTEGER;", "SIGNAL s : INTEGER;",
@ -297,7 +297,7 @@ function Beautify3Case11() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"PACKAGE p IS", "PACKAGE p IS",
"PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER);", "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER);",
@ -349,7 +349,7 @@ function Beautify3Case12() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"ARCHITECTURE a OF b IS", "ARCHITECTURE a OF b IS",
"SIGNAL x : INTEGER := 0;", "SIGNAL x : INTEGER := 0;",
@ -401,7 +401,7 @@ function Beautify3Case13() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"TYPE SharedCounter IS PROTECTED", "TYPE SharedCounter IS PROTECTED",
"PROCEDURE increment (N : INTEGER := 1);", "PROCEDURE increment (N : INTEGER := 1);",
@ -421,7 +421,7 @@ function Beautify3Case14() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"PACKAGE p IS", "PACKAGE p IS",
"TYPE SharedCounter IS PROTECTED", "TYPE SharedCounter IS PROTECTED",
@ -445,7 +445,7 @@ function Beautify3Case15() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"constant a : integer := 2#1101#", "constant a : integer := 2#1101#",
"constant b : integer := 3#20#;", "constant b : integer := 3#20#;",
@ -463,7 +463,7 @@ function Beautify3Case16() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"x <= 1 WHEN foo", "x <= 1 WHEN foo",
"ELSE 2 WHEN bar", "ELSE 2 WHEN bar",
@ -483,7 +483,7 @@ function Beautify3Case17() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"WITH y SELECT x <=", "WITH y SELECT x <=",
"1 WHEN a,", "1 WHEN a,",
@ -505,7 +505,7 @@ function Beautify3Case18() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"CONFIGURATION conf OF ent IS", "CONFIGURATION conf OF ent IS",
"USE work.foo;", "USE work.foo;",
@ -535,7 +535,7 @@ function Beautify3Case19() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"FUNCTION \" + \"(x, y : integer) return integer IS", "FUNCTION \" + \"(x, y : integer) return integer IS",
"BEGIN", "BEGIN",
@ -555,7 +555,7 @@ function Beautify3Case20() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"m <= ((1, 2, 3, 4)", "m <= ((1, 2, 3, 4)",
"(5, 6, 7, 8));", "(5, 6, 7, 8));",
@ -573,7 +573,7 @@ function Beautify3Case21() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let inputs: Array<string> = [ let inputs: Array<string> = [
"g: ENTITY work.foo", "g: ENTITY work.foo",
"GENERIC MAP( X => 1 )", "GENERIC MAP( X => 1 )",
@ -758,7 +758,7 @@ function IntegrationTest() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["port", "generic"]; new_line_after_symbols.noNewLineAfter = ["port", "generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
let input = "architecture TB of TB_CPU is\r\n component CPU_IF\r\n port -- port list\r\n end component;\r\n signal CPU_DATA_VALID: std_ulogic;\r\n signal CLK, RESET: std_ulogic := '0';\r\n constant PERIOD : time := 10 ns;\r\n constant MAX_SIM: time := 50 * PERIOD;\r\n begin\r\n -- concurrent statements\r\n end TB;" let input = "architecture TB of TB_CPU is\r\n component CPU_IF\r\n port -- port list\r\n end component;\r\n signal CPU_DATA_VALID: std_ulogic;\r\n signal CLK, RESET: std_ulogic := '0';\r\n constant PERIOD : time := 10 ns;\r\n constant MAX_SIM: time := 50 * PERIOD;\r\n begin\r\n -- concurrent statements\r\n end TB;"
let expected = "ARCHITECTURE TB OF TB_CPU IS\r\n COMPONENT CPU_IF\r\n PORT -- port list\r\n END COMPONENT;\r\n SIGNAL CPU_DATA_VALID : std_ulogic;\r\n SIGNAL CLK, RESET : std_ulogic := '0';\r\n CONSTANT PERIOD : TIME := 10 ns;\r\n CONSTANT MAX_SIM : TIME := 50 * PERIOD;\r\nBEGIN\r\n -- concurrent statements\r\nEND TB;"; let expected = "ARCHITECTURE TB OF TB_CPU IS\r\n COMPONENT CPU_IF\r\n PORT -- port list\r\n END COMPONENT;\r\n SIGNAL CPU_DATA_VALID : std_ulogic;\r\n SIGNAL CLK, RESET : std_ulogic := '0';\r\n CONSTANT PERIOD : TIME := 10 ns;\r\n CONSTANT MAX_SIM : TIME := 50 * PERIOD;\r\nBEGIN\r\n -- concurrent statements\r\nEND TB;";
let actual = beautify(input, settings); let actual = beautify(input, settings);
@ -911,173 +911,124 @@ function IntegrationTest() {
IntegrationTest70(); IntegrationTest70();
IntegrationTest71(); IntegrationTest71();
IntegrationTest72(); IntegrationTest72();
IntegrationTest73();
IntegrationTest74();
} }
function IntegrationTest23() { function IntegrationTest23() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", "\t", new_line_after_symbols);
let settings = GetDefaultSettings("\t");
let input = "PACKAGE p IS\r\n TYPE int_array IS ARRAY (INTEGER RANGE <>) OF INTEGER;\r\n TYPE ten_ints IS ARRAY (1 TO 10) OF INTEGER;\r\n TYPE chars IS (A, B, C);\r\n TYPE char_counts IS ARRAY (chars) OF INTEGER;\r\n TYPE two_d IS ARRAY (1 TO 3, 4 TO 6) OF INTEGER;\r\n TYPE ab_chars IS ARRAY (chars RANGE A TO B) OF INTEGER;\r\nEND PACKAGE;"; let input = "PACKAGE p IS\r\n TYPE int_array IS ARRAY (INTEGER RANGE <>) OF INTEGER;\r\n TYPE ten_ints IS ARRAY (1 TO 10) OF INTEGER;\r\n TYPE chars IS (A, B, C);\r\n TYPE char_counts IS ARRAY (chars) OF INTEGER;\r\n TYPE two_d IS ARRAY (1 TO 3, 4 TO 6) OF INTEGER;\r\n TYPE ab_chars IS ARRAY (chars RANGE A TO B) OF INTEGER;\r\nEND PACKAGE;";
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("Type array", input, actual); assertAndCountTest("Type array", input, actual);
} }
function IntegrationTest24() { function IntegrationTest24() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings();
let input = "ARCHITECTURE a OF e IS\r\n ATTRIBUTE foo : INTEGER;\r\n ATTRIBUTE foo OF x : SIGNAL IS 5;\r\n ATTRIBUTE foo OF x : COMPONENT IS 5;\r\n ATTRIBUTE foo OF x : LABEL IS 6;\r\n ATTRIBUTE foo OF x : TYPE IS 4;\r\nBEGIN\r\n ASSERT x'foo(5);\r\nEND ARCHITECTURE;"; let input = "ARCHITECTURE a OF e IS\r\n ATTRIBUTE foo : INTEGER;\r\n ATTRIBUTE foo OF x : SIGNAL IS 5;\r\n ATTRIBUTE foo OF x : COMPONENT IS 5;\r\n ATTRIBUTE foo OF x : LABEL IS 6;\r\n ATTRIBUTE foo OF x : TYPE IS 4;\r\nBEGIN\r\n ASSERT x'foo(5);\r\nEND ARCHITECTURE;";
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("attribute", input, actual); assertAndCountTest("attribute", input, actual);
} }
function IntegrationTest25() { function IntegrationTest25() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings();
let input = 'PACKAGE bitstring IS\r\n CONSTANT x : t := X"1234";\r\n CONSTANT y : t := O"1234";\r\n CONSTANT z : t := X"ab";\r\n CONSTANT b : t := B"101";\r\n CONSTANT c : t := x"f";\r\n CONSTANT d : t := X"a_b";\r\nEND PACKAGE;\r\nPACKAGE bitstring_error IS\r\n CONSTANT e1 : t := O"9"; -- Error\r\nEND PACKAGE;'; let input = 'PACKAGE bitstring IS\r\n CONSTANT x : t := X"1234";\r\n CONSTANT y : t := O"1234";\r\n CONSTANT z : t := X"ab";\r\n CONSTANT b : t := B"101";\r\n CONSTANT c : t := x"f";\r\n CONSTANT d : t := X"a_b";\r\nEND PACKAGE;\r\nPACKAGE bitstring_error IS\r\n CONSTANT e1 : t := O"9"; -- Error\r\nEND PACKAGE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("bitstring", input, actual); assertAndCountTest("bitstring", input, actual);
} }
function IntegrationTest26() { function IntegrationTest26() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings();
let input = 'ARCHITECTURE a OF e IS\r\nBEGIN\r\n b : BLOCK IS\r\n BEGIN\r\n END BLOCK;\r\n c : BLOCK IS\r\n SIGNAL x : INTEGER;\r\n SIGNAL y : real;\r\n BEGIN\r\n x <= y;\r\n END BLOCK;\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE a OF e IS\r\nBEGIN\r\n b : BLOCK IS\r\n BEGIN\r\n END BLOCK;\r\n c : BLOCK IS\r\n SIGNAL x : INTEGER;\r\n SIGNAL y : real;\r\n BEGIN\r\n x <= y;\r\n END BLOCK;\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("block", input, actual); assertAndCountTest("block", input, actual);
} }
function IntegrationTest27() { function IntegrationTest27() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'CONTEXT widget_context IS\r\n LIBRARY ieee;\r\n USE ieee.std_logic_1164.ALL, ieee.numeric_std.ALL;\r\n USE widget_lib.widget_defs.ALL;\r\n USE widget_lib.widget_comps.ALL;\r\nEND CONTEXT;\r\n\r\nCONTEXT dongle_context IS\r\n LIBRARY widget_lib;\r\n CONTEXT widget_lib.widget_context;\r\nEND CONTEXT;\r\n\r\nLIBRARY foo;\r\nUSE foo.moo;\r\n\r\nCONTEXT bad IS -- Error\r\nEND CONTEXT;'; let input = 'CONTEXT widget_context IS\r\n LIBRARY ieee;\r\n USE ieee.std_logic_1164.ALL, ieee.numeric_std.ALL;\r\n USE widget_lib.widget_defs.ALL;\r\n USE widget_lib.widget_comps.ALL;\r\nEND CONTEXT;\r\n\r\nCONTEXT dongle_context IS\r\n LIBRARY widget_lib;\r\n CONTEXT widget_lib.widget_context;\r\nEND CONTEXT;\r\n\r\nLIBRARY foo;\r\nUSE foo.moo;\r\n\r\nCONTEXT bad IS -- Error\r\nEND CONTEXT;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("context", input, actual); assertAndCountTest("context", input, actual);
} }
function IntegrationTest28() { function IntegrationTest28() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE foo OF bar IS\r\n SIGNAL \\foo bar\\ : INTEGER;\r\n SIGNAL \\a\\\\b\\ : INTEGER;\r\n SIGNAL \\Thing!!! \\ : INTEGER;\r\n SIGNAL \\name\\ : INTEGER;\r\n SIGNAL name : INTEGER;\r\nBEGIN\r\n \\foo.bar.baz\\ <= \\hello\\;\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE foo OF bar IS\r\n SIGNAL \\foo bar\\ : INTEGER;\r\n SIGNAL \\a\\\\b\\ : INTEGER;\r\n SIGNAL \\Thing!!! \\ : INTEGER;\r\n SIGNAL \\name\\ : INTEGER;\r\n SIGNAL name : INTEGER;\r\nBEGIN\r\n \\foo.bar.baz\\ <= \\hello\\;\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("extended \\ 28", input, actual); assertAndCountTest("extended \\ 28", input, actual);
} }
function IntegrationTest29() { function IntegrationTest29() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'PACKAGE func IS\r\n FUNCTION add(x, y : INTEGER; y : IN INTEGER) RETURN INTEGER;\r\n IMPURE FUNCTION naughty RETURN INTEGER;\r\n FUNCTION "+"(x, y : INTEGER) RETURN INTEGER;\r\nEND PACKAGE;'; let input = 'PACKAGE func IS\r\n FUNCTION add(x, y : INTEGER; y : IN INTEGER) RETURN INTEGER;\r\n IMPURE FUNCTION naughty RETURN INTEGER;\r\n FUNCTION "+"(x, y : INTEGER) RETURN INTEGER;\r\nEND PACKAGE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("extended \\ 29", input, actual); assertAndCountTest("extended \\ 29", input, actual);
} }
function IntegrationTest30() { function IntegrationTest30() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE a OF g IS\r\nBEGIN\r\n\r\n g1 : IF foo GENERATE\r\n SIGNAL x : INTEGER;\r\n BEGIN\r\n x <= 5;\r\n END GENERATE;\r\n\r\n g2 : IF bar GENERATE\r\n g2a : IF x < 5 GENERATE\r\n g <= 7;\r\n END GENERATE;\r\n END GENERATE;\r\n\r\n g3 : FOR i IN 1 TO 40 GENERATE\r\n SIGNAL x : INTEGER;\r\n BEGIN\r\n f <= h;\r\n END GENERATE;\r\n\r\n g4 : FOR i IN x\'RANGE GENERATE\r\n END GENERATE;\r\n\r\n g5 : FOR i IN x\'RANGE GENERATE\r\n BEGIN\r\n END GENERATE;\r\n\r\n g6 : FOR i IN 1 TO 3 GENERATE\r\n COMPONENT sub_ent IS\r\n PORT (val : OUT NATURAL);\r\n END COMPONENT sub_ent; -- OK\r\n BEGIN\r\n END GENERATE;\r\n\r\n g7 : IF true GENERATE\r\n PROCEDURE doit IS -- OK\r\n BEGIN\r\n write(OUTPUT, "OK." & LF);\r\n END PROCEDURE doit;\r\n BEGIN\r\n END GENERATE g7;\r\n\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE a OF g IS\r\nBEGIN\r\n\r\n g1 : IF foo GENERATE\r\n SIGNAL x : INTEGER;\r\n BEGIN\r\n x <= 5;\r\n END GENERATE;\r\n\r\n g2 : IF bar GENERATE\r\n g2a : IF x < 5 GENERATE\r\n g <= 7;\r\n END GENERATE;\r\n END GENERATE;\r\n\r\n g3 : FOR i IN 1 TO 40 GENERATE\r\n SIGNAL x : INTEGER;\r\n BEGIN\r\n f <= h;\r\n END GENERATE;\r\n\r\n g4 : FOR i IN x\'RANGE GENERATE\r\n END GENERATE;\r\n\r\n g5 : FOR i IN x\'RANGE GENERATE\r\n BEGIN\r\n END GENERATE;\r\n\r\n g6 : FOR i IN 1 TO 3 GENERATE\r\n COMPONENT sub_ent IS\r\n PORT (val : OUT NATURAL);\r\n END COMPONENT sub_ent; -- OK\r\n BEGIN\r\n END GENERATE;\r\n\r\n g7 : IF true GENERATE\r\n PROCEDURE doit IS -- OK\r\n BEGIN\r\n write(OUTPUT, "OK." & LF);\r\n END PROCEDURE doit;\r\n BEGIN\r\n END GENERATE g7;\r\n\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("generate", input, actual); assertAndCountTest("generate", input, actual);
} }
function IntegrationTest31() { function IntegrationTest31() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ENTITY ent IS\r\nEND ENTITY;\r\n\r\nARCHITECTURE a OF ent IS\r\nBEGIN\r\n main : PROCESS\r\n BEGIN\r\n REPORT """""";\r\n WAIT;\r\n END PROCESS;\r\nEND ARCHITECTURE;'; let input = 'ENTITY ent IS\r\nEND ENTITY;\r\n\r\nARCHITECTURE a OF ent IS\r\nBEGIN\r\n main : PROCESS\r\n BEGIN\r\n REPORT """""";\r\n WAIT;\r\n END PROCESS;\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("report \"\"", input, actual); assertAndCountTest("report \"\"", input, actual);
} }
function IntegrationTest32() { function IntegrationTest32() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'PACKAGE p IS\r\n\r\n TYPE SharedCounter IS PROTECTED\r\n PROCEDURE increment (N : INTEGER := 1);\r\n PROCEDURE decrement (N : INTEGER := 1);\r\n IMPURE FUNCTION value RETURN INTEGER;\r\n END PROTECTED SharedCounter;\r\n\r\n TYPE SharedCounter IS PROTECTED BODY\r\n VARIABLE counter : INTEGER := 0;\r\n\r\n PROCEDURE increment (N : INTEGER := 1) IS\r\n BEGIN\r\n counter := counter + N;\r\n END PROCEDURE increment;\r\n\r\n PROCEDURE decrement (N : INTEGER := 1) IS\r\n BEGIN\r\n counter := counter - N;\r\n END PROCEDURE decrement;\r\n\r\n IMPURE FUNCTION value RETURN INTEGER IS\r\n BEGIN\r\n RETURN counter;\r\n END FUNCTION value;\r\n END PROTECTED BODY;\r\n\r\nEND PACKAGE;'; let input = 'PACKAGE p IS\r\n\r\n TYPE SharedCounter IS PROTECTED\r\n PROCEDURE increment (N : INTEGER := 1);\r\n PROCEDURE decrement (N : INTEGER := 1);\r\n IMPURE FUNCTION value RETURN INTEGER;\r\n END PROTECTED SharedCounter;\r\n\r\n TYPE SharedCounter IS PROTECTED BODY\r\n VARIABLE counter : INTEGER := 0;\r\n\r\n PROCEDURE increment (N : INTEGER := 1) IS\r\n BEGIN\r\n counter := counter + N;\r\n END PROCEDURE increment;\r\n\r\n PROCEDURE decrement (N : INTEGER := 1) IS\r\n BEGIN\r\n counter := counter - N;\r\n END PROCEDURE decrement;\r\n\r\n IMPURE FUNCTION value RETURN INTEGER IS\r\n BEGIN\r\n RETURN counter;\r\n END FUNCTION value;\r\n END PROTECTED BODY;\r\n\r\nEND PACKAGE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("protected", input, actual); assertAndCountTest("protected", input, actual);
} }
function IntegrationTest33() { function IntegrationTest33() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE a OF b IS\r\nBEGIN\r\n\r\n -- Wait statements\r\n PROCESS IS\r\n BEGIN\r\n WAIT FOR 1 ns;\r\n block_forever : WAIT;\r\n WAIT ON x;\r\n WAIT ON x, y, z(1 DOWNTO 0);\r\n WAIT ON w(1) FOR 2 ns;\r\n WAIT UNTIL x = 3;\r\n WAIT UNTIL y = x FOR 5 ns;\r\n WAIT ON x UNTIL x = 2 FOR 1 ns;\r\n END PROCESS;\r\n\r\n -- Blocking assignment\r\n PROCESS IS\r\n VARIABLE a : INTEGER;\r\n BEGIN\r\n a := 2;\r\n a := a + (a * 3);\r\n END PROCESS;\r\n\r\n -- Assert and report\r\n PROCESS IS\r\n BEGIN\r\n ASSERT true;\r\n ASSERT false SEVERITY note;\r\n ASSERT 1 > 2 REPORT "oh no" SEVERITY failure;\r\n REPORT "hello";\r\n REPORT "boo" SEVERITY error;\r\n END PROCESS;\r\n\r\n -- Function calls\r\n PROCESS IS\r\n BEGIN\r\n x := foo(1, 2, 3);\r\n a := "ABS"(b);\r\n END PROCESS;\r\n\r\n -- If\r\n PROCESS IS\r\n BEGIN\r\n IF true THEN\r\n x := 1;\r\n END IF;\r\n test : IF true THEN\r\n x := y;\r\n END IF test;\r\n IF x > 2 THEN\r\n x := 5;\r\n ELSE\r\n y := 2;\r\n END IF;\r\n IF x > 3 THEN\r\n NULL;\r\n ELSIF x > 5 THEN\r\n NULL;\r\n ELSIF true THEN\r\n NULL;\r\n ELSE\r\n x := 2;\r\n END IF;\r\n END PROCESS;\r\n\r\n -- Null\r\n PROCESS IS\r\n BEGIN\r\n NULL;\r\n END PROCESS;\r\n\r\n -- Return\r\n PROCESS IS\r\n BEGIN\r\n RETURN 4 * 4;\r\n END PROCESS;\r\n\r\n -- While\r\n PROCESS IS\r\n BEGIN\r\n WHILE n > 0 LOOP\r\n n := n - 1;\r\n END LOOP;\r\n LOOP\r\n NULL;\r\n END LOOP;\r\n END PROCESS;\r\n\r\n -- Delayed assignment\r\n PROCESS IS\r\n BEGIN\r\n x <= 4 AFTER 5 ns;\r\n x <= 5 AFTER 1 ns, 7 AFTER 8 ns;\r\n x <= 5, 7 AFTER 8 ns;\r\n x <= INERTIAL 5;\r\n x <= TRANSPORT 4 AFTER 2 ns;\r\n x <= REJECT 4 ns INERTIAL 6 AFTER 10 ns;\r\n END PROCESS;\r\n\r\n -- For\r\n PROCESS IS\r\n BEGIN\r\n FOR i IN 0 TO 10 LOOP\r\n NULL;\r\n END LOOP;\r\n FOR i IN foo\'RANGE LOOP\r\n NULL;\r\n END LOOP;\r\n END PROCESS;\r\n\r\n -- Exit\r\n PROCESS IS\r\n BEGIN\r\n EXIT;\r\n EXIT WHEN x = 1;\r\n END PROCESS;\r\n\r\n -- Procedure call\r\n PROCESS IS\r\n BEGIN\r\n foo(x, y, 1);\r\n bar;\r\n foo(a => 1, b => 2, 3);\r\n END PROCESS;\r\n\r\n -- Case\r\n PROCESS IS\r\n BEGIN\r\n CASE x IS\r\n WHEN 1 =>\r\n NULL;\r\n WHEN 2 =>\r\n NULL;\r\n WHEN 3 | 4 =>\r\n NULL;\r\n WHEN OTHERS =>\r\n NULL;\r\n END CASE;\r\n END PROCESS;\r\n\r\n -- Next\r\n PROCESS IS\r\n BEGIN\r\n NEXT;\r\n NEXT WHEN foo = 5;\r\n END PROCESS;\r\n\r\n -- Signal assignment to aggregate\r\n PROCESS IS\r\n BEGIN\r\n (x, y, z) <= foo;\r\n END PROCESS;\r\n\r\n -- Case statement range bug\r\n PROCESS IS\r\n BEGIN\r\n CASE f IS\r\n WHEN 1 =>\r\n FOR i IN x\'RANGE LOOP\r\n END LOOP;\r\n END CASE;\r\n END PROCESS;\r\n\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE a OF b IS\r\nBEGIN\r\n\r\n -- Wait statements\r\n PROCESS IS\r\n BEGIN\r\n WAIT FOR 1 ns;\r\n block_forever : WAIT;\r\n WAIT ON x;\r\n WAIT ON x, y, z(1 DOWNTO 0);\r\n WAIT ON w(1) FOR 2 ns;\r\n WAIT UNTIL x = 3;\r\n WAIT UNTIL y = x FOR 5 ns;\r\n WAIT ON x UNTIL x = 2 FOR 1 ns;\r\n END PROCESS;\r\n\r\n -- Blocking assignment\r\n PROCESS IS\r\n VARIABLE a : INTEGER;\r\n BEGIN\r\n a := 2;\r\n a := a + (a * 3);\r\n END PROCESS;\r\n\r\n -- Assert and report\r\n PROCESS IS\r\n BEGIN\r\n ASSERT true;\r\n ASSERT false SEVERITY note;\r\n ASSERT 1 > 2 REPORT "oh no" SEVERITY failure;\r\n REPORT "hello";\r\n REPORT "boo" SEVERITY error;\r\n END PROCESS;\r\n\r\n -- Function calls\r\n PROCESS IS\r\n BEGIN\r\n x := foo(1, 2, 3);\r\n a := "ABS"(b);\r\n END PROCESS;\r\n\r\n -- If\r\n PROCESS IS\r\n BEGIN\r\n IF true THEN\r\n x := 1;\r\n END IF;\r\n test : IF true THEN\r\n x := y;\r\n END IF test;\r\n IF x > 2 THEN\r\n x := 5;\r\n ELSE\r\n y := 2;\r\n END IF;\r\n IF x > 3 THEN\r\n NULL;\r\n ELSIF x > 5 THEN\r\n NULL;\r\n ELSIF true THEN\r\n NULL;\r\n ELSE\r\n x := 2;\r\n END IF;\r\n END PROCESS;\r\n\r\n -- Null\r\n PROCESS IS\r\n BEGIN\r\n NULL;\r\n END PROCESS;\r\n\r\n -- Return\r\n PROCESS IS\r\n BEGIN\r\n RETURN 4 * 4;\r\n END PROCESS;\r\n\r\n -- While\r\n PROCESS IS\r\n BEGIN\r\n WHILE n > 0 LOOP\r\n n := n - 1;\r\n END LOOP;\r\n LOOP\r\n NULL;\r\n END LOOP;\r\n END PROCESS;\r\n\r\n -- Delayed assignment\r\n PROCESS IS\r\n BEGIN\r\n x <= 4 AFTER 5 ns;\r\n x <= 5 AFTER 1 ns, 7 AFTER 8 ns;\r\n x <= 5, 7 AFTER 8 ns;\r\n x <= INERTIAL 5;\r\n x <= TRANSPORT 4 AFTER 2 ns;\r\n x <= REJECT 4 ns INERTIAL 6 AFTER 10 ns;\r\n END PROCESS;\r\n\r\n -- For\r\n PROCESS IS\r\n BEGIN\r\n FOR i IN 0 TO 10 LOOP\r\n NULL;\r\n END LOOP;\r\n FOR i IN foo\'RANGE LOOP\r\n NULL;\r\n END LOOP;\r\n END PROCESS;\r\n\r\n -- Exit\r\n PROCESS IS\r\n BEGIN\r\n EXIT;\r\n EXIT WHEN x = 1;\r\n END PROCESS;\r\n\r\n -- Procedure call\r\n PROCESS IS\r\n BEGIN\r\n foo(x, y, 1);\r\n bar;\r\n foo(a => 1, b => 2, 3);\r\n END PROCESS;\r\n\r\n -- Case\r\n PROCESS IS\r\n BEGIN\r\n CASE x IS\r\n WHEN 1 =>\r\n NULL;\r\n WHEN 2 =>\r\n NULL;\r\n WHEN 3 | 4 =>\r\n NULL;\r\n WHEN OTHERS =>\r\n NULL;\r\n END CASE;\r\n END PROCESS;\r\n\r\n -- Next\r\n PROCESS IS\r\n BEGIN\r\n NEXT;\r\n NEXT WHEN foo = 5;\r\n END PROCESS;\r\n\r\n -- Signal assignment to aggregate\r\n PROCESS IS\r\n BEGIN\r\n (x, y, z) <= foo;\r\n END PROCESS;\r\n\r\n -- Case statement range bug\r\n PROCESS IS\r\n BEGIN\r\n CASE f IS\r\n WHEN 1 =>\r\n FOR i IN x\'RANGE LOOP\r\n END LOOP;\r\n END CASE;\r\n END PROCESS;\r\n\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("sequence", input, actual); assertAndCountTest("sequence", input, actual);
} }
function IntegrationTest34() { function IntegrationTest34() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE a OF b IS\r\n FOR x : y USE ENTITY work.foo;\r\n FOR x1, x2 : y USE ENTITY work.foo;\r\n FOR x : y USE ENTITY work.foo(bar);\r\n FOR x : y USE ENTITY work.foo(bar)\r\n GENERIC MAP(a => 1)\r\n PORT MAP(b => g);\r\n FOR ALL : y USE CONFIGURATION yah;\r\n FOR OTHERS : y USE OPEN;\r\nBEGIN\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE a OF b IS\r\n FOR x : y USE ENTITY work.foo;\r\n FOR x1, x2 : y USE ENTITY work.foo;\r\n FOR x : y USE ENTITY work.foo(bar);\r\n FOR x : y USE ENTITY work.foo(bar)\r\n GENERIC MAP(a => 1)\r\n PORT MAP(b => g);\r\n FOR ALL : y USE CONFIGURATION yah;\r\n FOR OTHERS : y USE OPEN;\r\nBEGIN\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("spec", input, actual); assertAndCountTest("spec", input, actual);
} }
function IntegrationTest35() { function IntegrationTest35() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE a OF b IS\r\n TYPE my_int IS RANGE 0 TO 100;\r\n SIGNAL x : my_int := 2;\r\n\r\n TYPE resistance IS RANGE 0 TO 10000000\r\n UNITS\r\n ohm;\r\n kohm = 1000 ohm;\r\n Mohm = 1000 kohm;\r\n END UNITS;\r\n SIGNAL r : resistance := 100 ohm;\r\n\r\n SUBTYPE big_r IS resistance RANGE 1000 TO 2000;\r\n\r\n SUBTYPE my_small_int IS my_int RANGE 0 TO 5;\r\n\r\n SUBTYPE foo IS my_int RANGE 2 TO my_int\'high;\r\n\r\n SUBTYPE rint IS resolved my_int;\r\n\r\n TYPE p IS ACCESS my_int;\r\n\r\n TYPE f IS FILE OF my_int;\r\n\r\n FILE f1 : f OPEN READ_MODE IS "foo";\r\n\r\n FILE f2 : f IS "bar";\r\n\r\n FILE f3 : f;\r\n\r\n TYPE r1 IS RECORD\r\n a : INTEGER;\r\n b : INTEGER;\r\n c : foo(1 TO 5);\r\n END RECORD;\r\n\r\n FILE f4 : f IS OUT "bar"; -- VHDL-87 compat\r\n\r\n FILE f5 : f IS IN "bar"; -- VHDL-87 compat\r\n\r\n TYPE r2 IS RECORD\r\n x : INTEGER;\r\n END RECORD r2;\r\n\r\nBEGIN\r\n\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE a OF b IS\r\n TYPE my_int IS RANGE 0 TO 100;\r\n SIGNAL x : my_int := 2;\r\n\r\n TYPE resistance IS RANGE 0 TO 10000000\r\n UNITS\r\n ohm;\r\n kohm = 1000 ohm;\r\n Mohm = 1000 kohm;\r\n END UNITS;\r\n SIGNAL r : resistance := 100 ohm;\r\n\r\n SUBTYPE big_r IS resistance RANGE 1000 TO 2000;\r\n\r\n SUBTYPE my_small_int IS my_int RANGE 0 TO 5;\r\n\r\n SUBTYPE foo IS my_int RANGE 2 TO my_int\'high;\r\n\r\n SUBTYPE rint IS resolved my_int;\r\n\r\n TYPE p IS ACCESS my_int;\r\n\r\n TYPE f IS FILE OF my_int;\r\n\r\n FILE f1 : f OPEN READ_MODE IS "foo";\r\n\r\n FILE f2 : f IS "bar";\r\n\r\n FILE f3 : f;\r\n\r\n TYPE r1 IS RECORD\r\n a : INTEGER;\r\n b : INTEGER;\r\n c : foo(1 TO 5);\r\n END RECORD;\r\n\r\n FILE f4 : f IS OUT "bar"; -- VHDL-87 compat\r\n\r\n FILE f5 : f IS IN "bar"; -- VHDL-87 compat\r\n\r\n TYPE r2 IS RECORD\r\n x : INTEGER;\r\n END RECORD r2;\r\n\r\nBEGIN\r\n\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("types", input, actual); assertAndCountTest("types", input, actual);
} }
function IntegrationTest36() { function IntegrationTest36() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE test OF bufr_test IS\r\nBEGIN\r\n\r\n BUF_DATA_CLK : BUFR\r\n GENERIC MAP(\r\n BUFR_DIVIDE => "BYPASS",\r\n SIM_DEVICE => "7SERIES")\r\n PORT MAP(\r\n O => amu_adc_dco,\r\n CE => \'1\',\r\n CLR => \'0\',\r\n I => amu_adc_dco_i);\r\n\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE test OF bufr_test IS\r\nBEGIN\r\n\r\n BUF_DATA_CLK : BUFR\r\n GENERIC MAP(\r\n BUFR_DIVIDE => "BYPASS",\r\n SIM_DEVICE => "7SERIES")\r\n PORT MAP(\r\n O => amu_adc_dco,\r\n CE => \'1\',\r\n CLR => \'0\',\r\n I => amu_adc_dco_i);\r\n\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("new line after (", input, actual); assertAndCountTest("new line after (", input, actual);
} }
function IntegrationTest37() { function IntegrationTest37() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ENTITY nest1 IS\r\nEND ENTITY;\r\nARCHITECTURE test OF nest1 IS\r\nBEGIN\r\n PROCESS IS\r\n VARIABLE x : INTEGER := 2;\r\n VARIABLE y : bit_vector(7 DOWNTO 0);\r\n IMPURE FUNCTION add_to_x(y : INTEGER) RETURN INTEGER IS\r\n IMPURE FUNCTION do_it RETURN INTEGER IS\r\n BEGIN\r\n RETURN x + y;\r\n END FUNCTION;\r\n BEGIN\r\n RETURN do_it;\r\n END FUNCTION;\r\n BEGIN\r\n ASSERT add_to_x(5) = 7;\r\n WAIT;\r\n END PROCESS;\r\nEND ARCHITECTURE;'; let input = 'ENTITY nest1 IS\r\nEND ENTITY;\r\nARCHITECTURE test OF nest1 IS\r\nBEGIN\r\n PROCESS IS\r\n VARIABLE x : INTEGER := 2;\r\n VARIABLE y : bit_vector(7 DOWNTO 0);\r\n IMPURE FUNCTION add_to_x(y : INTEGER) RETURN INTEGER IS\r\n IMPURE FUNCTION do_it RETURN INTEGER IS\r\n BEGIN\r\n RETURN x + y;\r\n END FUNCTION;\r\n BEGIN\r\n RETURN do_it;\r\n END FUNCTION;\r\n BEGIN\r\n ASSERT add_to_x(5) = 7;\r\n WAIT;\r\n END PROCESS;\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("nested functions", input, actual); assertAndCountTest("nested functions", input, actual);
} }
function IntegrationTest38() { function IntegrationTest38() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'REPORT INTEGER\'image(a) & " " & INTEGER\'image(b) & " "\r\n & INTEGER\'image(c) & " " & INTEGER\'image(d) & " "\r\n & INTEGER\'image(e) & " " & INTEGER\'image(f);\r\nWAIT;'; let input = 'REPORT INTEGER\'image(a) & " " & INTEGER\'image(b) & " "\r\n & INTEGER\'image(c) & " " & INTEGER\'image(d) & " "\r\n & INTEGER\'image(e) & " " & INTEGER\'image(f);\r\nWAIT;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("report severl lines", input, actual); assertAndCountTest("report severl lines", input, actual);
} }
function IntegrationTest39() { function IntegrationTest39() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'assert v / = ( X "01", X "02" ) ;'; let input = 'assert v / = ( X "01", X "02" ) ;';
let expected = 'ASSERT v /= (X "01", X "02");'; let expected = 'ASSERT v /= (X "01", X "02");';
let actual = beautify(input, settings); let actual = beautify(input, settings);
@ -1085,50 +1036,35 @@ function IntegrationTest39() {
} }
function IntegrationTest40() { function IntegrationTest40() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings();
let input = 'PORT MAP\r\n (we => NOT cpu_rw, spo => ram_dout);\r\nPORT MAP(we => NOT cpu_rw, spo => ram_dout);\r\nPORT MAP\r\n(\r\n we => NOT cpu_rw, spo => ram_dout\r\n);'; let input = 'PORT MAP\r\n (we => NOT cpu_rw, spo => ram_dout);\r\nPORT MAP(we => NOT cpu_rw, spo => ram_dout);\r\nPORT MAP\r\n(\r\n we => NOT cpu_rw, spo => ram_dout\r\n);';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("port map in newline", input, actual); assertAndCountTest("port map in newline", input, actual);
} }
function IntegrationTest41() { function IntegrationTest41() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE test3 OF test IS\r\n COMPONENT comp IS PORT (a : BOOLEAN);\r\n END COMPONENT;\r\n SIGNAL s_ok : BOOLEAN;\r\nBEGIN\r\n comp PORT MAP(a => s_ok); -- unlabeled component instantiation\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE test3 OF test IS\r\n COMPONENT comp IS PORT (a : BOOLEAN);\r\n END COMPONENT;\r\n SIGNAL s_ok : BOOLEAN;\r\nBEGIN\r\n comp PORT MAP(a => s_ok); -- unlabeled component instantiation\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("end component", input, actual); assertAndCountTest("end component", input, actual);
} }
function IntegrationTest42() { function IntegrationTest42() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ENTITY bar IS\r\nEND ENTITY bar;\r\nENTITY \\foo\\ IS\r\n PORT (test : IN BIT);\r\nEND ENTITY \\foo\\;\r\nARCHITECTURE structural OF \\foo\\ IS\r\nBEGIN -- architecture structural\r\nEND ARCHITECTURE structural;\r\nARCHITECTURE structural OF bar IS\r\n SIGNAL test : BIT;\r\nBEGIN -- architecture structural\r\n foo_1 : ENTITY work.\\foo\\\r\n PORT MAP(test => test);\r\nEND ARCHITECTURE structural;'; let input = 'ENTITY bar IS\r\nEND ENTITY bar;\r\nENTITY \\foo\\ IS\r\n PORT (test : IN BIT);\r\nEND ENTITY \\foo\\;\r\nARCHITECTURE structural OF \\foo\\ IS\r\nBEGIN -- architecture structural\r\nEND ARCHITECTURE structural;\r\nARCHITECTURE structural OF bar IS\r\n SIGNAL test : BIT;\r\nBEGIN -- architecture structural\r\n foo_1 : ENTITY work.\\foo\\\r\n PORT MAP(test => test);\r\nEND ARCHITECTURE structural;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("end component", input, actual); assertAndCountTest("end component", input, actual);
} }
function IntegrationTest43() { function IntegrationTest43() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'ARCHITECTURE test OF issue122 IS\r\n IMPURE FUNCTION func(x : INTEGER) RETURN INTEGER IS\r\n IMPURE FUNCTION nested RETURN INTEGER IS\r\n BEGIN\r\n RETURN x;\r\n END FUNCTION;\r\n VARIABLE v : INTEGER := nested;\r\n BEGIN\r\n RETURN v;\r\n END FUNCTION;\r\nBEGIN\r\nEND ARCHITECTURE;'; let input = 'ARCHITECTURE test OF issue122 IS\r\n IMPURE FUNCTION func(x : INTEGER) RETURN INTEGER IS\r\n IMPURE FUNCTION nested RETURN INTEGER IS\r\n BEGIN\r\n RETURN x;\r\n END FUNCTION;\r\n VARIABLE v : INTEGER := nested;\r\n BEGIN\r\n RETURN v;\r\n END FUNCTION;\r\nBEGIN\r\nEND ARCHITECTURE;';
let actual = beautify(input, settings); let actual = beautify(input, settings);
assertAndCountTest("end component", input, actual); assertAndCountTest("end component", input, actual);
} }
function IntegrationTest44() { function IntegrationTest44() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings(" ");
let input = 'REPORT\n"A_ARITH_MOD_tester.main Tester is now ready. A total of " &\nINTEGER\'image(totalTests) & " tests have been detected.";'; let input = 'REPORT\n"A_ARITH_MOD_tester.main Tester is now ready. A total of " &\nINTEGER\'image(totalTests) & " tests have been detected.";';
let expected = 'REPORT\r\n "A_ARITH_MOD_tester.main Tester is now ready. A total of " &\r\n INTEGER\'image(totalTests) & " tests have been detected.";'; let expected = 'REPORT\r\n "A_ARITH_MOD_tester.main Tester is now ready. A total of " &\r\n INTEGER\'image(totalTests) & " tests have been detected.";';
let actual = beautify(input, settings); let actual = beautify(input, settings);
@ -1366,19 +1302,37 @@ function IntegrationTest72() {
assertAndCountTest("scientific notation", expected, actual); assertAndCountTest("scientific notation", expected, actual);
} }
function GetDefaultSettings() {
function IntegrationTest73() {
let settings = GetDefaultSettings();
settings.EndOfLine = "\n";
let input = 'test := test;\ntest := test;';
let actual = beautify(input, settings);
assertAndCountTest("end of line", input, actual);
}
function IntegrationTest74() {
let settings = GetDefaultSettings();
settings.EndOfLine = " EOF ";
let input = 'test := test;\ntest := test;';
let expected = 'test := test; EOF test := test;';
let actual = beautify(input, settings);
assertAndCountTest("end of line 2", expected, actual);
}
function GetDefaultSettings(indentation: string = " "): BeautifierSettings {
let new_line_after_symbols = new NewLineSettings(); let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"]; new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols, indentation);
return settings; return settings;
} }
function getDefaultBeautifierSettings(newLineSettings: NewLineSettings, indentation: string = " "): BeautifierSettings {
return new BeautifierSettings(false, false, false, false, false, "uppercase", indentation, newLineSettings, "\r\n");
}
function IntegrationTest20() { function IntegrationTest20() {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings();
let input = "process xyx (vf,fr,\r\nde -- comment\r\n)"; let input = "process xyx (vf,fr,\r\nde -- comment\r\n)";
let expected = "PROCESS xyx (vf, fr, \r\n de -- comment\r\n )"; let expected = "PROCESS xyx (vf, fr, \r\n de -- comment\r\n )";
let actual = beautify(input, settings); let actual = beautify(input, settings);
@ -1386,10 +1340,7 @@ function IntegrationTest20() {
} }
function IntegrationTest5() { function IntegrationTest5() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = GetDefaultSettings();
settings.SignAlignRegional = true; settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PORT"]; settings.SignAlignKeyWords = ["PORT"];
let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);"; let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);";
@ -1402,7 +1353,7 @@ function IntegrationTest6() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";", "port map"]; new_line_after_symbols.newLineAfter = ["then", ";", "port map"];
new_line_after_symbols.noNewLineAfter = ["generic"]; new_line_after_symbols.noNewLineAfter = ["generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
settings.SignAlignRegional = true; settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PORT"]; settings.SignAlignKeyWords = ["PORT"];
let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);"; let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);";
@ -1414,7 +1365,7 @@ function IntegrationTest6() {
function IntegrationTest7() { function IntegrationTest7() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
settings.SignAlignRegional = true; settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PORT", "GENERIC"]; settings.SignAlignKeyWords = ["PORT", "GENERIC"];
let input = "entity p is\r\n generic\r\n (\r\n -- INCLK\r\n INCLK0_INPUT_FREQUENCY : natural;\r\n\r\n -- CLK1\r\n CLK1_DIVIDE_BY : natural := 1;\r\n CLK1_MULTIPLY_BY : unnatural:= 1;\r\n CLK1_PHASE_SHIFT : string := \"0\"\r\n );\r\n port\r\n (\r\n inclk0 : in std_logic := '0';\r\n c0 : out std_logic ;\r\n c1 : out std_logic \r\n );\r\nEND pll;"; let input = "entity p is\r\n generic\r\n (\r\n -- INCLK\r\n INCLK0_INPUT_FREQUENCY : natural;\r\n\r\n -- CLK1\r\n CLK1_DIVIDE_BY : natural := 1;\r\n CLK1_MULTIPLY_BY : unnatural:= 1;\r\n CLK1_PHASE_SHIFT : string := \"0\"\r\n );\r\n port\r\n (\r\n inclk0 : in std_logic := '0';\r\n c0 : out std_logic ;\r\n c1 : out std_logic \r\n );\r\nEND pll;";
@ -1427,7 +1378,7 @@ function IntegrationTest2() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings(); let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"]; new_line_after_symbols.noNewLineAfter = ["generic"];
let settings: BeautifierSettings = new BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
settings.RemoveComments = true; settings.RemoveComments = true;
let input = "architecture TB of TB_CPU is\r\n component CPU_IF\r\n port -- port list\r\n end component;\r\n signal CPU_DATA_VALID: std_ulogic;\r\n signal CLK, RESET: std_ulogic := '0';\r\n constant PERIOD : time := 10 ns;\r\n constant MAX_SIM: time := 50 * PERIOD;\r\n begin\r\n -- concurrent statements\r\n end TB;" let input = "architecture TB of TB_CPU is\r\n component CPU_IF\r\n port -- port list\r\n end component;\r\n signal CPU_DATA_VALID: std_ulogic;\r\n signal CLK, RESET: std_ulogic := '0';\r\n constant PERIOD : time := 10 ns;\r\n constant MAX_SIM: time := 50 * PERIOD;\r\n begin\r\n -- concurrent statements\r\n end TB;"
let expected = "ARCHITECTURE TB OF TB_CPU IS\r\n COMPONENT CPU_IF\r\n PORT\r\n END COMPONENT;\r\n SIGNAL CPU_DATA_VALID : std_ulogic;\r\n SIGNAL CLK, RESET : std_ulogic := '0';\r\n CONSTANT PERIOD : TIME := 10 ns;\r\n CONSTANT MAX_SIM : TIME := 50 * PERIOD;\r\nBEGIN\r\nEND TB;"; let expected = "ARCHITECTURE TB OF TB_CPU IS\r\n COMPONENT CPU_IF\r\n PORT\r\n END COMPONENT;\r\n SIGNAL CPU_DATA_VALID : std_ulogic;\r\n SIGNAL CLK, RESET : std_ulogic := '0';\r\n CONSTANT PERIOD : TIME := 10 ns;\r\n CONSTANT MAX_SIM : TIME := 50 * PERIOD;\r\nBEGIN\r\nEND TB;";


Loading…
Cancel
Save