You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

738 lines
40 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const VHDLFormatter_1 = require("./VHDLFormatter");
  4. const VHDLFormatter_2 = require("./VHDLFormatter");
  5. const VHDLFormatter_3 = require("./VHDLFormatter");
  6. const VHDLFormatter_4 = require("./VHDLFormatter");
  7. const VHDLFormatter_5 = require("./VHDLFormatter");
  8. const VHDLFormatter_6 = require("./VHDLFormatter");
  9. const VHDLFormatter_7 = require("./VHDLFormatter");
  10. const VHDLFormatter_8 = require("./VHDLFormatter");
  11. const VHDLFormatter_9 = require("./VHDLFormatter");
  12. const VHDLFormatter_10 = require("./VHDLFormatter");
  13. let testCount = 0;
  14. var showUnitTests = true; //window.location.href.indexOf("http") < 0;
  15. if (showUnitTests) {
  16. testCount = 0;
  17. UnitTest();
  18. UnitTestIndentDecode();
  19. UnitTestRemoveAsserts();
  20. UnitTestApplyNoNewLineAfter();
  21. UnitTestSetNewLinesAfterSymbols();
  22. UnitTestFormattedLineToString();
  23. UnitTestbeautify3();
  24. console.log("total tests: " + testCount);
  25. }
  26. function UnitTestFormattedLineToString() {
  27. console.log("=== FormattedLineToString ===");
  28. FormattedLineToStringCase1();
  29. FormattedLineToStringCase2();
  30. }
  31. function FormattedLineToStringCase1() {
  32. let inputs = [
  33. new VHDLFormatter_9.FormattedLine("a;", 0),
  34. new VHDLFormatter_9.FormattedLine("b;", 0)
  35. ];
  36. let expected = ["a;", "b;"];
  37. UnitTest7(VHDLFormatter_10.FormattedLineToString, "General", " ", inputs, expected);
  38. }
  39. function FormattedLineToStringCase2() {
  40. let inputs = [
  41. new VHDLFormatter_9.FormattedLine("a;", 1),
  42. new VHDLFormatter_9.FormattedLine("b;", 2)
  43. ];
  44. let expected = [" a;", " b;"];
  45. UnitTest7(VHDLFormatter_10.FormattedLineToString, "General", " ", inputs, expected);
  46. }
  47. function UnitTestbeautify3() {
  48. console.log("=== beautify3 ===");
  49. Beautify3Case1();
  50. Beautify3Case2();
  51. Beautify3Case3();
  52. Beautify3Case4();
  53. Beautify3Case5();
  54. Beautify3Case6();
  55. Beautify3Case7();
  56. Beautify3Case8();
  57. Beautify3Case9();
  58. Beautify3Case10();
  59. Beautify3Case11();
  60. Beautify3Case12();
  61. Beautify3Case13();
  62. Beautify3Case14();
  63. }
  64. function Beautify3Case1() {
  65. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  66. new_line_after_symbols.newLineAfter = ["then", ";"];
  67. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  68. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  69. let inputs = ["a;", "b;"];
  70. let expected = [new VHDLFormatter_9.FormattedLine("a;", 0), new VHDLFormatter_9.FormattedLine("b;", 0)];
  71. UnitTest6(VHDLFormatter_8.beautify3, "General", settings, inputs, expected, 0, 1, 0);
  72. }
  73. function Beautify3Case2() {
  74. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  75. new_line_after_symbols.newLineAfter = ["then", ";"];
  76. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  77. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  78. let inputs = ["IF x = '1' THEN", "RETURN 1;", "END IF;"];
  79. let expected = [
  80. new VHDLFormatter_9.FormattedLine("IF x = '1' THEN", 0),
  81. new VHDLFormatter_9.FormattedLine("RETURN 1;", 1),
  82. new VHDLFormatter_9.FormattedLine("END IF;", 0)
  83. ];
  84. UnitTest6(VHDLFormatter_8.beautify3, "IF END", settings, inputs, expected, 0, 2, 0);
  85. }
  86. function Beautify3Case3() {
  87. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  88. new_line_after_symbols.newLineAfter = ["then", ";"];
  89. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  90. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  91. let inputs = [
  92. "IF x = '1' THEN",
  93. "RETURN 1;",
  94. "ELSIF x = '0' THEN",
  95. "RETURN 0;",
  96. "ELSE",
  97. "RETURN -1;",
  98. "END IF;"
  99. ];
  100. let expected = [
  101. new VHDLFormatter_9.FormattedLine("IF x = '1' THEN", 0),
  102. new VHDLFormatter_9.FormattedLine("RETURN 1;", 1),
  103. new VHDLFormatter_9.FormattedLine("ELSIF x = '0' THEN", 0),
  104. new VHDLFormatter_9.FormattedLine("RETURN 0;", 1),
  105. new VHDLFormatter_9.FormattedLine("ELSE", 0),
  106. new VHDLFormatter_9.FormattedLine("RETURN -1;", 1),
  107. new VHDLFormatter_9.FormattedLine("END IF;", 0)
  108. ];
  109. UnitTest6(VHDLFormatter_8.beautify3, "if elsif else end", settings, inputs, expected, 0, 6, 0);
  110. }
  111. function Beautify3Case4() {
  112. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  113. new_line_after_symbols.newLineAfter = ["then", ";"];
  114. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  115. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  116. let inputs = ["END"];
  117. let expected = [new VHDLFormatter_9.FormattedLine("END", 0)];
  118. UnitTest6(VHDLFormatter_8.beautify3, "one line END", settings, inputs, expected, 0, 0, 0);
  119. }
  120. function Beautify3Case5() {
  121. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  122. new_line_after_symbols.newLineAfter = ["then", ";"];
  123. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  124. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  125. let inputs = [
  126. "CASE b",
  127. "WHEN 1 =>",
  128. "c <= d;",
  129. "WHEN 2 =>",
  130. "d <= f;",
  131. "END CASE;"
  132. ];
  133. let expected = [
  134. new VHDLFormatter_9.FormattedLine("CASE b", 0),
  135. new VHDLFormatter_9.FormattedLine("WHEN 1 =>", 1),
  136. new VHDLFormatter_9.FormattedLine("c <= d;", 2),
  137. new VHDLFormatter_9.FormattedLine("WHEN 2 =>", 1),
  138. new VHDLFormatter_9.FormattedLine("d <= f;", 2),
  139. new VHDLFormatter_9.FormattedLine("END CASE;", 0)
  140. ];
  141. UnitTest6(VHDLFormatter_8.beautify3, "case when when end", settings, inputs, expected, 0, 5, 0);
  142. }
  143. function Beautify3Case6() {
  144. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  145. new_line_after_symbols.newLineAfter = ["then", ";"];
  146. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  147. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  148. let inputs = [
  149. "CASE b",
  150. "WHEN 1 =>",
  151. "c <= d;",
  152. "CASE b",
  153. "WHEN 1 =>",
  154. "c <= d;",
  155. "WHEN 2 =>",
  156. "d <= f;",
  157. "END CASE;",
  158. "WHEN 2 =>",
  159. "d <= f;",
  160. "END CASE;"
  161. ];
  162. let expected = [
  163. new VHDLFormatter_9.FormattedLine("CASE b", 0),
  164. new VHDLFormatter_9.FormattedLine("WHEN 1 =>", 1),
  165. new VHDLFormatter_9.FormattedLine("c <= d;", 2),
  166. new VHDLFormatter_9.FormattedLine("CASE b", 2),
  167. new VHDLFormatter_9.FormattedLine("WHEN 1 =>", 3),
  168. new VHDLFormatter_9.FormattedLine("c <= d;", 4),
  169. new VHDLFormatter_9.FormattedLine("WHEN 2 =>", 3),
  170. new VHDLFormatter_9.FormattedLine("d <= f;", 4),
  171. new VHDLFormatter_9.FormattedLine("END CASE;", 2),
  172. new VHDLFormatter_9.FormattedLine("WHEN 2 =>", 1),
  173. new VHDLFormatter_9.FormattedLine("d <= f;", 2),
  174. new VHDLFormatter_9.FormattedLine("END CASE;", 0)
  175. ];
  176. UnitTest6(VHDLFormatter_8.beautify3, "case & case end", settings, inputs, expected, 0, 11, 0);
  177. }
  178. function Beautify3Case7() {
  179. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  180. new_line_after_symbols.newLineAfter = ["then", ";"];
  181. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  182. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  183. let inputs = [
  184. "ARCHITECTURE a OF one IS",
  185. "SIGNAL x : INTEGER;",
  186. "BEGIN",
  187. "-- architecture",
  188. "END ARCHITECTURE;"
  189. ];
  190. let expected = [
  191. new VHDLFormatter_9.FormattedLine("ARCHITECTURE a OF one IS", 0),
  192. new VHDLFormatter_9.FormattedLine("SIGNAL x : INTEGER;", 1),
  193. new VHDLFormatter_9.FormattedLine("BEGIN", 0),
  194. new VHDLFormatter_9.FormattedLine("-- architecture", 1),
  195. new VHDLFormatter_9.FormattedLine("END ARCHITECTURE;", 0),
  196. ];
  197. UnitTest6(VHDLFormatter_8.beautify3, "architecture", settings, inputs, expected, 0, 4, 0);
  198. }
  199. function Beautify3Case8() {
  200. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  201. new_line_after_symbols.newLineAfter = ["then", ";"];
  202. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  203. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  204. let inputs = [
  205. "ARCHITECTURE a OF one IS",
  206. "SIGNAL x : INTEGER;",
  207. "BEGIN",
  208. "-- architecture",
  209. "END ARCHITECTURE;",
  210. "ARCHITECTURE b OF one IS",
  211. "SIGNAL x : INTEGER;",
  212. "BEGIN",
  213. "-- architecture",
  214. "END ARCHITECTURE;"
  215. ];
  216. let expected = [
  217. new VHDLFormatter_9.FormattedLine("ARCHITECTURE a OF one IS", 0),
  218. new VHDLFormatter_9.FormattedLine("SIGNAL x : INTEGER;", 1),
  219. new VHDLFormatter_9.FormattedLine("BEGIN", 0),
  220. new VHDLFormatter_9.FormattedLine("-- architecture", 1),
  221. new VHDLFormatter_9.FormattedLine("END ARCHITECTURE;", 0),
  222. new VHDLFormatter_9.FormattedLine("ARCHITECTURE b OF one IS", 0),
  223. new VHDLFormatter_9.FormattedLine("SIGNAL x : INTEGER;", 1),
  224. new VHDLFormatter_9.FormattedLine("BEGIN", 0),
  225. new VHDLFormatter_9.FormattedLine("-- architecture", 1),
  226. new VHDLFormatter_9.FormattedLine("END ARCHITECTURE;", 0),
  227. ];
  228. UnitTest6(VHDLFormatter_8.beautify3, "architecture 2", settings, inputs, expected, 0, 9, 0);
  229. }
  230. function Beautify3Case9() {
  231. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  232. new_line_after_symbols.newLineAfter = ["then", ";"];
  233. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  234. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  235. let inputs = [
  236. "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS",
  237. "VARIABLE i : INTEGER;",
  238. "BEGIN",
  239. "y := x + 1;",
  240. "END PROCEDURE;"
  241. ];
  242. let expected = [
  243. new VHDLFormatter_9.FormattedLine("PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS", 0),
  244. new VHDLFormatter_9.FormattedLine("VARIABLE i : INTEGER;", 1),
  245. new VHDLFormatter_9.FormattedLine("BEGIN", 0),
  246. new VHDLFormatter_9.FormattedLine("y := x + 1;", 1),
  247. new VHDLFormatter_9.FormattedLine("END PROCEDURE;", 0)
  248. ];
  249. UnitTest6(VHDLFormatter_8.beautify3, "procedure", settings, inputs, expected, 0, 4, 0);
  250. }
  251. function Beautify3Case10() {
  252. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  253. new_line_after_symbols.newLineAfter = ["then", ";"];
  254. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  255. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  256. let inputs = [
  257. "PACKAGE three IS",
  258. "SIGNAL s : INTEGER;",
  259. "ALIAS sa IS s;",
  260. "END PACKAGE;"
  261. ];
  262. let expected = [
  263. new VHDLFormatter_9.FormattedLine("PACKAGE three IS", 0),
  264. new VHDLFormatter_9.FormattedLine("SIGNAL s : INTEGER;", 1),
  265. new VHDLFormatter_9.FormattedLine("ALIAS sa IS s;", 1),
  266. new VHDLFormatter_9.FormattedLine("END PACKAGE;", 0)
  267. ];
  268. UnitTest6(VHDLFormatter_8.beautify3, "package", settings, inputs, expected, 0, 3, 0);
  269. }
  270. function Beautify3Case11() {
  271. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  272. new_line_after_symbols.newLineAfter = ["then", ";"];
  273. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  274. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  275. let inputs = [
  276. "PACKAGE p IS",
  277. "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER);",
  278. "END PACKAGE;",
  279. "PACKAGE BODY p IS",
  280. "PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS",
  281. "VARIABLE i : INTEGER;",
  282. "BEGIN",
  283. "y := x + 1;",
  284. "END PROCEDURE;",
  285. "PROCEDURE bar(FILE x : text);",
  286. "PROCEDURE baz IS",
  287. "TYPE foo;",
  288. "ALIAS x IS y;",
  289. "BEGIN",
  290. "END PROCEDURE;",
  291. "PROCEDURE tralala IS",
  292. "USE work.foo;",
  293. "BEGIN",
  294. "END PROCEDURE;",
  295. "END PACKAGE BODY;"
  296. ];
  297. let expected = [
  298. new VHDLFormatter_9.FormattedLine("PACKAGE p IS", 0),
  299. new VHDLFormatter_9.FormattedLine("PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER);", 1),
  300. new VHDLFormatter_9.FormattedLine("END PACKAGE;", 0),
  301. new VHDLFormatter_9.FormattedLine("PACKAGE BODY p IS", 0),
  302. new VHDLFormatter_9.FormattedLine("PROCEDURE foo(x : IN INTEGER; y : OUT INTEGER) IS", 1),
  303. new VHDLFormatter_9.FormattedLine("VARIABLE i : INTEGER;", 2),
  304. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  305. new VHDLFormatter_9.FormattedLine("y := x + 1;", 2),
  306. new VHDLFormatter_9.FormattedLine("END PROCEDURE;", 1),
  307. new VHDLFormatter_9.FormattedLine("PROCEDURE bar(FILE x : text);", 1),
  308. new VHDLFormatter_9.FormattedLine("PROCEDURE baz IS", 1),
  309. new VHDLFormatter_9.FormattedLine("TYPE foo;", 2),
  310. new VHDLFormatter_9.FormattedLine("ALIAS x IS y;", 2),
  311. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  312. new VHDLFormatter_9.FormattedLine("END PROCEDURE;", 1),
  313. new VHDLFormatter_9.FormattedLine("PROCEDURE tralala IS", 1),
  314. new VHDLFormatter_9.FormattedLine("USE work.foo;", 2),
  315. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  316. new VHDLFormatter_9.FormattedLine("END PROCEDURE;", 1),
  317. new VHDLFormatter_9.FormattedLine("END PACKAGE BODY;", 0)
  318. ];
  319. UnitTest6(VHDLFormatter_8.beautify3, "package procedure", settings, inputs, expected, 0, expected.length - 1, 0);
  320. }
  321. function Beautify3Case12() {
  322. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  323. new_line_after_symbols.newLineAfter = ["then", ";"];
  324. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  325. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  326. let inputs = [
  327. "ARCHITECTURE a OF b IS",
  328. "SIGNAL x : INTEGER := 0;",
  329. "BEGIN",
  330. "p: PROCESS IS",
  331. "BEGIN",
  332. "END PROCESS;",
  333. "PROCESS",
  334. "VARIABLE y : INTEGER := 5;",
  335. "BEGIN",
  336. "x <= y;",
  337. "END PROCESS;",
  338. "PROCESS (x) IS",
  339. "BEGIN",
  340. "x <= x + 1;",
  341. "END PROCESS;",
  342. "POSTPONED PROCESS IS",
  343. "BEGIN",
  344. "END PROCESS;",
  345. "POSTPONED assert x = 1;",
  346. "END ARCHITECTURE;"
  347. ];
  348. let expected = [
  349. new VHDLFormatter_9.FormattedLine("ARCHITECTURE a OF b IS", 0),
  350. new VHDLFormatter_9.FormattedLine("SIGNAL x : INTEGER := 0;", 1),
  351. new VHDLFormatter_9.FormattedLine("BEGIN", 0),
  352. new VHDLFormatter_9.FormattedLine("p: PROCESS IS", 1),
  353. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  354. new VHDLFormatter_9.FormattedLine("END PROCESS;", 1),
  355. new VHDLFormatter_9.FormattedLine("PROCESS", 1),
  356. new VHDLFormatter_9.FormattedLine("VARIABLE y : INTEGER := 5;", 2),
  357. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  358. new VHDLFormatter_9.FormattedLine("x <= y;", 2),
  359. new VHDLFormatter_9.FormattedLine("END PROCESS;", 1),
  360. new VHDLFormatter_9.FormattedLine("PROCESS (x) IS", 1),
  361. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  362. new VHDLFormatter_9.FormattedLine("x <= x + 1;", 2),
  363. new VHDLFormatter_9.FormattedLine("END PROCESS;", 1),
  364. new VHDLFormatter_9.FormattedLine("POSTPONED PROCESS IS", 1),
  365. new VHDLFormatter_9.FormattedLine("BEGIN", 1),
  366. new VHDLFormatter_9.FormattedLine("END PROCESS;", 1),
  367. new VHDLFormatter_9.FormattedLine("POSTPONED assert x = 1;", 1),
  368. new VHDLFormatter_9.FormattedLine("END ARCHITECTURE;", 0)
  369. ];
  370. UnitTest6(VHDLFormatter_8.beautify3, "package postponed procedure", settings, inputs, expected, 0, expected.length - 1, 0);
  371. }
  372. function Beautify3Case13() {
  373. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  374. new_line_after_symbols.newLineAfter = ["then", ";"];
  375. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  376. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  377. let inputs = [
  378. "TYPE SharedCounter IS PROTECTED",
  379. "PROCEDURE increment (N : INTEGER := 1);",
  380. "IMPURE FUNCTION value RETURN INTEGER;",
  381. "END PROTECTED SharedCounter;"
  382. ];
  383. let expected = [
  384. new VHDLFormatter_9.FormattedLine("TYPE SharedCounter IS PROTECTED", 0),
  385. new VHDLFormatter_9.FormattedLine("PROCEDURE increment (N : INTEGER := 1);", 1),
  386. new VHDLFormatter_9.FormattedLine("IMPURE FUNCTION value RETURN INTEGER;", 1),
  387. new VHDLFormatter_9.FormattedLine("END PROTECTED SharedCounter;", 0)
  388. ];
  389. UnitTest6(VHDLFormatter_8.beautify3, "type projected", settings, inputs, expected, 0, expected.length - 1, 0);
  390. }
  391. function Beautify3Case14() {
  392. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  393. new_line_after_symbols.newLineAfter = ["then", ";"];
  394. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  395. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  396. let inputs = [
  397. "PACKAGE p IS",
  398. "TYPE SharedCounter IS PROTECTED",
  399. "PROCEDURE increment (N : INTEGER := 1);",
  400. "IMPURE FUNCTION value RETURN INTEGER;",
  401. "END PROTECTED SharedCounter;",
  402. "TYPE SharedCounter IS PROTECTED BODY"
  403. ];
  404. let expected = [
  405. new VHDLFormatter_9.FormattedLine("PACKAGE p IS", 0),
  406. new VHDLFormatter_9.FormattedLine("TYPE SharedCounter IS PROTECTED", 1),
  407. new VHDLFormatter_9.FormattedLine("PROCEDURE increment (N : INTEGER := 1);", 2),
  408. new VHDLFormatter_9.FormattedLine("IMPURE FUNCTION value RETURN INTEGER;", 2),
  409. new VHDLFormatter_9.FormattedLine("END PROTECTED SharedCounter;", 1),
  410. new VHDLFormatter_9.FormattedLine("TYPE SharedCounter IS PROTECTED BODY", 1)
  411. ];
  412. UnitTest6(VHDLFormatter_8.beautify3, "type projected", settings, inputs, expected, 0, expected.length - 1, 0);
  413. }
  414. function UnitTestSetNewLinesAfterSymbols() {
  415. console.log("=== SetNewLinesAfterSymbols ===");
  416. let input = "a; @@comments1\r\nb;";
  417. let expected = "a; @@comments1\r\nb;";
  418. let parameters = new VHDLFormatter_3.NewLineSettings();
  419. parameters.newLineAfter = ["then", ";"];
  420. parameters.noNewLineAfter = ["port", "generic"];
  421. UnitTest5(VHDLFormatter_7.SetNewLinesAfterSymbols, "no new line after comment", parameters, input, expected);
  422. input = "a; b;";
  423. expected = "a;\r\nb;";
  424. UnitTest5(VHDLFormatter_7.SetNewLinesAfterSymbols, "new line after ;", parameters, input, expected);
  425. }
  426. function UnitTestApplyNoNewLineAfter() {
  427. console.log("=== ApplyNoNewLineAfter ===");
  428. let input = ["a;", "b;"];
  429. let expected = ["a;@@singleline", "b;@@singleline"];
  430. let parameters = [";"];
  431. UnitTest4(VHDLFormatter_6.ApplyNoNewLineAfter, "one blankspace", parameters, input, expected);
  432. input = ["a;", "b THEN", "c"];
  433. expected = ["a;@@singleline", "b THEN@@singleline", "c"];
  434. parameters = [";", "then"];
  435. UnitTest4(VHDLFormatter_6.ApplyNoNewLineAfter, "one blankspace", parameters, input, expected);
  436. }
  437. function UnitTestRemoveAsserts() {
  438. console.log("=== RemoveAsserts ===");
  439. let input = ["ASSERT a;"];
  440. let expected = [""];
  441. UnitTest3(VHDLFormatter_5.RemoveAsserts, "one assert", input, expected);
  442. input = ["ASSERT a", "b;", "c"];
  443. expected = ["", "", "c"];
  444. UnitTest3(VHDLFormatter_5.RemoveAsserts, "multiline assert", input, expected);
  445. }
  446. function UnitTestIndentDecode() {
  447. console.log("=== IndentDecode ===");
  448. UnitTest2(VHDLFormatter_2.indentDecode, "one blankspace", " ", "one blankspace");
  449. UnitTest2(VHDLFormatter_2.indentDecode, "mixed chars", " A ", "one blankspace & one A & one blankspace");
  450. UnitTest2(VHDLFormatter_2.indentDecode, "4 blankspaces", " ", "four blankspace");
  451. UnitTest2(VHDLFormatter_2.indentDecode, "9 blankspaces", " ", "many blankspace");
  452. }
  453. function compareFormattedLines(expected, actual, message) {
  454. var l = Math.min(actual.length, expected.length);
  455. let result = "";
  456. for (var i = 0; i < l; i++) {
  457. if (actual[i] instanceof VHDLFormatter_9.FormattedLine) {
  458. if (expected[i] instanceof VHDLFormatter_9.FormattedLine) {
  459. let compareResult = compareFormattedLine((expected[i]), (actual[i]), message, false);
  460. if (compareResult.length > 0) {
  461. result += "index " + i + "\n" + compareResult;
  462. }
  463. }
  464. else {
  465. result += "index " + i + "\nexpected FormatLine[], actual FormattedLine. actual:" + (actual[i]).Line;
  466. }
  467. }
  468. else {
  469. if (expected[i] instanceof VHDLFormatter_9.FormattedLine) {
  470. result += "index " + i + "\nexpected FormatLine, actual FormattedLine[]. expected:" + (expected[i]).Line;
  471. }
  472. else {
  473. let compareResult = compareFormattedLines((actual[i]), (expected[i]), message);
  474. if (compareResult.length > 0) {
  475. result += "index " + i + "\n" + compareResult;
  476. }
  477. }
  478. }
  479. }
  480. if (actual.length > expected.length) {
  481. result += "actual has more items";
  482. for (var i = expected.length; i < actual.length; i++) {
  483. result += "actual[" + i + "] = " + actual[i];
  484. }
  485. }
  486. else if (actual.length < expected.length) {
  487. result += "expected has more items";
  488. for (var i = actual.length; i < expected.length; i++) {
  489. result += "expected[" + i + "] = " + expected[i];
  490. }
  491. }
  492. return result;
  493. }
  494. function assertFormattedLines(testName, expected, actual, message) {
  495. let result = compareFormattedLines(expected, actual, message);
  496. if (result.length > 0) {
  497. console.log(testName + " failed:\n" + result);
  498. }
  499. testCount++;
  500. }
  501. function compareFormattedLine(expected, actual, message, cumulateTestCount) {
  502. let result = "";
  503. if (expected.Indent != actual.Indent) {
  504. result += 'indents are not equal;\nexpected: "' + expected.Line + '", ' + expected.Indent
  505. + ';\nactual: "' + actual.Line + '", ' + actual.Indent + "\n";
  506. }
  507. let compareResult = CompareString(actual.Line, expected.Line);
  508. if (compareResult != true) {
  509. result += compareResult;
  510. }
  511. return result;
  512. }
  513. function assert(testName, expected, actual, message) {
  514. var result = CompareString(actual, expected);
  515. if (result != true) {
  516. console.log(testName + " failed: \n" + result);
  517. }
  518. else {
  519. //console.log(testName + " pass");
  520. }
  521. testCount++;
  522. }
  523. function assertArray(testName, expected, actual, message) {
  524. var result = CompareArray(actual, expected);
  525. if (result != true) {
  526. console.log(testName + " failed: " + result);
  527. }
  528. else {
  529. //console.log(testName + " pass");
  530. }
  531. testCount++;
  532. }
  533. function UnitTest7(func, testName, indentation, inputs, expected) {
  534. let actual = func(inputs, indentation);
  535. assertArray(testName, expected, actual);
  536. }
  537. function UnitTest6(func, testName, parameters, inputs, expected, startIndex, expectedEndIndex, indent) {
  538. let actual = [];
  539. let endIndex = func(inputs, actual, parameters, startIndex, indent);
  540. if (endIndex != expectedEndIndex) {
  541. console.log(testName + " failed;\nend index, actual: " + endIndex + "; expected: " + expectedEndIndex);
  542. }
  543. assertFormattedLines(testName, expected, actual);
  544. }
  545. function UnitTest5(func, testName, parameters, inputs, expected) {
  546. let actual = func(inputs, parameters);
  547. assert(testName, expected, actual);
  548. }
  549. function UnitTest4(func, testName, parameters, inputs, expected) {
  550. let actual = JSON.parse(JSON.stringify(inputs));
  551. func(actual, parameters);
  552. assertArray(testName, expected, actual);
  553. }
  554. function UnitTest3(func, testName, inputs, expected) {
  555. let actual = JSON.parse(JSON.stringify(inputs));
  556. func(actual);
  557. assertArray(testName, expected, actual);
  558. }
  559. function UnitTest2(func, testName, inputs, expected) {
  560. let actual = func(inputs);
  561. assert(testName, expected, actual);
  562. }
  563. function deepCopy(objectToCopy) {
  564. return (JSON.parse(JSON.stringify(objectToCopy)));
  565. }
  566. function UnitTest() {
  567. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  568. new_line_after_symbols.newLineAfter = ["then", ";"];
  569. new_line_after_symbols.noNewLineAfter = ["port", "generic"];
  570. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  571. 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;";
  572. 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;";
  573. let actual = VHDLFormatter_1.beautify(input, settings);
  574. assert("General", expected, actual);
  575. IntegrationTest2();
  576. let new_line_after_symbols_2 = new VHDLFormatter_3.NewLineSettings();
  577. new_line_after_symbols_2.newLineAfter = [];
  578. new_line_after_symbols_2.noNewLineAfter = ["then", ";", "generic", "port"];
  579. let newSettings = deepCopy(settings);
  580. newSettings.NewLineSettings = new_line_after_symbols_2;
  581. expected = "a; b; c;";
  582. input = "a; \r\nb;\r\n c;";
  583. actual = VHDLFormatter_1.beautify(input, newSettings);
  584. assert("Remove line after ;", expected, actual);
  585. newSettings = deepCopy(settings);
  586. newSettings.RemoveAsserts = true;
  587. input = "architecture arch of ent is\r\nbegin\r\n assert False report sdfjcsdfcsdj;\r\n assert False report sdfjcsdfcsdj severity note;\r\nend architecture;";
  588. expected = "ARCHITECTURE arch OF ent IS\r\nBEGIN\r\nEND ARCHITECTURE;";
  589. actual = VHDLFormatter_1.beautify(input, newSettings);
  590. assert("Remove asserts", expected, actual);
  591. input = "entity TB_DISPLAY is\r\n-- port declarations\r\nend TB_DISPLAY;\r\n\r\narchitecture TEST of TB_DISPLAY is\r\n-- signal declarations\r\nbegin\r\n-- component instance(s)\r\nend TEST;";
  592. expected = "ENTITY TB_DISPLAY IS\r\n -- port declarations\r\nEND TB_DISPLAY;\r\n\r\nARCHITECTURE TEST OF TB_DISPLAY IS\r\n -- signal declarations\r\nBEGIN\r\n -- component instance(s)\r\nEND TEST;";
  593. actual = VHDLFormatter_1.beautify(input, settings);
  594. assert("ENTITY ARCHITECTURE", expected, actual);
  595. IntegrationTest5();
  596. IntegrationTest6();
  597. IntegrationTest7();
  598. input = 'if a(3 downto 0) > "0100" then\r\na(3 downto 0) := a(3 downto 0) + "0011" ;\r\nend if ;';
  599. expected = 'IF a(3 DOWNTO 0) > "0100" THEN\r\n a(3 DOWNTO 0) := a(3 DOWNTO 0) + "0011";\r\nEND IF;';
  600. actual = VHDLFormatter_1.beautify(input, settings);
  601. assert("IF END IF case 1", expected, actual);
  602. input = "if s = '1' then\r\no <= \"010\";\r\nelse\r\no <= \"101\";\r\nend if;";
  603. expected = "IF s = '1' THEN\r\n o <= \"010\";\r\nELSE\r\n o <= \"101\";\r\nEND IF;";
  604. actual = VHDLFormatter_1.beautify(input, settings);
  605. assert("IF ELSE END IF case 1", expected, actual);
  606. newSettings = deepCopy(settings);
  607. newSettings.NewLineSettings.newLineAfter.push("ELSE");
  608. input = "IF (s = r) THEN rr := '0'; ELSE rr := '1'; END IF;";
  609. expected = "IF (s = r) THEN\r\n rr := '0';\r\nELSE\r\n rr := '1';\r\nEND IF;";
  610. actual = VHDLFormatter_1.beautify(input, newSettings);
  611. assert("IF ELSE END IF case 2", expected, actual);
  612. input = 'P1:process\r\nvariable x: Integer range 1 to 3;\r\nvariable y: BIT_VECTOR (0 to 1);\r\nbegin\r\n C1: case x is\r\n when 1 => Out_1 <= 0;\r\n when 2 => Out_1 <= 1;\r\n end case C1;\r\n C2: case y is\r\n when "00" => Out_2 <= 0;\r\n when "01" => Out_2 <= 1;\r\n end case C2;\r\nend process;';
  613. expected = 'P1 : PROCESS\r\n VARIABLE x : INTEGER RANGE 1 TO 3;\r\n VARIABLE y : BIT_VECTOR (0 TO 1);\r\nBEGIN\r\n C1 : CASE x IS\r\n WHEN 1 => Out_1 <= 0;\r\n WHEN 2 => Out_1 <= 1;\r\n END CASE C1;\r\n C2 : CASE y IS\r\n WHEN "00" => Out_2 <= 0;\r\n WHEN "01" => Out_2 <= 1;\r\n END CASE C2;\r\nEND PROCESS;';
  614. actual = VHDLFormatter_1.beautify(input, settings);
  615. assert("WHEN CASE", expected, actual);
  616. input = "case READ_CPU_STATE is\r\n when WAITING =>\r\n if CPU_DATA_VALID = '1' then\r\n CPU_DATA_READ <= '1';\r\n READ_CPU_STATE <= DATA1;\r\n end if;\r\n when DATA1 =>\r\n -- etc.\r\nend case;";
  617. expected = "CASE READ_CPU_STATE IS\r\n WHEN WAITING =>\r\n IF CPU_DATA_VALID = '1' THEN\r\n CPU_DATA_READ <= '1';\r\n READ_CPU_STATE <= DATA1;\r\n END IF;\r\n WHEN DATA1 =>\r\n -- etc.\r\nEND CASE;";
  618. actual = VHDLFormatter_1.beautify(input, settings);
  619. assert("WHEN CASE & IF", expected, actual);
  620. input = "entity aa is\r\n port (a : in std_logic;\r\n b : in std_logic;\r\n );\r\nend aa;\r\narchitecture bb of aa is\r\n component cc\r\n port(\r\n a : in std_logic;\r\n b : in std_logic;\r\n );\r\n end cc;\r\n\r\nbegin\r\n C : cc port map (\r\n long => a,\r\n b => b\r\n );\r\nend;";
  621. expected = "ENTITY aa IS\r\n PORT (\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n );\r\nEND aa;\r\nARCHITECTURE bb OF aa IS\r\n COMPONENT cc\r\n PORT (\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n );\r\n END cc;\r\n\r\nBEGIN\r\n C : cc PORT MAP(\r\n long => a,\r\n b => b\r\n );\r\nEND;";
  622. actual = VHDLFormatter_1.beautify(input, settings);
  623. assert("PORT MAP", expected, actual);
  624. input = "entity aa is\r\n port (a : in std_logic;\r\n b : in std_logic;\r\n );\r\n port (a : in std_logic;\r\n b : in std_logic;\r\n );\r\nend aa;\r\narchitecture bb of aa is\r\n component cc\r\n port(\r\n a : in std_logic;\r\n b : in std_logic;\r\n );\r\n port(\r\n a : in std_logic;\r\n b : in std_logic;\r\n );\r\n end cc;\r\n\r\nbegin\r\n C : cc port map (\r\n long => a,\r\n b => b\r\n );\r\n D : cc port map (\r\n long => a,\r\n b => b\r\n );\r\nend;";
  625. expected = "ENTITY aa IS\r\n PORT (\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n );\r\n PORT (\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n );\r\nEND aa;\r\nARCHITECTURE bb OF aa IS\r\n COMPONENT cc\r\n PORT (\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n );\r\n PORT (\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n );\r\n END cc;\r\n\r\nBEGIN\r\n C : cc PORT MAP(\r\n long => a,\r\n b => b\r\n );\r\n D : cc PORT MAP(\r\n long => a,\r\n b => b\r\n );\r\nEND;";
  626. actual = VHDLFormatter_1.beautify(input, settings);
  627. assert("Multiple PORT MAPs", expected, actual);
  628. input = "port (a : in std_logic;\r\n b : in std_logic;\r\n);";
  629. expected = "PORT\r\n(\r\n a : IN std_logic;\r\n b : IN std_logic;\r\n);";
  630. new_line_after_symbols_2 = new VHDLFormatter_3.NewLineSettings();
  631. new_line_after_symbols_2.newLineAfter = ["then", ";", "generic", "port"];
  632. newSettings = deepCopy(settings);
  633. newSettings.NewLineSettings = new_line_after_symbols_2;
  634. actual = VHDLFormatter_1.beautify(input, newSettings);
  635. assert("New line after PORT", expected, actual);
  636. newSettings = deepCopy(settings);
  637. newSettings.NewLineSettings.newLineAfter = [];
  638. input = "component a is\r\nport( Data : inout Std_Logic_Vector(7 downto 0););\r\nend component a;";
  639. expected = "COMPONENT a IS\r\n PORT (Data : INOUT Std_Logic_Vector(7 DOWNTO 0););\r\nEND COMPONENT a;";
  640. actual = VHDLFormatter_1.beautify(input, newSettings);
  641. assert("New line after PORT (single line)", expected, actual);
  642. input = "process xyx (vf,fr,\r\nde -- comment\r\n)";
  643. expected = "PROCESS xyx (vf, fr, \r\n de -- comment\r\n )";
  644. actual = VHDLFormatter_1.beautify(input, newSettings);
  645. assert("Align parameters in PROCESS", expected, actual);
  646. input = "architecture a of b is\r\nbegin\r\n process (w)\r\n variable t : std_logic_vector (4 downto 0) ;\r\nbegin\r\n a := (others => '0') ;\r\nend process ;\r\nend a;";
  647. expected = "ARCHITECTURE a OF b IS\r\nBEGIN\r\n PROCESS (w)\r\n VARIABLE t : std_logic_vector (4 DOWNTO 0);\r\n BEGIN\r\n a := (OTHERS => '0');\r\n END PROCESS;\r\nEND a;";
  648. actual = VHDLFormatter_1.beautify(input, newSettings);
  649. assert("Double BEGIN", expected, actual);
  650. let newSettings2 = deepCopy(newSettings);
  651. newSettings2.SignAlignAll = true;
  652. input = "entity a is\r\n port ( w : in std_logic_vector (7 downto 0) ;\r\n w_s : out std_logic_vector (3 downto 0) ; ) ;\r\nend a ;\r\narchitecture b of a is\r\nbegin\r\n process ( w )\r\n variable t : std_logic_vector (4 downto 0) ;\r\n variable bcd : std_logic_vector (11 downto 0) ;\r\nbegin\r\n b(2 downto 0) := w(7 downto 5) ;\r\n t := w(4 downto 0) ;\r\n w_s <= b(11 downto 8) ;\r\n w <= b(3 downto 0) ;\r\nend process ;\r\nend b ;";
  653. expected = "ENTITY a IS\r\n PORT\r\n (\r\n w : IN std_logic_vector (7 DOWNTO 0);\r\n w_s : OUT std_logic_vector (3 DOWNTO 0); \r\n );\r\nEND a;\r\nARCHITECTURE b OF a IS\r\nBEGIN\r\n PROCESS (w)\r\n VARIABLE t : std_logic_vector (4 DOWNTO 0);\r\n VARIABLE bcd : std_logic_vector (11 DOWNTO 0);\r\n BEGIN\r\n b(2 DOWNTO 0) := w(7 DOWNTO 5);\r\n t := w(4 DOWNTO 0);\r\n w_s <= b(11 DOWNTO 8);\r\n w <= b(3 DOWNTO 0);\r\n END PROCESS;\r\nEND b;";
  654. actual = VHDLFormatter_1.beautify(input, newSettings2);
  655. assert("Align signs in all places", expected, actual);
  656. }
  657. function IntegrationTest5() {
  658. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  659. new_line_after_symbols.newLineAfter = ["then", ";"];
  660. new_line_after_symbols.noNewLineAfter = ["generic"];
  661. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  662. settings.SignAlignRegional = true;
  663. let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);";
  664. let expected = "PORT MAP(\r\n input_1 => input_1_sig,\r\n input_2 => input_2_sig,\r\n output => output_sig\r\n);";
  665. let actual = VHDLFormatter_1.beautify(input, settings);
  666. assert("Sign align in PORT", expected, actual);
  667. }
  668. function IntegrationTest6() {
  669. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  670. new_line_after_symbols.newLineAfter = ["then", ";", "port map"];
  671. new_line_after_symbols.noNewLineAfter = ["generic"];
  672. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  673. settings.SignAlignRegional = true;
  674. let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);";
  675. let expected = "PORT MAP\r\n(\r\n input_1 => input_1_sig,\r\n input_2 => input_2_sig,\r\n output => output_sig\r\n);";
  676. let actual = VHDLFormatter_1.beautify(input, settings);
  677. assert("Sign align in PORT & new line after MAP", expected, actual);
  678. }
  679. function IntegrationTest7() {
  680. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  681. new_line_after_symbols.newLineAfter = ["then", ";"];
  682. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  683. settings.SignAlignRegional = true;
  684. 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;";
  685. let expected = "ENTITY p IS\r\n GENERIC (\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 inclk0 : IN std_logic := '0';\r\n c0 : OUT std_logic;\r\n c1 : OUT std_logic\r\n );\r\nEND pll;";
  686. let actual = VHDLFormatter_1.beautify(input, settings);
  687. assert("Sign align in PORT & GENERIC", expected, actual);
  688. }
  689. function IntegrationTest2() {
  690. let new_line_after_symbols = new VHDLFormatter_3.NewLineSettings();
  691. new_line_after_symbols.newLineAfter = ["then", ";"];
  692. new_line_after_symbols.noNewLineAfter = ["generic"];
  693. let settings = new VHDLFormatter_4.BeautifierSettings(false, false, false, false, false, "uppercase", " ", new_line_after_symbols);
  694. settings.RemoveComments = true;
  695. 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;";
  696. 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;";
  697. let actual = VHDLFormatter_1.beautify(input, settings);
  698. assert("Remove comments", expected, actual);
  699. }
  700. function CompareString(actual, expected) {
  701. var l = Math.min(actual.length, expected.length);
  702. for (var i = 0; i < l; i++) {
  703. if (actual[i] != expected[i]) {
  704. var toEnd = Math.min(i + 50, l);
  705. return '\ndifferent at ' + i.toString() +
  706. '\nactual: "\n' + actual.substring(i, toEnd) +
  707. '\nexpected: "\n' + expected.substring(i, toEnd) + '"\n---' +
  708. "\nactual (full): \n" + actual + "\n---" +
  709. "\nexpected (full): \n" + expected + "\n====\n";
  710. }
  711. }
  712. if (actual != expected) {
  713. return 'actual: \n"' + actual + '"\nexpected: \n"' + expected + '"';
  714. }
  715. return true;
  716. }
  717. function CompareArray(actual, expected) {
  718. var l = Math.min(actual.length, expected.length);
  719. let result = "";
  720. for (var i = 0; i < l; i++) {
  721. if (actual[i] != expected[i]) {
  722. result += CompareString(actual[i], expected[i]) + "\n";
  723. }
  724. }
  725. if (actual.length > expected.length) {
  726. result += "actual has more items";
  727. for (var i = expected.length; i < actual.length; i++) {
  728. result += "actual[" + i + "] = " + actual[i];
  729. }
  730. }
  731. else if (actual.length < expected.length) {
  732. result += "expected has more items";
  733. for (var i = actual.length; i < expected.length; i++) {
  734. result += "expected[" + i + "] = " + expected[i];
  735. }
  736. }
  737. return true;
  738. }
  739. //# sourceMappingURL=VHDLFormatterUnitTests.js.map