From 4f49ffe9139b15e215fcd09034c0a75c638d5638 Mon Sep 17 00:00:00 2001 From: gmickus Date: Fri, 27 Sep 2024 11:38:25 +0300 Subject: [PATCH] Implement formatter ; add tests --- .../enum/1-enum-with-values/input.p | 21 +++++++++++++++++++ .../enum/1-enum-with-values/target.p | 20 ++++++++++++++++++ resources/functionalTests/enum/1-flag/input.p | 14 +++++++++++++ .../input.p => 1-flag/target.p} | 0 .../functionalTests/enum/1-simple/input.p | 10 +++++++++ .../functionalTests/enum/1-simple/target.p | 10 +++++++++ .../enum/2-multiple-enums/input.p | 10 +++++++++ .../input.p => 2-multiple-enums/target.p} | 0 .../enum/6do-start copy 2/target.p | 14 ------------- .../enum/6do-start copy 3/target.p | 14 ------------- .../enum/6do-start copy/input.p | 5 ----- .../enum/6do-start copy/target.p | 6 ------ src/v2/formatters/enum/EnumFormatter.ts | 9 ++++++-- 13 files changed, 92 insertions(+), 41 deletions(-) create mode 100644 resources/functionalTests/enum/1-enum-with-values/input.p create mode 100644 resources/functionalTests/enum/1-enum-with-values/target.p create mode 100644 resources/functionalTests/enum/1-flag/input.p rename resources/functionalTests/enum/{6do-start copy 2/input.p => 1-flag/target.p} (100%) create mode 100644 resources/functionalTests/enum/1-simple/input.p create mode 100644 resources/functionalTests/enum/1-simple/target.p create mode 100644 resources/functionalTests/enum/2-multiple-enums/input.p rename resources/functionalTests/enum/{6do-start copy 3/input.p => 2-multiple-enums/target.p} (100%) delete mode 100644 resources/functionalTests/enum/6do-start copy 2/target.p delete mode 100644 resources/functionalTests/enum/6do-start copy 3/target.p delete mode 100644 resources/functionalTests/enum/6do-start copy/input.p delete mode 100644 resources/functionalTests/enum/6do-start copy/target.p diff --git a/resources/functionalTests/enum/1-enum-with-values/input.p b/resources/functionalTests/enum/1-enum-with-values/input.p new file mode 100644 index 0000000..d22ae60 --- /dev/null +++ b/resources/functionalTests/enum/1-enum-with-values/input.p @@ -0,0 +1,21 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.bodyFormatting": true, + "AblFormatter.enumFormatting": true}*/ + +ENUM Oper: + DEFINE ENUM + Invalid = 0 + Create = 1 + Delete = 2 + BeforeUpdate = 3 + AfterUpdate = 4 +FieldDelete = 5 + PartitionDrop = 6 +PartitionTruncate = 7 + PartitionDeallocate = 8 + MTPartitionDeallocate = 9 + MTPartitionDrop = 10 +MergePartitionDrop = 11 + FieldAdd = 12. + END ENUM. + \ No newline at end of file diff --git a/resources/functionalTests/enum/1-enum-with-values/target.p b/resources/functionalTests/enum/1-enum-with-values/target.p new file mode 100644 index 0000000..a461bfc --- /dev/null +++ b/resources/functionalTests/enum/1-enum-with-values/target.p @@ -0,0 +1,20 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.bodyFormatting": true, + "AblFormatter.enumFormatting": true}*/ + +ENUM Oper: + define ENUM Invalid = 0 + Create = 1 + Delete = 2 + BeforeUpdate = 3 + AfterUpdate = 4 + FieldDelete = 5 + PartitionDrop = 6 + PartitionTruncate = 7 + PartitionDeallocate = 8 + MTPartitionDeallocate = 9 + MTPartitionDrop = 10 + MergePartitionDrop = 11 + FieldAdd = 12. +END ENUM. + \ No newline at end of file diff --git a/resources/functionalTests/enum/1-flag/input.p b/resources/functionalTests/enum/1-flag/input.p new file mode 100644 index 0000000..e9ce320 --- /dev/null +++ b/resources/functionalTests/enum/1-flag/input.p @@ -0,0 +1,14 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.bodyFormatting": true, + "AblFormatter.enumFormatting": true}*/ + +ENUM LiteraryMood FLAGS: + define ENUM None = 0 + Joyful + Melancholy + Heroic + Whimsical + Epic + JoyfulMelancholy = Joyful,Melancholy + Tragic = Epic. +END ENUM. \ No newline at end of file diff --git a/resources/functionalTests/enum/6do-start copy 2/input.p b/resources/functionalTests/enum/1-flag/target.p similarity index 100% rename from resources/functionalTests/enum/6do-start copy 2/input.p rename to resources/functionalTests/enum/1-flag/target.p diff --git a/resources/functionalTests/enum/1-simple/input.p b/resources/functionalTests/enum/1-simple/input.p new file mode 100644 index 0000000..f6389de --- /dev/null +++ b/resources/functionalTests/enum/1-simple/input.p @@ -0,0 +1,10 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true}*/ + +ENUM Weather: +define ENUM Rainy + Default = Sunny + Cloudy + Snowy + Apocalyptic . +END ENUM. \ No newline at end of file diff --git a/resources/functionalTests/enum/1-simple/target.p b/resources/functionalTests/enum/1-simple/target.p new file mode 100644 index 0000000..9fdfe6d --- /dev/null +++ b/resources/functionalTests/enum/1-simple/target.p @@ -0,0 +1,10 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.blockFormatting": true}*/ + +ENUM Weather: + define ENUM Rainy + Default = Sunny + Cloudy + Snowy + Apocalyptic. +END ENUM. \ No newline at end of file diff --git a/resources/functionalTests/enum/2-multiple-enums/input.p b/resources/functionalTests/enum/2-multiple-enums/input.p new file mode 100644 index 0000000..9f2f9a6 --- /dev/null +++ b/resources/functionalTests/enum/2-multiple-enums/input.p @@ -0,0 +1,10 @@ +/* formatterSettingsOverride */ +/* { "AblFormatter.bodyFormatting": true, + "AblFormatter.enumFormatting": true}*/ + +ENUM Direction: + define ENUM North + South. + define ENUM Dog + Cat. +END ENUM. \ No newline at end of file diff --git a/resources/functionalTests/enum/6do-start copy 3/input.p b/resources/functionalTests/enum/2-multiple-enums/target.p similarity index 100% rename from resources/functionalTests/enum/6do-start copy 3/input.p rename to resources/functionalTests/enum/2-multiple-enums/target.p diff --git a/resources/functionalTests/enum/6do-start copy 2/target.p b/resources/functionalTests/enum/6do-start copy 2/target.p deleted file mode 100644 index ec11a81..0000000 --- a/resources/functionalTests/enum/6do-start copy 2/target.p +++ /dev/null @@ -1,14 +0,0 @@ -/* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": true, - "AblFormatter.enumFormatting": true}*/ - -ENUM LiteraryMood FLAGS: - define ENUM None = 0 - Joyful - Melancholy - Heroic - Whimsical - Epic - JoyfulMelancholy = Joyful,Melancholy - Tragic = Epic. -END ENUM. \ No newline at end of file diff --git a/resources/functionalTests/enum/6do-start copy 3/target.p b/resources/functionalTests/enum/6do-start copy 3/target.p deleted file mode 100644 index 137fe8e..0000000 --- a/resources/functionalTests/enum/6do-start copy 3/target.p +++ /dev/null @@ -1,14 +0,0 @@ -/* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": true, - "AblFormatter.enumFormatting": true}*/ - -ENUM LiteraryMood FLAGS: - define ENUM None = 0 - Joyful - Melancholy - Heroic - Whimsical - Epic - JoyfulMelancholy = Joyful,Melancholy - Tragic = Epic. - END ENUM. \ No newline at end of file diff --git a/resources/functionalTests/enum/6do-start copy/input.p b/resources/functionalTests/enum/6do-start copy/input.p deleted file mode 100644 index b9f5d48..0000000 --- a/resources/functionalTests/enum/6do-start copy/input.p +++ /dev/null @@ -1,5 +0,0 @@ -/* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": true}*/ - -do while true: a = 3. -end. \ No newline at end of file diff --git a/resources/functionalTests/enum/6do-start copy/target.p b/resources/functionalTests/enum/6do-start copy/target.p deleted file mode 100644 index a130272..0000000 --- a/resources/functionalTests/enum/6do-start copy/target.p +++ /dev/null @@ -1,6 +0,0 @@ -/* formatterSettingsOverride */ -/* { "AblFormatter.blockFormatting": true}*/ - -do while true: - a = 3. -end. \ No newline at end of file diff --git a/src/v2/formatters/enum/EnumFormatter.ts b/src/v2/formatters/enum/EnumFormatter.ts index c53deaa..d5d53e1 100644 --- a/src/v2/formatters/enum/EnumFormatter.ts +++ b/src/v2/formatters/enum/EnumFormatter.ts @@ -31,7 +31,6 @@ export class EnumFormatter extends AFormatter implements IFormatter { const oldText = FormatterHelper.getCurrentText(node, fullText); const newText = this.collectEnumStructure(node, fullText); - console.log("Enum:\n" + newText); return this.getCodeEdit(node, oldText, newText, fullText); } @@ -57,6 +56,8 @@ export class EnumFormatter extends AFormatter implements IFormatter { } resultString = resultString.concat(childString); }); + // Look over this after #215 closed, as the dot should no longer be needed! + resultString += "."; return resultString; } @@ -66,9 +67,13 @@ export class EnumFormatter extends AFormatter implements IFormatter { foundFirstMember: boolean ): string { let newString = ""; - console.log("childType: " + node.type); switch (node.type) { + case SyntaxNodeType.DefineKeyword: + newString = + fullText.eolDelimiter + + FormatterHelper.getCurrentText(node, fullText).trim(); + break; case SyntaxNodeType.EnumMember: newString = foundFirstMember ? fullText.eolDelimiter +