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.

80 lines
3.3 KiB

  1. import { beautify, signAlignSettings } from "../VHDLFormatter";
  2. import { NewLineSettings } from "../VHDLFormatter";
  3. import { BeautifierSettings } from "../VHDLFormatter";
  4. import { RemoveAsserts } from "../VHDLFormatter";
  5. import { ApplyNoNewLineAfter } from "../VHDLFormatter";
  6. import { SetNewLinesAfterSymbols } from "../VHDLFormatter";
  7. import { beautify3 } from "../VHDLFormatter";
  8. import { FormattedLine } from "../VHDLFormatter";
  9. import { FormattedLineToString } from "../VHDLFormatter";
  10. describe('VHDLFormatter', function () {
  11. it('do not format block comments', function () {
  12. let settings = GetDefaultSettings();
  13. let input = 'a;\r\n/*a; \r\n b;\r\nport ( ) ;\r\n/*\r\n*/c;';
  14. let result = beautify(input, settings);
  15. expect(result).toBe(input);
  16. });
  17. it('do not format block comments 2', function () {
  18. let settings = GetDefaultSettings();
  19. let input = 'a;/*a;*/b;\r\nc;';
  20. let result = beautify(input, settings);
  21. expect(result).toBe(input);
  22. });
  23. it('do not format block comments 3', function () {
  24. let settings = GetDefaultSettings();
  25. let input = 'a;\r\n/*a;*//*\r\n*/c;';
  26. let result = beautify(input, settings);
  27. expect(result).toBe(input);
  28. });
  29. it('do not format block comments 4', function () {
  30. let settings = GetDefaultSettings();
  31. let input = '/*\r\nwoof\r\n*//*\r\nwoof\r\n*//*\r\nwoof\r\n*/';
  32. let result = beautify(input, settings);
  33. expect(result).toBe(input);
  34. });
  35. it('add new line at the end of the file', function () {
  36. let settings = GetDefaultSettings();
  37. settings.AddNewLine = true;
  38. let input = 'test';
  39. let result = beautify(input, settings);
  40. expect(result).toBe("test\r\n");
  41. });
  42. it('upper case types', function () {
  43. let settings = GetDefaultSettings();
  44. let input = "x : string;\r\ny : std_logic_vector;";
  45. let result = beautify(input, settings);
  46. expect(result).toBe("x : STRING;\r\ny : STD_LOGIC_VECTOR;");
  47. });
  48. it('package ends with ;', function () {
  49. let settings = GetDefaultSettings();
  50. let input = "PACKAGE p IS NEW work.p_template\r\n GENERIC MAP(N => N);\r\nUSE p.ALL;";
  51. let result = beautify(input, settings);
  52. expect(result).toBe(input);
  53. });
  54. it('package ends with ; (same line)', function () {
  55. let settings = GetDefaultSettings();
  56. let input = "PACKAGE p IS NEW work.p_template;\r\nUSE p.ALL;";
  57. let result = beautify(input, settings);
  58. expect(result).toBe(input);
  59. });
  60. });
  61. function GetDefaultSettings(indentation: string = " "): BeautifierSettings {
  62. let new_line_after_symbols = new NewLineSettings();
  63. new_line_after_symbols.newLineAfter = ["then", ";"];
  64. new_line_after_symbols.noNewLineAfter = ["generic"];
  65. let signAligns = new signAlignSettings(false, false, "", []);
  66. let settings = getDefaultBeautifierSettings(new_line_after_symbols, signAligns, indentation);
  67. return settings;
  68. }
  69. function getDefaultBeautifierSettings(newLineSettings: NewLineSettings, signAlignSettings: signAlignSettings = null, indentation: string = " "): BeautifierSettings {
  70. return new BeautifierSettings(false, false, false, signAlignSettings, "uppercase", "uppercase", indentation, newLineSettings, "\r\n", false);
  71. }