@ -29,6 +29,13 @@ function UnitTestbeautify3() {
Beautify3Case4 ( ) ;
Beautify3Case4 ( ) ;
Beautify3Case5 ( ) ;
Beautify3Case5 ( ) ;
Beautify3Case6 ( ) ;
Beautify3Case6 ( ) ;
Beautify3Case7 ( ) ;
Beautify3Case8 ( ) ;
Beautify3Case9 ( ) ;
Beautify3Case10 ( ) ;
Beautify3Case11 ( ) ;
Beautify3Case12 ( ) ;
Beautify3Case13 ( ) ;
}
}
function Beautify3Case1 ( ) {
function Beautify3Case1 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
@ -144,6 +151,219 @@ function Beautify3Case6() {
] ;
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "case & case end" , settings , inputs , expected , 0 , 11 , 0 ) ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "case & case end" , settings , inputs , expected , 0 , 11 , 0 ) ;
}
}
function Beautify3Case7 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"ARCHITECTURE a OF one IS" ,
"SIGNAL x : INTEGER;" ,
"BEGIN" ,
"-- architecture" ,
"END ARCHITECTURE;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "ARCHITECTURE a OF one IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "SIGNAL x : INTEGER;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "-- architecture" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END ARCHITECTURE;" , 0 ) ,
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "architecture" , settings , inputs , expected , 0 , 4 , 0 ) ;
}
function Beautify3Case8 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"ARCHITECTURE a OF one IS" ,
"SIGNAL x : INTEGER;" ,
"BEGIN" ,
"-- architecture" ,
"END ARCHITECTURE;" ,
"ARCHITECTURE b OF one IS" ,
"SIGNAL x : INTEGER;" ,
"BEGIN" ,
"-- architecture" ,
"END ARCHITECTURE;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "ARCHITECTURE a OF one IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "SIGNAL x : INTEGER;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "-- architecture" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END ARCHITECTURE;" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "ARCHITECTURE b OF one IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "SIGNAL x : INTEGER;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "-- architecture" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END ARCHITECTURE;" , 0 ) ,
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "architecture 2" , settings , inputs , expected , 0 , 9 , 0 ) ;
}
function Beautify3Case9 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS" ,
"VARIABLE i : INTEGER;" ,
"BEGIN" ,
"y := x + 1;" ,
"END PROCEDURE;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "VARIABLE i : INTEGER;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "y := x + 1;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCEDURE;" , 0 )
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "procedure" , settings , inputs , expected , 0 , 4 , 0 ) ;
}
function Beautify3Case10 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"PACKAGE three IS" ,
"SIGNAL s : INTEGER;" ,
"ALIAS sa IS s;" ,
"END PACKAGE;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "PACKAGE three IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "SIGNAL s : INTEGER;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "ALIAS sa IS s;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PACKAGE;" , 0 )
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "package" , settings , inputs , expected , 0 , 3 , 0 ) ;
}
function Beautify3Case11 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"PACKAGE p IS" ,
"PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER);" ,
"END PACKAGE;" ,
"PACKAGE BODY p IS" ,
"PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS" ,
"VARIABLE i : INTEGER;" ,
"BEGIN" ,
"y := x + 1;" ,
"END PROCEDURE;" ,
"PROCEDURE bar(FILE x : text);" ,
"PROCEDURE baz IS" ,
"TYPE foo;" ,
"ALIAS x IS y;" ,
"BEGIN" ,
"END PROCEDURE;" ,
"PROCEDURE tralala IS" ,
"USE work.foo;" ,
"BEGIN" ,
"END PROCEDURE;" ,
"END PACKAGE BODY;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "PACKAGE p IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER);" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PACKAGE;" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "PACKAGE BODY p IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "VARIABLE i : INTEGER;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "y := x + 1;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCEDURE;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE bar(FILE x : text);" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE baz IS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "TYPE foo;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "ALIAS x IS y;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCEDURE;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE tralala IS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "USE work.foo;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCEDURE;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PACKAGE BODY;" , 0 )
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "package" , settings , inputs , expected , 0 , expected . length - 1 , 0 ) ;
}
function Beautify3Case12 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"ARCHITECTURE a OF b IS" ,
"SIGNAL x : INTEGER := 0;" ,
"BEGIN" ,
"p: PROCESS IS" ,
"BEGIN" ,
"END PROCESS;" ,
"PROCESS" ,
"VARIABLE y : INTEGER := 5;" ,
"BEGIN" ,
"x <= y;" ,
"END PROCESS;" ,
"PROCESS (x) IS" ,
"BEGIN" ,
"x <= x + 1;" ,
"END PROCESS;" ,
"POSTPONED PROCESS IS" ,
"BEGIN" ,
"END PROCESS;" ,
"POSTPONED assert x = 1;" ,
"END ARCHITECTURE;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "ARCHITECTURE a OF b IS" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "SIGNAL x : INTEGER := 0;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "p: PROCESS IS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCESS;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCESS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "VARIABLE y : INTEGER := 5;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "x <= y;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCESS;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCESS (x) IS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "x <= x + 1;" , 2 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCESS;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "POSTPONED PROCESS IS" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "BEGIN" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROCESS;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "POSTPONED assert x = 1;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END ARCHITECTURE;" , 0 )
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "package" , settings , inputs , expected , 0 , expected . length - 1 , 0 ) ;
}
function Beautify3Case13 ( ) {
let new_line_after_symbols = new VHDLFormatter_3 . NewLineSettings ( ) ;
new_line_after_symbols . newLineAfter = [ "then" , ";" ] ;
new_line_after_symbols . noNewLineAfter = [ "port" , "generic" ] ;
let settings = new VHDLFormatter_4 . BeautifierSettings ( false , false , false , false , false , "uppercase" , " " , new_line_after_symbols ) ;
let inputs = [
"TYPE SharedCounter IS PROTECTED" ,
"PROCEDURE increment (N : INTEGER := 1);" ,
"IMPURE FUNCTION value RETURN INTEGER;" ,
"END PROTECTED SharedCounter;"
] ;
let expected = [
new VHDLFormatter_9 . FormattedLine ( "TYPE SharedCounter IS PROTECTED" , 0 ) ,
new VHDLFormatter_9 . FormattedLine ( "PROCEDURE increment (N : INTEGER := 1);" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "IMPURE FUNCTION value RETURN INTEGER;" , 1 ) ,
new VHDLFormatter_9 . FormattedLine ( "END PROTECTED SharedCounter;" , 0 )
] ;
UnitTest6 ( VHDLFormatter_8 . beautify3 , "package" , settings , inputs , expected , 0 , expected . length - 1 , 0 ) ;
}
function UnitTestSetNewLinesAfterSymbols ( ) {
function UnitTestSetNewLinesAfterSymbols ( ) {
console . log ( "=== SetNewLinesAfterSymbols ===" ) ;
console . log ( "=== SetNewLinesAfterSymbols ===" ) ;
let input = "a; @@comments1\r\nb;" ;
let input = "a; @@comments1\r\nb;" ;
@ -183,24 +403,30 @@ function UnitTestIndentDecode() {
UnitTest2 ( VHDLFormatter_2 . indentDecode , "4 blankspaces" , " " , "four blankspace" ) ;
UnitTest2 ( VHDLFormatter_2 . indentDecode , "4 blankspaces" , " " , "four blankspace" ) ;
UnitTest2 ( VHDLFormatter_2 . indentDecode , "9 blankspaces" , " " , "many blankspace" ) ;
UnitTest2 ( VHDLFormatter_2 . indentDecode , "9 blankspaces" , " " , "many blankspace" ) ;
}
}
function assertFormattedLines ( testName , expected , actual , message , cumulateTestCount ) {
function compareFormattedLines ( expected , actual , message ) {
var l = Math . min ( actual . length , expected . length ) ;
var l = Math . min ( actual . length , expected . length ) ;
let result = "" ;
let result = "" ;
for ( var i = 0 ; i < l ; i ++ ) {
for ( var i = 0 ; i < l ; i ++ ) {
if ( actual [ i ] instanceof VHDLFormatter_9 . FormattedLine ) {
if ( actual [ i ] instanceof VHDLFormatter_9 . FormattedLine ) {
if ( expected [ i ] instanceof VHDLFormatter_9 . FormattedLine ) {
if ( expected [ i ] instanceof VHDLFormatter_9 . FormattedLine ) {
assertFormattedLine ( testName , ( expected [ i ] ) , ( actual [ i ] ) , message , false ) ;
let compareResult = compareFormattedLine ( ( expected [ i ] ) , ( actual [ i ] ) , message , false ) ;
if ( compareResult . length > 0 ) {
result += "index " + i + "\n" + compareResult ;
}
}
}
else {
else {
console . log ( "expected FormatLine[], actual FormattedLine. actual:" + ( actual [ i ] ) . Line ) ;
result += "index " + i + "\n expected FormatLine[], actual FormattedLine. actual:" + ( actual [ i ] ) . Line ;
}
}
}
}
else {
else {
if ( expected [ i ] instanceof VHDLFormatter_9 . FormattedLine ) {
if ( expected [ i ] instanceof VHDLFormatter_9 . FormattedLine ) {
console . log ( " expected FormatLine, actual FormattedLine[]. expected:" + ( expected [ i ] ) . Line ) ;
result += "index " + i + "\n expected FormatLine, actual FormattedLine[]. expected:" + ( expected [ i ] ) . Line ;
}
}
else {
else {
assertFormattedLines ( testName , ( actual [ i ] ) , ( expected [ i ] ) , message , false ) ;
let compareResult = compareFormattedLines ( ( actual [ i ] ) , ( expected [ i ] ) , message ) ;
if ( compareResult . length > 0 ) {
result += "index " + i + "\n" + compareResult ;
}
}
}
}
}
}
}
@ -216,28 +442,26 @@ function assertFormattedLines(testName, expected, actual, message, cumulateTestC
result += "expected[" + i + "] = " + expected [ i ] ;
result += "expected[" + i + "] = " + expected [ i ] ;
}
}
}
}
return result ;
}
function assertFormattedLines ( testName , expected , actual , message ) {
let result = compareFormattedLines ( expected , actual , message ) ;
if ( result . length > 0 ) {
if ( result . length > 0 ) {
console . log ( result ) ;
}
if ( cumulateTestCount != false ) {
testCount ++ ;
console . log ( testName + " failed:\n" + result ) ;
}
}
testCount ++ ;
}
}
function assertFormattedLine ( testName , expected , actual , message , cumulateTestCount ) {
function compareFormattedLine ( expected , actual , message , cumulateTestCount ) {
let result = "" ;
if ( expected . Indent != actual . Indent ) {
if ( expected . Indent != actual . Indent ) {
console . log ( testName + ' failed:\nexpected: "' + expected . Line + '", ' + expected . Indent
+ ';\nactual: "' + actual . Line + '", ' + actual . Indent ) ;
}
var result = CompareString ( actual . Line , expected . Line ) ;
if ( result != true ) {
console . log ( testName + " failed: " + result ) ;
}
else {
//console.log(testName + " pass");
result += 'indents are not equal;\nexpected: "' + expected . Line + '", ' + expected . Indent
+ ';\nactual: "' + actual . Line + '", ' + actual . Indent + "\n" ;
}
}
if ( cumulateTestCount != false ) {
testCount ++ ;
let compareResult = CompareString ( actual . Line , expected . Line ) ;
if ( compareResult != true ) {
result += compareResult ;
}
}
return result ;
}
}
function assert ( testName , expected , actual , message ) {
function assert ( testName , expected , actual , message ) {
var result = CompareString ( actual , expected ) ;
var result = CompareString ( actual , expected ) ;